VI/VIM的应知必会内容一览 | LINUX

249 阅读2分钟

这是我参与更文挑战的第29天,活动详情查看: 更文挑战

To insert text(插入文本):

|Command |Insert Text| |-- - i | before cursor 光标前插入 a| after cursor 光标后插入 A| at the end of the line 光标移动到底行 o| open a line below the current line 在当前行下方新建一行 O| open a line above the current line在当前行上方新建一行 r| replace the current character 替换当前字符 R| replace characters until , overwrite替换字符直到敲击,覆盖

To move the cursor(移动光标):

|Command |Moves the cursor| |-- -| SPACE, l (el), or right arrow |space to the right 向右移动光标 h or left arrow| space to the left 向左移动光标 j or down arrow |down one line下一行 k or up arrow |up one line 上一行 w |word to the right b |word to the left $ |end of the line移动到这一行的最后面字符处 0 (zero) |beginning of the line移动到这一行的最开始字符处 e |end of the word to the right -|beginning of previous line光标移动到非空格符的上一行 ) |end of the sentence ( |beginning of the sentence } |end of paragraph { |beginning of paragraph

To Delete Text(删除文本):

|Command |Action| |-- -| d0 |delete to beginning of line 删除该行的最前面一个字符 dw| delete to end of word d3w| delete to end of third word db| delete to beginning of word dW| delete to end of blank delimited word dB| delete to beginning of blank delimited word dd| delete current line 删除当前行 5dd| delete 5 lines starting with the current line 删除当前行接下来的5行 dL| delete through the last line on the screen dH| delete through the first line on the screen d)| delete through the end of the sentence d(| delete through the beginning of the sentence x| delete the current character 删除当前字符 nx| delete the number of characters specified by n. 连续向后删除 n 个字符 nX| delete n characters before the current character 连续向前删除 n 个字符

Yanking (copy) and Putting (paste) Text(复制和粘贴文本):

|Command |Effect| |-- -| yM |yank text specified by M
y3w| yank 3 words 复制3个词 nyy| yank n lines 复制n行 Y| yank to the end of the line 复制到行尾 P| put text above current line 粘贴到当前行的上方 p| put text below current line 粘贴到当前行的下方

Ending an Editing Session

|Command| Effect| |-- -| :w| writes the contents of the work buffer to the file :q| quit 退出 :q!| save and quit 保存并退出 :wq| save and quit保存并退出 :w filename| saves to filename (allows you to change the name of the file) 设置文件名保存

Miscellaneous commands

|Command |Effect| |-- -| J| join the current line and the following line :set number| number the lines on the screen (not actually added to file) 显示函数 :set nonumber| turns off numbering of lines 关闭显示行数 :r filename| reads filename into the current file at the location of the cursor :set showmode| displays INPUT MODE at the lower right hand corner of screen ~| change uppercase to lowercase and vice-versa