快速调用编辑器来写一条长,复杂或难的命令
Rapidly invoke an editor to write a long, complex, or tricky command
下次当你需要用shell输入一组长命令时,试试按住ctrl然后按x和e键
Next time you are using your shell and need to enter a long command, try ctrl-x e (press x and e while holding control key).
shell会将你已经敲出的命令行粘贴到由变量EDITOR定义的编辑器中。然后可以用所有vi,emacs,nano,或者你喜欢的编辑器里面强大的宏和命令来编辑它们。
The shell will take what you've written on the command line so far and paste it into the editor specified by $EDITOR. Then you can edit at leisure using all the powerful macros and commands of vi, emacs, nano, or your preferred editor.
赶脚这个功能挺牛呀,马上试试。
先看一下EDITOR变量:
$ echo $EDITOR //空的,啥也没有
按照方法调用一下试试:
$ bash: emacs: command not found //可见默认是emacs编辑器,但没有安装,我也只会vi呀~~
改成vi:
$ EDITOR=vi
这回好用了,直接进入vim界面了。退出时:wq保存,然后按向上方向键即可出现最终的命令。比较懒就不截图了,大家可以试试。
当然,如果要一直用,需要把
export EDITOR=vi
加入到用户家目录下的.bashrc文件中。
转载于:https://blog.51cto.com/smellyman/1891571