那是 ed
默认情况下,其提示为空字符串。如果要退出,请输入q。不要以开头:。如果您尚未保存更改,它将以答复?。您可以将其解释为“确定吗?”,然后q再次命令进行确认。顺便说一下,它不理解的任何命令也会引起它的应答?。那是它知道的唯一错误消息。
它的命令是什么VIM / VI / EX是基于/ SED上,所以命令一样g/re/p,%s/vi/&m/g,1,3d,/pattern/,$d,w,q,wq工作就像VIM。
命令一样i,a和c进入插入模式。要退出插入模式并返回命令模式,只需输入仅包含的行.。要“移动”到另一行,只需输入行号,与当前行的偏移量(例如+2或-1)或正则表达式作为转到该行的命令。.表示命令模式下的当前行。您可以使用它来知道您的位置。$表示最后一行。
顺便说一句,如果您想了解更多有关它的信息,这是linux中的GNU程序,它的大多数文档都在info ed代替中man ed。
这是一个示例会话,其中添加了注释(不被ed接受):
$ ed
i # insert (on current line)
vi
. # end insert
%s/vi/&m/g # substitute vi for vim globally in all lines
i # insert (on current line)
first line
. # end insert
$a # append on last line
last line
. # end insert
%p # print all lines
first line
vim
last line
2 # move to line 2 and print it
vim
/line # move forward to line matching /line/ and print it
last line
-1 # move 1 line backwards and print it
vim
?line # move backward to line matching /line/ and print it
first line
+1 # move 1 line forward and print it
vim
g/line/p # print lines matching /line/ (grep)
first line
last line
p # print (current line)
last line
. # move to current line and print it
last line
c # change (current line)
final line
. # end insert
%p # print all lines
first line
vim
final line
/vim/,$c # change from line matching /vim/ to last line
that's all
. # end insert
%p # print all lines
first line
that's all
wq # write and quit
? # write what?
h # help with last error message
No current filename
wq # write and quit to check error message
?
H # help with all error messages
No current filename
wq # write and quit to check error message
?
No current filename
wq file.txt # write file.txt and quit
22 # wrote 22 bytes
编辑:像感恩节提到的那样,可以使用h或激活更多有用的错误消息H。另外,在命令中引用“所有行”的正式方法,不是%在命令的范围内,而是在命令中ed。在GNU中ed,%支持使用该功能,但info手册中未提及。%所有行的使用显然是由发明的ex,似乎是因为那里的,意思.,.而不是1,$像那样ed。
EDIT2:设置其他编辑器
像提到的其他答案一样,如果要指定其他编辑器,则可以通过设置EDITOR或VISUAL环境变量来指定。答案中将说明两者之间的区别。
如果要为单个命令设置它,可以这样做:
EDITOR=vi crontab -e
如果您希望在shell会话中启动的所有程序都使用它,则可以这样:
export EDITOR=vi
crontab -e
您可以分别保存exportin ~/.profile或/etc/profile,这取决于您是否希望它成为bash的用户或系统设置。这是unix可移植的设置编辑器的方法。您可以在任何发行版中执行此操作。
在Ubuntu中,也有该update-alternatives命令。update-alternatives --display editor可以使用update-alternatives --config editor来查看当前的默认编辑器,您可以使用它进行设置:
$ sudo update-alternatives --config editor
There are 4 choices for the alternative editor (providing /usr/bin/editor).
Selection Path Priority Status
------------------------------------------------------------
* 0 /bin/nano 40 auto mode
1 /bin/ed -100 manual mode
2 /bin/nano 40 manual mode
3 /usr/bin/vim.basic 30 manual mode
4 /usr/bin/vim.tiny 10 manual mode
Press enter to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in manual mode.
ed:默认情况下,它会给出一个字符计数(在基于Debian的系统中,这通常888是第一次,这是模板“空” crontab中的字符数)。如果看到计数为0,则必须对其进行修改。请参阅Crontab -e命令无法正常工作