VIM Introduction
vim is a function similar to the powerful vi text editor, and in contrast to the traditional vi editor has been improved on a lot of features, has been widely used in Unix-like systems. Simple configuration, you can complete a powerful learning.
If no vim editor on your operating system (Unix-like systems), install it! To ubuntu operating system as an example:
Install vim
sudo aptitude install -y vim
The basic use of VIM
Open the file using vim
Open a file using vim
sudo vim /etc/passwd
The number of rows to pinpoint the file you want to edit
sudo vim +18 /etc/passwd
Use vim to open multiple files at one time
sudo vim -O /etc/passwd /etc/group
Such vim can open two files, the default cursor in the left-most window, you can directly edit the contents inside. Use Ctrl + W can be switched to another window (need to save the contents of writing before switching).
Configuration vim (vim configuration file may be written in vimrc)
Show Line Numbers
: set nu
Auto-indenting
: set ai
Syntax Highlighting
: syntax on
VIM SHELL command is executed
:! gcc -o hello hello.c
Defined shortcuts
Enter the vim configuration file
sudo vim /etc/vim/vimrc
Edit the configuration file in vimrc
noremap <F6> :set nu noremap <F7> :set ai noremap <F8> :syntax on
Efficient allocation
filetype on # 启用文件类型侦测 set encoding=cp936 # 指定当前字符编码为 Windows 简体中文 set tabstop=4 # 设置 Tab 键为4个空格 set mouse=a # 在终端中使用鼠标 set ignorecase # 查找时忽略大小写 set helplang=cn # 在安装完中文帮助文档后设置帮助文档的语言 help user # 查阅中文手册 help user_num(范围:01-32) # num可以直接定位到章节 help tag # tag为手册名称
personal use vim configuration
: set nu
: set ai
: syntax on
: filetype on
set tabstop=4
set mouse=a
set ignorecase
vi mode of operation
vi There are three basic modes: command mode, text input mode, line mode.
vi mode of operation
2.1 Command Mode
At any time, no matter what mode the user is in, just click the ESC key to enter the Vi command mode; we start Vi input at a shell environment (for the $ prompt), when entering the editor, and in this mode . In this mode, the user can input various legal Vi command to manage their documents. At this point any characters entered from the keyboard are interpreted as editing commands, if the input character is legal Vi command, Vi complete the appropriate action after receiving a user command. But it must be noted that the command entered do not show up on the screen. If the lawful order of the input character is not Vi, Vi will ring alarm.
2.2 Edit mode
Insert command input I (the current position of the insertion) in command mode, a (current position of a position after insertion), o (the next row is inserted) may enter text input mode. In this mode, any character entered by the user are saved vi as the contents of the file, and displays it on the screen. In the text entry, if you want to return to command mode, press ESC can.
2.3 line mode
In command mode, the user presses ":" key to enter the last line mode, then Vi will be displayed in a last line (usually the last line of the screen) display window ":" as the last line mode prompt, wait for user input commands. (Medium, such as the contents of the edit buffer is written to the file) Most file management commands are executed in this mode. After the last line command, Vi automatically return to command mode.
If from the command mode to the edit mode, you can type a command or I; if necessary to return from the text mode, press Esc to. In the command mode, enter ":" to switch to line mode, then enter the command.
3. vi basic operations
3.1 to enter the edit mode
command | meaning |
---|---|
i sum I | i inserted before the cursor, I first inserted line |
a sum A | After a cursor insertion, the insertion end of the line A |
o sum O | o at the cursor next line is inserted, O insert a row in the row where the cursor |
Move the cursor 3.2
command | meaning |
---|---|
h | The cursor is moved to the left |
j | Move the cursor down |
k | Cursor up |
l | Move the cursor to the right |
H、M、L | The visible screen to move the cursor to the first line (H), the middle line (M), the last line (L) |
And $ ^ | ^ Move to the beginning of the line $ move to the end of the line |
G and gg | The last line of the document G, gg the first line of the document |
ctrl+f、ctrl+b | Scroll forward and backward scroll |
ctrl+d、ctrl+u | Ping half forward, backward semi-Ping |
{ with } | {Some upward movement, backward movement section} |
w and b | Move forward a word, move back one word |
3.3 Delete command
command | meaning |
---|---|
X and x | After deleting the cursor one character x, X cursor before deleting a character, the character at the cursor position comprising |
dd和 n dd | dd delete the row, 5 dd delete the specified number of lines |
d0 and D | d0 delete all the contents of the cursor before the Bank, the Bank after D delete all the contents of the cursor, the cursor position contains character |
dw | Delete the word under the cursor position, light table contains the location of the character |
3.4 Undo command
command | meaning |
---|---|
in | Step by step withdrawal |
ctrl + r | Anti revoked |
3.5 Repeat command
command | meaning |
---|---|
. | Performing a repeated operation command |
3.6 Copy and paste
command | meaning |
---|---|
yy | And n yy y $ y ^ yy and copy the current row, 5 yy copy row 5 |
p | In the open position the cursor down the new line paste |
3.7 Select text
command | meaning |
---|---|
v and V | v select a single character, V select an entire row |
< <和> > | After selecting text, left indent, right indent |
Find and Replace 3.8
command | meaning |
---|---|
The command mode, r and R | Alternatively the current character r, R replace characters after the cursor |
Line mode, / + str | A look - n, N Find Previous |
Line mode,% s / abc / 123 / g | All file abc replace 123 |
Line mode, 1, 10s / abc / 123 / g | Abc between the first row to the 10th row 123 replaced |
VIM editor Advanced
Ready access to the VIM manual
http://soruceforge.net/projects/vimdoc/files/vimcdoc/vimcdoc-1.9.0.tar.gz/download
Use vim plugin
vim plugin's official website: https://www.vim.org/scripts/script.php?script_id=273
Plug general installation procedure (TagList widget example):
Unzip the package
sudo unzip taglist_46.zip
Copy xxx.vim to the next / etc / vim / plugin directory
cd plugin sudo cp -rf taglist.vim /etc/vim/plugin
VIM enter a command reboot
:Tlist