Vim usage Basics

Source: Internet
Author: User
Tags image line

-- To do good things, you must first sharpen the tool.
Vim is VI improved. VI is an excellent text editor on Unix-like systems. It is better to use gvim on various platforms.
Vim's official website is: gvim inside the http://www.vim.org Program Free Download, various plug-ins for you to choose from, and a small number of free books on VIM for you to download.
Vim is different from notepad, write, and MS Office Word. If you get used to it, it is very painful to use Vim again. It is a plain text compiler and one of the best recognized text compilers.
Vim is so powerful that it allows you to set it according to your usage habits. In this case, the longer you use it, the more you like it. The more you know about it, the more surprises you have. I have benefited a lot and should share some good things with you. Therefore, I would like to recommend some Vim knowledge for your reference.
Vim has three working modes: insert mode, command mode, and row mode ). The insert mode is the same as when we use Notepad. We can enter text at will, and there is nothing to say. The other two modes are described below.
The first is the mutual conversion of the three modes. Open Vim. The default mode is the command mode. After a or I is input, it can be converted to the insert mode. After ESC is input, the command mode is returned: it can be converted to the line mode. The line mode can also be returned to the command mode after ESC is input. Note: The line mode and insert mode cannot be directly converted to each other and must be converted to the command mode. (If the following command starts with a colon, It is a line-mode command by default; otherwise, it is a command in command mode)
The four hjkl keys are equivalent to moving the cursor →. You can use them in command mode to move the cursor up, down, and left. (Pay special attention not to move the cursor from top to bottom of the keypad, otherwise it will lose one of the main reasons for using vim, which is the most difficult habit to change when using Vim)
W is the start of the next word.

: W is to save the file

: WQ is used to save and exit the file.
B is to jump to the beginning of a word
E is to jump to the end of a word.
[[Or GG is the first line to jump to the file
] Or G is to jump to the last line of the file
Ng is the nth line of the object, where n is a number
N | it is the nth character to jump to the row, where n is a number
A is the insert character to the cursor
A is the last character inserted into the row.
I is to insert characters before the cursor
I is to insert characters to the switch.
S is to modify the character at the cursor (delete the current character and then enter the insert mode)
S is to modify the character of the row (delete the current row and then enter the insert mode)
C is used in combination with other commands. For example, Cw is a word after the cursor, CB is a word before the cursor, and so on: ch is a character before the cursor, CJ is a line after the cursor, and so on. If you add a number to the front, for example, NCW (N is a number) is the N words after the cursor is changed, and other commands are also like this, which is the essence of vim. Just like tai chi, Yi, and Yi, the four elephants are as wonderful as gossip. Most of the commands can be combined in this way and can be found by yourself. They have a general rule: num + order + Where, such as 4cw (modifying 4 words), 4 is num, C is order, W is where; the same is true for 4yj (copying 5 rows ).
C is the content after the current cursor character of the current row
D is similar to C in usage, but D is deleted, not modified, so it does not enter the insert mode.
D is the content after the current cursor character is deleted from the current row.
R changes the current character to another character. For example, RA changes the current character to a and does not enter the insertion mode.
R is the character after the cursor is changed until you Press ESC, and it does not enter the insert mode.
V is the character selection command. Press V and move the cursor down or down to select multiple characters first.
V is to select rows. You can move the cursor up or down after pressing V to select multiple rows.
CTRL + Q or Ctrl + V is to open the visual block for selection, Windows can only use Ctrl + Q, because Ctrl + V is occupied by the System
X is the character that deletes the cursor.
X is the character before the cursor is deleted.
Y is the character at the current cursor. If multiple characters are selected, Press Y to copy the selected character.
Y or YY is the content of the current row. If multiple rows are selected, then Y is the content of the selected row.
P is the next row of the current row pasted in the clipboard.
P is the last row of the current row pasted in the clipboard.
O inserts a new row into the next row of the current row.
O inserts a new row into the previous row of the current row.
ZF folds the content after multiple lines are selected.
Zo is used to open the current fold
ZC is the folding that closes the cursor.
Zn is used to open all folds.
ZM is used to close all opened folds.
: SP file name is to open a new file in a horizontal window
: The VSP file name is used to open a new file in a vertical window.
CTRL + W switch in the order of opening the window twice
CTRL + W + (one in hjkl) is to switch the window in the nominal animation direction of the light.
CTRL + W + R and CTRL + W + R both change the positions of the current window and other windows. The difference is that their order is the opposite.
CTRL + W + (hjkl) is to change the position of the current window and the cursor moving to the upper window (if any)
0 is to move the cursor to the first character of the line.
^ Moves the cursor to the beginning of the first non-blank character in the row.
$ Is to move the cursor to the end of the row
Is to repeat the previous command
FW is to find a character after the cursor of the line, W can be any character, and the comma can repeat this search
FW is to find a character before the cursor of the line. W can be any character, and the comma can repeat this search.
ZZ stores the current row in the middle of the window.
ZT is to put the current row in the first row of the window.
ZB puts the current row in the first row of the window.
Ma indicates a at the cursor, where a can be any letter.
'A moves the cursor to sign A, where a can be any letter.
'A moves the cursor to the row where sign A is located, where a can be any letter.
> Indent the current row backward.
<Indent the current row forward
> The lines are indented backward after multiple lines are selected.
<Indent these rows forward after multiple rows are selected
/Word is to search for a word, word can be any string
? Word is used to search for a word. Word can be any string. What is different from? Is in the opposite direction.
N or N is in/or? Switch the search result. N and n are in the opposite direction.
* Or # Is the word at the search cursor. The difference is that the * and # search directions are exactly the opposite.
: Bn or BP switches between buffers when the buffer is added.
: ARGs is used to view multiple opened buffers in one row.
: Ls is to view multiple opened buffers in multiple rows.
: Set nu indicates the row number displayed in the window.
: Set Nonu indicates that the row number is not displayed in the window.
: Set backup backs up an edited file.
: Set nobackup does not back up an edited file. It can be seen that if set is set in pairs, a set a does not correspond to a set Noa.
: Set tabstop = 4: A tab key is displayed with four spaces, and many other settings are similar to their form.
: Set all allows you to view all set settings.
: % S/life/g is to change all life in the file to life. Life and life can be any string, and life can also be a regular expression.
: S/life/g is similar to the above command, but this command does not change all files, only change 1 to 10 lines
: Pwd indicates the current Vim working path.
: The CD is similar to the command in the operating system to change the vim working path.
: LCD %: P: H: Change the vim working path of the current window to the path of the opened file without affecting the working path of other windows.
:! Ls is the command to call the Operating System. ls can be any system command that can be executed. You can also pass some variables in VIM to the operating system commands, for example, in Windows, you can use ::! Explorer %: P: H directory of the file opened in the window
: Ex the folder where the files opened in the vim horizontal window are located
: Vex indicates the folder where the files opened in the vertical window of Vim are located.
: Set mouse = a selection = exclusive selectmode = mouse. The key command allows Vim to point the cursor to the cursor like notepad.
: Hi normal guibg = black guifg = white this command can make your vim interface look better.
: Map y $ is to let y not copy a row, but let it copy the content from the cursor to the end of the row like y $.
: Map \ CD: LCD %: P: H is used to add the image line command: LCD %: P: H to the \ CD command in command mode, change the working path of the current window to the path of the file opened in the current window. Many of your own shortcuts can be defined through this method, and complicated functions can also be defined for processing. If necessary, you can refer to the document for learning.
: Tabnew can open a new tab
GT or GT can be switched between tabs, but they are in the opposite direction.
: E file name can open a new Buffer
GF if there is another file path in the file, this command can be used to access the file when the cursor is on the path.
CTRL + O can return the previous opened file

if you have mastered the above content, you can use Vim normally. You can refer to documents or books to learn and use other useful commands. However, this function is far more important than that, there are also many very convenient plug-ins, such as taglist, bufferexplorer, and nerd_tree. You can learn and use them by yourself, which greatly facilitates Vim text processing capabilities. Of course, the most powerful thing is that Vim can work with shell or batch processing or some other scripts. In this way, the vim function is infinitely magnified, which requires our efforts to discover.
In addition, due to my limited level and a rush in writing, the text may be wrong constantly. I hope you will not be surprised and criticize and correct me more.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.