Inline Editing
Intro
在终端中,有时会遇到编辑长命令的需求,例如curl
,wget
,ffmpeg
等命令就可以很长
当在终端输了一长串命令,但发现中间有错误👇
NUSHELL
$ echo "Beautiful is better than ugly.> Explicit is better than implicit.> Simple is better than complex.> Complex is better than complicated.> Flat is better than nested.;> rm -rf /; # ~~(*/ω\*)~ 不要删掉我~~;> Sparse is better than dense.> Readability counts.> Special cases aren't special enough to break the rules.> Although practicality beats purity> Errors should never pass silently.> Unless explicitly silenced.> In the face of ambiguity, refuse the temptation to guess.> There should be one-- and preferably only one --obvious way to do it.> Although that way may not be obvious at first unless you're Dutch.> Now is better than never.> Although never is often better than *right* now.> If the implementation is hard to explain, it's a bad idea.> If the implementation is easy to explain, it may be a good idea.> Namespaces are one honking great idea -- let's do more of those!"
如何便捷地修改命令,许多shell提供了优雅的解决方案。
Solutions
使用外部编辑器
许多shell都支持使用外部editor中对command进行编辑,这样就可以使用编辑器(vim,helix,nano)的强大功能来编辑命令。(如果不在乎启动速度,甚至可以用vscode)
以Nushell为例,使用scp
将remote machine上的文件复制到本地时,需要修改remote machine的host name,可以先用Ctrl+O
打开nvim,跳转到指定位置修改,然后优雅的保存退出
对于Bash,默认情况下,Bash是在emacs模式下运行的。按下Ctrl + x, Ctrl + e
组合键,就可以打开编辑器编辑命令。如果在vi模式下,进入normal模式后按v键即可

Yet Another Way
众所周知,生成随机字符串的方式之一就是退出VIM,VIM还是太吃操作了🥴,有没有更加简单又强势的操作推荐一下嘛?

按住left/right
不放,或者进阶一点按住Ctrl+left/right
不放;此外配合Ctrl+A
,Ctrl+E
跳转到行首/行尾,针对绝大多数场景都是够用的
Change Default Editor
设置默认的编辑器,对于ssh远程开发,helix是不错的选择,nvim还需要折腾下系统剪切板
DIFF
# if using nushell, add this line to config.nu$env.config = {+ buffer_editor: "nvim"}# if using bash, add this line to .bashrc+ export VISUAL=nvim# if using fish, add this line to config.fish+ set -gx VISUAL nvim
Inline Editing