Vim compiler related knowledge
1. About the Vim compiler
In popular Linux operating systems, a super easy-to-use text editor is installed by default-the name is “vim” , vimis an upgraded version of the vi editor. vim has the ability to edit programs. It can actively identify the correctness of grammar by font color to facilitate program design.
2. Several modes of Vim
Command mode: control cursor movement, delete, copy and paste text. p>
Input mode: normal text entry.
Last line mode: save, exit and set the editing environment.
Remember that every time you run the vim editor, the default is “command mode“, you need to enter the “input mode“, and return to “command mode” after each editing. Enter “last line mode” to save or exit the text.
3. Enable vim
-
vim -c cmd file: execute the specified command before opening the file;
li>
-
vim -r file: restore the last abnormal exit File;
-
vim -R file: Open the file as read-only, but can be forced to save
-
vim -M file: Open the file in read-only mode, and cannot be forced to save;
-
vim -y num file: Set the size of the editing window to num lines;
-
vim + file: start from the end of the file;
-
vim +num file: start from line num;
-
vim +/string file: Open the file and place the cursor on the first string found.
-
vim –remote file: Use the existing vim process to open the specified file. This is useful if you don’t want to enable multiple vim sessions. But be aware that if you use vim, it will look for a server named VIM; if you already have a gvim running, you can use gvim –remote file to open the file in the existing gvim.
/p>
4. Commonly used commands
1. Delete characters To delete a character, only Move the cursor to the character and press “x”.
2. Delete a line Delete a whole line of content using “dd “Order. After deletion, the lower row will move up to fill the gap.
3. Remove line breaks In Vim you can merge two lines into one line, which means that the line break between the two lines is deleted: the command is “J”.
4. Withdraw If you delete too much content by mistake. Obviously you can enter it again, but the command “u” is more convenient, it can undo the last operation.
5. Redo If you undo multiple times, you can also use CTRL-R (Redo) to reverse the undone action. In other words, it is an undo to undo. There is another form of the undo command, the “U” command, which undoes all operations on a line at a time. The second use of this command will undo the previous “U” operation. Note: You can use “u” and CTRL-R to retrieve any operating status.
6. Append The “i” command can insert text before the current cursor. The “a” command can insert text after the current cursor. The “o” command can start a new line below the current line and change the current mode to Insert mode. The “O” command (note the capital letter O) will start a new line above the current line.
7. Use the command to count Suppose you want to move up 9 lines. This can be done with “kkkkkkkkk” or “9k”. In fact, many commands can accept a number as the number of times to execute the same command repeatedly. For example, in the example just now, three exclamation marks should be appended to the end of the line, and the command used at that time was “a!!!”. Another way is to use the “3a!” command. 3 indicates that the command will be repeated 3 times. Similarly, “3x” can be used to delete 3 characters. The specified number should be immediately before the command it needs to be modified.
8. Exit To exit Vim, use the command “ZZ”. This command saves the current file and exits Vim.
9. Give up editing discard all changes and exit, use the command “:q!”. Use the “:e!” command to discard all changes and reload the original content of the file.
10. Move in Word units< span class="md-softbreak"> Use the “w” command to move the cursor forward on the first character of a word; for example, “3w” moves the cursor forward 3 words. The “b” command moves the cursor backward to the first character of the previous word. The “e” command will move the cursor to the last character of the next word. Command “ge”, it will move the cursor to the last character of the previous word. ,
11. Move to the beginning or end of the line “” command moves the cursor to the end of the current line. If you have a key on your keyboard, it will do the same. The “‘” command moves the cursor to the first non-blank character in the current line. The “0” command always moves the cursor to the first character in the current line. The same is true for the keys. The “” command moves the cursor to The end of the current line. If there is a key on your keyboard, it works the same. The “” command moves the cursor to the first non-blank character in the current line. The “0” command always moves the cursor to the current line The first character of the line. The same is true for the key.” “The command moves the cursor to the end of the current line. If there is a key on your keyboard, it does the same. The “^” command moves the cursor to the current line The first non-blank character. The “0” command always moves the cursor to the first character of the current line. The same is true for the key. The “” command can also accept a count, such as “1” will move the cursor to At the end of the current line, “2” will move the cursor to the end of the current line, “2” will move the cursor to the end of the current line, “2” will move to the end of the next line, and so on. “0” Commands cannot accept counts like this, and adding a count before the command “^” has no effect.
12. Move to the specified character Command “fx” to search on the current line The next character x (to the right) can be searched in the left direction with a command count “F” command. The “tx” command is the same as the “fx” command, except that it does not place the cursor on the searched character, but On a character before it. Tip: “t” means “To”. The reverse version of this command is “Tx”. These 4 commands can be repeated with “;”. The same is repeated with “,” Command, but the direction is opposite to the direction of the original command. span>
13. Move with the purpose of matching a bracket Use the command “%” to jump to the parenthesis that matches the parenthesis under the current cursor. If the current cursor is on the “(“, it jumps forward to the On the matching “)”, if it is currently on the “)”, it will automatically jump backward to the matching “(“Go up.
14. Move to the specified line Use The “G” command specifies a command count, and this command will position the cursor on the line specified by the command count. For example, “33G” will place the cursor on line 33. If no command count is specified as a parameter, “G” will position the cursor on the last line. The “gg” command is a quick way to jump to the first line. Another way to move to a line is to specify a command count before the command “%”. For example, “50%” will position the cursor at In the middle of the file. “90%” jumps to near the end of the file. commands “H”, “M”, “L” to jump the cursor to the first line, middle line, and end line respectively.
15. Tell you your current location Use the CTRL-G command. “Set number” displays a line number in front of each line. Instead, use the command “:set nonumber” to turn off the line number. “:Set ruler” displays the current cursor position in the lower right corner of the Vim window.
16. Rolling screen CTRL-U The window displaying the text scrolled up half a screen. The CTRL-D command moves the window down by half the screen. You can use CTRL-E (scroll up) and CTRL-Y (scroll down) to scroll one line at a time. To scroll forward a full screen use the command CTRL-F. In addition, CTRL-B is its reverse version. The “zz” command will put the current line in the center of the screen, the “zt” command will put the current line at the top of the screen, and the “zb” will put the current line at the bottom of the screen. span>
17. Simple search “/string” command can be used to search for a character string. To find the next position of the last searched string, use the “n” command. If you know that the exact position you are looking for is the number of occurrences of the target string, you can also put a command count before the “n”. “3n” will find the third occurrence of the target string. The “?” command works the same as the “/”, but the search direction is opposite. The “N” command will repeat the previous search, but the original The search direction specified with “/” or “?” is opposite. If the search content ignores case, use the command “set ignorecase”, and return the exact match with the command “set noignorecase”.
18. Find the next word in the text Position the cursor on this word and press “ ” key. Vim will take the word currently under the cursor and use it as the target string to search. The “#” command is the reverse version of ““. You can also add a command count before these two commands: “3*” to find the third occurrence of the word under the cursor.
19 .Find the entire word If you use “/the” to find Vim, it will also match “there”. To find “the” as a separate word, use the following command: “/the>”. “>” is a special notation, it only matches the end of a word. Approximately, “<” matches to the beginning of a word. In this way, to find “the” as a word, you can use: “/\”.
20 .Highlight search results To enable this function, use “:set hlsearch”, and disable this function: “:set nohlsearch”. If you just want to remove the current highlight, you can use the following command: “:nohlsearch” (can be abbreviated as noh).
21. Match the beginning and end of a line< span class="md-softbreak"> The ^ character matches the beginning of a line. The character matches the end of a line. So”/was The character matches the end of a line. So the “/was character matches the end of a line. So “/was” only matches the word was at the end of a line, so “/^was” only matches the word was at the beginning of a line.
22 . Match any single character . This character can match any character. For example, “c.m” can match any case where the previous character is c and the next character is m, no matter what the middle character is.
23. Match special characters Put a backslash in front of the special character. If you find “ter.”, use the command “/ter\.”
24. Use the tag When you use the “G” command to jump from one place to another, Vim Will remember where you took off. This position is a marker in Vim. Using the command “" can make you jump back to the starting point just now.
The command can jump back and forth between two points. The CTRL-O command jumps to the position where you stopped the cursor earlier (hint: O means older). CTRL-I jumps back to the updated position of the stopped cursor later (hint: I is on the keyboard) Located in front of O). Note: Using CTRL-I is the same as pressing a key.
25. Named tag The command “ma” will name the position under the cursor as the tag “a”. A total of 26 custom markers can be used from a to z. To jump to a mark you have defined, use the command “marks "marks is the name of the defined mark. The command "'a" makes you jump to the beginning of the line where a is located, and "
a” will pinpoint where a is located. Command: “:marks” is used to view the list of marks. Command delm! Remove all marks.
26. Operator commands and displacement The “dw” command can delete a word, and the “d4w” command deletes 4 Words, and so on. Similar to “d2e”, “d$”. This type of command has a fixed mode: operator command + displacement command. First type an operator command. For example, “d” is a delete operator. Next is a displacement life. For example, “w”. In this way, wherever the cursor is moved, it is the scope of the command.
27. Change the text The operator command is “c”, change the command. Its behavior is similar to the “d” command, but it will enter the Insert mode after the command is executed. For example, “cw” changes a word. Or, to be more precise, it deletes a word and puts you in Insert mode. The “cc” command can change the entire line. However, the original indentation is maintained. “c” changes the current cursor to the end of the line. Shortcut command: x represents d**l( Delete the character under the current cursor)Xrepresents d**h(Delete the character to the left of the current cursor)Drepresents d” Change the content of the current cursor to the end of the line. Shortcut command: x stands for dl (delete the character under the current cursor) X stands for dh (delete the character to the left of the current cursor) D stands for d “change the current cursor to the end of the line content. Shortcut command: x represents dl (delete the character under the current cursor) X represents dh (delete the character to the left of the current cursor) D represents d (delete the content to the end of the line) C stands for c$ (modified to the end of the line) s stands for cl (modified a character) S stands for cc (modify a whole line) command “3dw” and “D3w” is to delete 3 words. The first command “3dw” can be regarded as the operation of deleting a word executed 3 times; the second command “d3w” is to delete 3 words at a time. This is the unobvious difference. In fact, you can put the command count in both places. For example, “3d2w” is to delete two words, repeat the execution 3 times, for a total of 6 words. span>
28. Replace a single character The “r” command is not an operator command. It waits for you to type the next character to replace the character under the current cursor. The prefix of the “r” command with a command count is to replace multiple characters with the character that is about to be entered. To replace a character with a newline character use “r”. It deletes a character and inserts a newline character. Using the command count here will only delete the specified number of characters: “4r” will replace 4 characters with a newline character.
29. Repeat the changes “.” command will repeat the changes made last time. The “.” command will repeat all the changes you have made, except for the “u” command CTRL-R and the commands beginning with a colon. “.” needs to be executed in Normal mode, it repeats the command, not the changed content,
30.Visual mode Press “v” to enter Visual mode. Move the cursor to cover the range of text you want to manipulate. At the same time, the selected text will be highlighted. Finally, type the operator command.
31. Move text When you delete text with commands like “d” or “x”, the deleted content is still saved. You can also retrieve it with the p command. The “P” command puts the returned content before the cursor, and the “p” command puts it after the cursor. For the entire line deleted with “dd”, “P” will place it on the previous line of the current line. “P” refers to the line after the current line. You can also use command counting for the commands “p” and “P”. Its effect is that the same content is retrieved the specified number of times. In this way, the “3p” after “dd” can put 3 copies of the deleted line at the current position. The command “xp” swaps the character under the cursor with the next character.
32 .Copy text The “y” operator command will copy the text to a register 3. Then you can retrieve it with the “p” command. Because “y” is an operator command, you can use “yw” to copy a word. You can also use commands to count. In the following example, use the “y2w” command to copy two words, and the “yy” command to copy a whole line. “Y” is also to copy the content of the whole line. The command to copy the current cursor to the end of the line is “y$”.
33. Text object “diw” delete the word where the current cursor is (excluding blank characters) “daw” delete the word where the current cursor is (including blank characters) span>
34. Shortcut command < span class="md-plain"> x Delete the character under the current cursor (shortcut command of “dl”) X Delete the character before the current cursor Character (shortcut command of “dh”) D delete the content from the current cursor to the end of the line (shortcut command of “d$”) dw Delete from the current cursor to the beginning of the next word db Delete from the current cursor to the beginning of the previous word diw Delete the word at the current cursor (excluding blank characters) daw delete the word (including blank characters) where the cursor is currently located dG delete the current line to Content at the end of the file dgg Delete the content from the current line to the beginning of the file If you replace the “d” with the “c” command, these commands all become change commands. Using “y” is the yank command, and so on. span>
35. Edit another file Use the command “:edit foo.txt”, also Can be abbreviated as “:e foo.txt”.
36. File list You can specify multiple files to edit when starting Vim, using the command “vim one.c two.c three.c”. Vim will only display the first file after starting. After editing the file, you can use the command: “:next” or “:n” to save the work results and continue editing the next file, command: “:wnext” Or “:wn” can merge this process.
37. Display the file currently being edited< span class="md-softbreak"> Use the command “:args”.
38. Move to another file Use the command “:previous” “:prev” to return to the previous file, and the merge save steps are “:wprevious” “:wprev”. To move to the last file “:last”, to the first “:first”. But there is no such command as “:wlast” or “:wfirst”. You can use a command count before the “:next” and “:previous” commands.
39. Edit another file list You can redefine a file list without restarting Vim. The command “:args five.c six.c seven.h” defines three files to be edited.
39. Auto save command “:set autowrite”, “set aw”. Automatically write the content back to the file: If the file has been modified, in each of :next, :rewind, :last, :first, :previous, :stop, :suspend, :tag, :!, :make, CTRL-] and CTRL-^ command. Command “:set autowriteall”,”set awa”. Similar to ‘autowrite’, but also applicable to “:edit”, “:enew”, “:quit”, “:qall”, “:exit”, “:xit”, “:recover” and closing the Vim window. Setting this option also means that Vim behaves as if ‘autowrite’ is turned on.
40 .Switch to another file To quickly switch between two files, use CTRL-^.
41. File tag Marks named in capital letters. They are global tags, and they can be used in any file. For example, if you are editing “fab1.java”, use the command “50%mF” to set a flag named F in the middle of the file. Then in the “fab2.java” file, use the command “GnB” to set a tag named B on the last line. You can use the “F” command to jump to the middle of the file “fab1.java”. Or edit another file, the “‘B” command will bring you back to the last line of the file “fab2.java”. To know what position a mark represents, you can use the name of the mark as the parameter of the “marks” command “:marks M” Or keep up with several parameters “:marks MJK” You can use CTRL-O and CTRL-I to jump to an earlier position and Somewhere in the back.
42. View the file Only view the file, do not write content to the file, you can edit the file in read-only format . Use the command: vim -R file. If you want to forcibly avoid modifying the file, you can use the command: vim -M file.
43. Change the file name save the existing file as a new file, use the command “:sav(eas) move.c”. If you want to change the name of the file currently being edited, but don’t want to save the file, you can use the command: “:f(ile) move.c”.
44. Split a window The easiest way to open a new window is to use the command: “:split”. The CTRL-W command can switch the currently active window.
45. Close the window Use the command: “close”. You can close the current window. In fact, any command “:quit” and “ZZ” to exit file editing will close the window, but using “:close” can prevent you from closing the last Vim, so as not to accidentally close Vim entirely.
46. Close everything except the current window Other windows Use the command: “:only” to close all other windows except the current window. If any of these windows have been modified, you will get an error message and that window will be left behind.
47. Separate one for another file The window command “:split two.c” can open the second window and start editing in the newly opened window as parameter file. If you want to open a new window and start editing an empty buffer, use the command: “:new”.
48 .Vertical split Use the command “:vsplit or::vsplit two.c”.同样有一个对应的”:vnew”命令,用于垂直分隔窗口并在其中打开一个新的空缓冲区。
49.切换窗口 CTRL-W h 到左边的窗口 CTRL-W j 到下面的窗口 CTRL-W k 到上面的窗口 CTRL-W l 到右边的窗口 CTRL-W t 到顶部窗口 CTRL-W b 到底部窗口
50.针对所有窗口操作的命令 “:qall”放弃所有操作并退出,”:wall”保存所有,”:wqall”保存所有并退出。
51.为每一个文件打开一个窗口 使用”-o”选项可以让Vim为每一个文件打开一个窗口: “vim -o one.txt two.txt three.txt”。
52.使用vimdiff查看不同 “vimdiff main.c~ main.c”,另一种进入diff模式的办法可以在Vim运行中操作。编辑文件”main.c”,然后打开另一个分隔窗口显示其不同: “:edit main.c” “:vertical diffpatch main.c.diff”。 53.页签 命令”:tabe(dit) thatfile”在一个窗口中打开”thatfile”,该窗口占据着整个的Vim显示区域。命令”:tab split/new”结果是新建了一个拥有一个窗口的页签。以用”gt”命令在不同的页签间切换。