现在的位置: 首页 > 综合 > 正文

Linux文本编辑VI大全

2013年08月14日 ⁄ 综合 ⁄ 共 2269字 ⁄ 字号 评论关闭

Linux文本编辑VI大全

VI/VIM是Linux文本编辑的利器,掌握VI使用,是成熟Linux程序员的关键特征之一

下载和安装

一般版本的Linux默认安装了VI/VIM,嵌入式Linux一般都精简掉了。下载安装过程如下:
  • 从http://vim.org下载VIM源码
  • tar xzf vim-7.0.tar.gz
  • cd vim70
  • ./configure --prefix=/opt --enable-cscope
  • make
  • make install

控制类命令

使用vi打开文件命令: vi file-to-edit.txt
vi编辑器有三种工作模式:命令行模式,插入模式,命令模式.
  • 命令模式: ESC键返回命令模式,可执行光标命令
  • 输入模式: 在输入符号"i",进入插入模式, ESC键退出输入模式,进入命令行模式。
  • 命令行模式: 下载ESC键,在输入符号":",在屏幕下方出现命令行模式。
命令行: ZZ 保存退出
命令行: ":wq"  写入退出
命令行: ":w"    写入但不退出
命令行: ":q!"   不保存退出
命令行: ":qa" 退出所有打开的文件

光标类命令

Keystrokes Action
h/j/k/l Move cursor left/down/up/right
spacebar Move cursor right one space
-/+ Move cursor down/up in first column
ctrl-d Scroll down one half of a page
ctrl-u Scroll up one half of a page
ctrl-f Scroll forward one page
ctrl-b Scroll back one page
M (shift-h) Move cursor to middle of page
H Move cursor to top of page
L Move cursor to bottom of page
W
w
5w
Move cursor a word at a time
Move cursor ahead 5 words
B
b
5b
Move cursor back a word at a time
Move cursor back a word at a time
Move cursor back 5 words
e
5e
Move cursor to end of word
Move cursor ahead to the end of the 5th word
0 (zero) Move cursor to beginning of line
$ Move cursor to end of line
) Move cursor to beginning of next sentence
( Move cursor to beginning of current sentence
G Move cursor to end of file
% Move cursor to the matching bracket.
Place cursor on {}[]() and type "%". 
Use the matchit or xmledit plug-in to extend this capability to XML/XHTML tags.
'. Move cursor to previously modified line.
'a Move cursor to line mark "a" generated by marking with keystroke "ma"
'A Move cursor to line mark "a" (global between buffers) generated by marking with keystroke "mA"
]' Move cursor to next lower case mark.
[' Move cursor to previous lower case mark.

编辑类命令

Keystrokes Action
i Insert at cursor
a Append after cursor
A Append at end of line
ESC Terminate insert mode
u Undo last change
U Undo all changes to entire line
o Open a new line
dd
3dd
Delete line
Delete 3 lines.
D Delete contents of line after cursor
C Delete contents of line after cursor and insert new text. Press esc key to end insertion.
dw
4dw
Delete word
Delete 4 words
cw Change word
x Delete character at cursor
r Replace character
R Overwrite characters from cursor onward
s Substitute one character under cursor continue to insert
S Substitute entire line and begin to insert at beginning of line
~ Change case of individual character
ctrl-a
ctrl-x
Increment number under the cursor.
Decrement number under the cursor.
/search_string{CR} Search for search_string
?search_string{CR} Search backwards (up in file) for search_string
n Find next occurrence of search_word
N Find previous occurrence of search_word
. repeat last command action.

抱歉!评论已关闭.