iN2gN3jT

导航

Linux 终端编辑器

vim

有模态的编辑器

快捷命令

:h       | 打开帮助
:h 关键词 | 打开相关关键词的帮助
:on      | 仅保留当前窗口 (其他用法 :only)
:close   | 关闭当前窗口
Ctrl-w w | 循环切换窗口 (Ctrl-w W 反向循环切换窗口)
:w       | 写入
:q       | 退出
:x       | 写入并退出(相当于 :wq 或 Xx)

崩溃恢复

$ vim test.txt
E325: ATTENTION
Found a swap file by the name ".test.txt.swp"
          owned by: root   dated: Sun Oct 25 21:46:19 2026
         file name: ~root/test.txt
          modified: YES
         user name: root   host name: test
        process ID: 2014 (STILL RUNNING)
While opening file "test.txt"
             dated: Thu Oct 22 17:27:49 2026

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r test.txt"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file ".test.txt.swp"
    to avoid this message.

Swap file ".test.txt.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:

emacs

重度依赖快捷键的编辑器

C-g 中断当前命令执行
C-x C-s 保存当前文件
C-x C-c 退出 Emmacs
M-x eww 打开 web 浏览器 eww (按 l 后退,按 r 前进)

nano

简单易用的编辑器

^G Help         ^O Write Out    ^W Where Is     ^K Cut          ^T Execute	^C Location     M-U Undo        M-A Set Mark    M-] To Bracket
^X Exit         ^R Read File    ^\ Replace	^U Paste        ^J Justify	^_ Go To Line   M-E Redo        M-6 Copy        ^Q Where Was
^G 打开帮助
^O 写出(相当于保存Save)
^W 在哪里(相当于寻找Find)
^K 剪切
^T 执行(打开执行特定命令的界面)
^C 显示位置(如 [ line 1/1 (100%), col 1/1 (100%), char 0/0 (0%) ] )
M-U 撤销变更
M-A 打标志(可达到选取一段文字的效果)
M-] 从当前光标下的括号字符跳转到匹配的另一个光标字符
^X 退出
^R 读取文件内容到当前缓冲区
^\ 替换
^U 粘贴
^J 对齐自然段
^_ 跳转到指定行号
M-E 重做变更
M-6 复制
^Q 曾经在哪里(相当于向前寻找)

ed

ed编辑器

快捷命令

P 显示提示符星号 *
,p 打印全部
3,5p 打印 3,4,5 行
;p 从当前行打印到文件末尾
g/re/p 将所有含有 re 关键词的行都打印出来
n 打印当前行号和行的内容
s/a/b/g 将当前行的所有 a 替换成 b
a 在当前行的下一行插入(使用 /^\.\n/ 作为输入内容的结尾)
i 在当前行的上一行插入(使用 /^\.\n/ 作为输入内容的结尾)
!cmd 执行命令cmd
r !cmd 读取命令cmd执行产生的内容到缓冲区
w 写入缓存区的内容到文件
q 退出
q! 强制退出

sed

sed流编辑器

sed的 -i, --in-place 选项可以原地修改文件的内容

例子

$ cat test2.txt
line1
line2: old1
line3: old2
line4
$ sed 's/old/new/' test2.txt
line1
line2: new1
line3: new2
line4
$ sed -i 's/old/new/' test2.txt
$ cat test2.txt
line1
line2: new1
line3: new2
line4

posted on 2026-10-25 22:10  笔记和文档  阅读(10)  评论(0)    收藏  举报