edit command (CLI text editor) returns to Windows
Moderator: DosItHelp
Re: edit command (CLI text editor) returns to Windows
Thanks for the short notice. I've updated the topic to let the younger audience know that this is a feature that dates back to the old days, before 64-bit machines became common. The edit.com editor was a 16-bit tool that (if I recall correctly) was still shipped with the 32-bit version of Windows 7.
Just to add ... The revival was planned for a while, and Microsoft asked the community for feedback about their preferred third party editors and features.
https://github.com/microsoft/terminal/discussions/16440
Curious to see how it will develop further.
Steffen
Just to add ... The revival was planned for a while, and Microsoft asked the community for feedback about their preferred third party editors and features.
https://github.com/microsoft/terminal/discussions/16440
Curious to see how it will develop further.
Steffen
Re: edit command (CLI text editor) returns to Windows
Mmm... More than 10 years ago I started to write a Batch file version of Edlin.com MS-DOS line editor. This was an interesting ancient editor that does not used the screen to browse along the file contents; it show file lines via user requests and also edits the lines in individual line-by-line basis always in sequential text-mode (hence the name).
I want to make good use of this topic as a justification to post my ancient Edlin.bat line editor. I hope it will be interesting for someone (although I doubt it could be useful for anyone).
Antonio
I want to make good use of this topic as a justification to post my ancient Edlin.bat line editor. I hope it will be interesting for someone (although I doubt it could be useful for anyone).
Code: Select all
@if (@CodeSection == @Batch) @then
@echo off
rem Edlin.bat: Emulator of old MS-DOS edlin.com line-oriented text editor
rem Antonio Perez Ayala
rem Version 0.1 (preliminary): Replace, Search and Transfer commands not yet implemented
rem Things to do:
rem - Minor adjustment of final "current line" in a couple commands
rem - Implement relative, (.) and (#) line numbers
rem - More extensive error checking in commands
if "%~1" equ "" echo File name must be specified& goto :EOF
if "%~1" equ "/?" (
echo Starts Edlin, a line-oriented text editor.
echo/
echo EDLIN [drive:][path]filename
echo/
choice /M "Do you want to open the Edlin article in Wikipedia "
if not errorlevel 2 explorer http://en.wikipedia.org/wiki/Edlin
goto :EOF
)
rem Load the file, if it exists
setlocal DisableDelayedExpansion
set /A curLine=0,lastLine=0
if exist %1 (
for /F "delims=" %%a in ('findstr /N "^" %1') do (
set "line=%%a"
set /A lastLine+=1
setlocal EnableDelayedExpansion
for /F "tokens=1,* delims=ÿ" %%b in ("!lastLine!ÿ!line:*:=!") do endlocal & set "line[%%b]=%%c"
)
set curLine=1
set "newFile="
echo End of input file
) else (
set newFile=True
echo New file
)
setlocal EnableDelayedExpansion
set quote="
set digits=0123456789
:getCommand
if %curLine% gtr %lastLine% set curLine=%lastLine%
set "command="
set /P "command=*"
rem Separate command parameters
set "p1=" & set "p2=" & set "p3=" & set "p4="
if not defined command (
set "letter=#"
goto execCommand
)
set "letter=!command:~-1!"
if "!digits:%letter%=!" neq "%digits%" (
set "letter=#"
set p1=%command%
goto execCommand
)
set "command=!command:~0,-1!"
if defined command (
if "!command:~0,1!" equ "," set "command=!quote!!command!"
for /F "tokens=1-4 delims=," %%a in ("!command:,,=,"",!") do (
set "p1=%%~a" & set "p2=%%~b" & set "p3=%%~c" & set "p4=%%~d"
)
)
:execCommand
call :command-%letter% %1
if /I "%letter%" equ "e" goto :EOF
if /I "%letter%" equ "q" goto :EOF
goto getCommand
Copy lines from Begin to End and insert they at Dest, [repeat Times times]
:command-C [begin],[end],dest[,times]Copy
if defined p1 (set begin=%p1%) else set begin=%curLine%
if defined p2 (set end=%p2%) else set end=%curLine%
if %end% gtr %lastLine% set end=%lastLine%
set dest=%p3%
if %dest% gtr %lastLine% set /A dest=lastLine+1
if defined p4 (set times=%p4%) else set times=1
rem Renumber lines from Dest to lastLine, if any
set /A lines=end-begin+1
if %dest% leq %lastLine% (
set /A newDest=dest+lines*times
call :copyLines %dest% %lastLine% !newDest!
if %dest% lss %begin% set /A begin+=lines*times, end+=lines*times
)
set /A curLine=dest, lastLine+=lines*times
rem Copy lines
for /L %%i in (1,1,%times%) do (
call :copyLines %begin% %end% !dest!
set /A dest+=lines
)
exit /B
Delete lines from Begin to End
:command-D [begin][,end]Delete
if defined p1 (set begin=%p1%) else set begin=%curLine%
if defined p2 (set end=%p2%) else set end=%begin%
if %end% gtr %lastLine% set end=%lastLine%
set /A newBegin=end+1
if %newBegin% leq %lastLine% call :copyLines %newBegin% %lastLine% %begin%
set /A curLine=begin, lastLine-=end-begin+1
exit /B
edit Line
:command-# [line]
if defined p1 (set "begin=%p1%") else set /A begin=curLine+1
if defined line[%begin%] (
CScript //nologo //E:JScript "%~F0" "!line[%begin%]!{ENTER}"
set "num= %begin%"
set /P "=<!num:~-7!:*"
set /P "line[%begin%]=>!num:~-7!:*"
set curLine=%begin%
)
exit /B
End/Save
:command-E End
if not defined newFile (
del "%~DPN1.bak" 2> NUL
ren "%~1" "%~N1.bak"
)
(for /L %%i in (1,1,%lastLine%) do echo(!line[%%i]!) > "%~1"
exit /B
Insert new text at Line
:command-I [line]Insert
if defined p1 (set begin=%p1%) else set begin=%curLine%
if %begin% gtr %lastLine% set /A begin=lastLine+1
set new=%begin%
rem Get new lines from keyboard until two spaces at end of line
echo To end insert, enter two spaces at end of line
:newLine
set "new[%new%]="
set "num= %new%"
set /P "new[%new%]=>%num:~-7%:*"
if "!new[%new%]:~-2!" equ " " goto endInsert
set /A new+=1
goto newLine
:endInsert
set "new[%new%]=!new[%new%]:~0,-2!"
if not defined new[%new%] set /A new-=1
rem Renumber lines from Begin to lastLine, if any
if %new% geq %begin% if %begin% leq %lastLine% (
set /A dest=new+1
call :copyLines %begin% %lastLine% !dest!
set /A curLine=new+1, lastLine=dest+lastLine-begin
) else (
set /A curLine=new+1, lastLine=new
)
rem Insert new text in the lines
for /L %%i in (%begin%,1,%new%) do set "line[%%i]=!new[%%i]!" & set "new[%%i]="
exit /B
List lines from Begin to End
:command-L [begin][,end]List
if not defined p1 ( rem Begin line omitted
if not defined p2 ( rem Both lines omitted
set /A begin=curLine-11
if !begin! lss 1 set begin=1
set /A end=begin+22
) else ( rem Just end line given
set /A begin=p2-22, end=p2
if !begin! lss 1 set begin=1
)
) else ( rem Begin line given
if not defined p2 ( rem Just begin line given
set /A begin=p1, end=p1+22
) else ( rem Both lines given
set /A begin=p1, end=p2
)
)
if %end% gtr %lastLine% set end=%lastLine%
for /L %%i in (%begin%,1,%end%) do (
if %%i equ %curLine% (set "num= %%i:*") else set "num= %%i: "
echo !num:~-10!!line[%%i]!
)
exit /B
Move lines from Begin to End at Dest
:command-M [begin],[end],destMove
set "p4="
call :command-C
set /A newBegin=end+1
if %newBegin% leq %lastLine% call :copyLines %newBegin% %lastLine% %begin%
set /A lastLine-=end-begin+1
exit /B
Paging lines from Begin for Range lines per page
:command-P [begin][,range]Paging
if defined p1 (
set begin=%p1%
) else (
if %curLine% equ 1 (
set begin=1
) else (
set /A begin=curLine+1
)
)
if defined p2 (set /A end=begin+p2-1) else set /A end=begin+22
if %end% gtr %lastLine% set end=%lastLine%
set curLine=%end%
for /L %%i in (%begin%,1,%end%) do (
if %%i equ %curLine% (set "num= %%i:*") else set "num= %%i: "
echo !num:~-10!!line[%%i]!
)
exit /B
Quit/No save
:command-Q Quit
choice /M "Abort edit "
if errorlevel 2 set "letter=X"
exit /B
Replace Text1 by Text2 in lines from Begin to End
(not yet implemented)
:command-r [begin][,end][?]Rtext1[Ctrl-Ztext2]
exit /B
Search the Text in lines from Begin to End
(not yet implemented)
:command-s [begin][,end][?]Stext
exit /B
Transfer (insert) text from Filename at Line
(not yet implemented)
:command-t [line]Tfilename
exit /B
Show help on commands
:command-?
echo Edit line line#
REM echo Append [#lines]A
echo Copy [startline],[endline],toline[,times]C
echo Delete [startline][,endline]D
echo End (save file) E
echo Insert [line]I
ECHO To end insert, enter two spaces at end of line.
echo List [startline][,endline]L
echo Move [startline],[endline],tolineM
echo Page [startline][,numlines]P
echo Quit (throw away changes) Q
echo Replace [startline][,endline][?]Roldtext[CTRL+Znewtext]
echo Search [startline][,endline][?]Stext
echo Transfer (insert file) [toline]T[drive:][path]filename
REM echo Write [#lines]W
exit /B
"CopyLines" auxiliary subroutine
:copyLines begin end dest
if %3 lss %1 (
set _dest=%3
for /L %%i in (%1,1,%2) do (
set "line[!_dest!]=!line[%%i]!"
set /A _dest+=1
)
) else (
set /A _dest=%3+%2-%1
for /L %%i in (%2,-1,%1) do (
set "line[!_dest!]=!line[%%i]!"
set /A _dest-=1
)
)
exit /B
@end
WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));
Re: edit command (CLI text editor) returns to Windows
EDLIN.COM 2392 bytes.
Those were the days.
Saso
Those were the days.
Saso
Re: edit command (CLI text editor) returns to Windows
This is so cool! I remember Edit from Windows XP in 2008 when I was first learning DOS Batch, and even in 2008 I was surprised that it was there! Edit, a.k.a. MS-DOS Editor, which I found references to in a 1993 MS-DOS 6.2 manual, I couldn't believe that was on there, given that Windows XP had things like Notepad, so I was actually not surprised when I tried the command in Windows 10 one day and it didn't work, I kind of figured it was on its way out, as much as I liked it. However I wasn't the biggest fan of Edlin, just Edit, so I'm glad Edit is coming back to Windows! Maybe it's a retro resurgence, just like vinyl coming back, or Nintendo making devices inspired by their old consoles like NES Classic and such, I guess it's about time for Edit to come back, that's just how the cycle goes. And despite me not particularly enjoying my time trying out Edlin in the XP days, thanks for posting Edlin-inspired code so I can understand how a text-processing program is coded!