Detailed explanation of vim command under linux

  
        

A very detailed introduction to the operation commands of vim in linux.

Some advanced editors will contain macro functions. Of course, vim can't be missing. It is very convenient to use macros in vim:
:qx Start recording macros and save the result in register xq to exit Record mode @x Play the macro command recorded in the x register. Explain slightly. When you enter: qx in normal mode, all the editing actions for the text will be recorded. Enter q again to exit the recording mode, then Enter @x to repeat the command you just recorded. This command can be followed by a number indicating how many times to repeat, such as @x20, which can be repeated 20 times. This is very useful in batch processing of text. Editing multiple files at the same time In the many plugins of vim, there is a plugin called minibuffer, which is the tab page function mentioned below, which can support editing multiple files at the same time. Label command: tabe fn Edit file fngt in a new tab switch to the next tab gT Switch to the previous tab: tabr Switch to the first tab: tabl Switch to the last tab: tabm [N] After moving the current tab to the Nth tab, as you can imagine, the tabs with eclipse, ue, etc. are a meaning! Window command ctrl+ws horizontal split window ctrl+ww switch window ctrl+wq exit the current window (because there are multiple files at the same time, this command will not affect other windows) ctrl+wv vertical split window other vim will not be on the file before saving Do the actual modification, just load into the buffer, the editing of the file is actually the editing of the buffer, until the :w will be stored in the physical file. :e file Load file into new buffer: bn Jump to next buffer: bd Delete buffer (close file): sp fn Split window and load fn into new window Exit editor: w Write the buffer to the file, ie save the modification: wq save the modification and exit: x save the modification and exit: q exit, if the buffer has been modified, it will prompt: q! forced exit, abandon the modification to find the replacement /pattern direction After the search string pattern?pattern forward search string patternn next match (if yes /search, then the next one, ? search is up next) N previous match (same as above): %s /Old/new/g Search the entire file, replace all old with new:%s/old/new/gc Search the entire file, replace all old with new, every time you have to confirm whether to replace copy and paste dd delete cursor The line dw deletes a word (word) x deletes the current character X deletes the previous character D deletes the line to the end of the line yy copy a line, this command can be followed by a number, the number of copies is copied, such as 6yy, indicating that 6 lines of yw are copied from the current line. Copy a word y$ copy to the end of the line p sticky Paste the contents of the board to the bottom of the current line. P Paste the contents of the paste board onto the top of the current line.]p Indented paste, vim will automatically adjust the indentation of the code"a put the contents into/stored in a register, you can Support multi-paste board attached: For example, a commonly used register is the system register, the name is +, so the command pasted from the system paste board to vim is "+p, note that the + here does not represent the operator, twenty-one register. Moving the cursor to move the cursor in vim is very different from other editors, but once you learn it, it will move quickly in the text. h,j,k,l up, down, left, right ctrl-f up one page ctrl-b down one page % jump to the brackets matching the current brackets, as currently in {, then jump to The matching } w jumps to the next prefix, splits by punctuation or word W to jump to the next prefix, long jump, such as end-of-line is considered a word e jumps to the next suffix E jumps to the next One suffix, long hop b jump to the previous word B to jump to the previous word, long jump 0 to the beginning of the line, whether with or without indentation, jump to the 0th character ^ jump to the first character at the beginning of the line $ jump to the end of the line gg jump to the first line of the file gd jump to the declaration of the variable where the current cursor is located [N]G jump to the Nth line, such as 0G, is equivalent to gg, 100G is the 100th line fx Find the x character in the current line, jump to the found; repeat the previous f command, instead of repeating the input fxtx similar to fx, but only jump to the previous character of x where Fx is opposite to fx), Jump to the upper/next statement* Find the word where the cursor is located, look down # Find the word where the cursor is, and look up `. Jump to the last edit position Move H on the screen Cursor to the top line of the current screen M Move the cursor to the middle line on the current screen. Move the cursor to the bottom line of the current screen. Bookmark ma Save the current position as the label a`a Jump to the label a. Edit r Replace A character J connects the next line and the current line as a line cc Deletes the current line and enters edit mode cw Deletes the current word and enters edit mode c$ Erases the content from the current position to the end of the line, and enters edit mode s Deletes the current character and Enter edit mode S Delete the line where the cursor is located and enter edit mode xp Exchange the current character and the next character u Undo ctrl+r Redo. Repeat the previous edit command~ Switch between upper and lower case, the current character g~iw switches the case of the current word gUiw Change the current word to uppercase guiw Change the current word to lowercase>> Move the current line to the right by one unit<< Move the current line one unit to the left (a tab) == Automatically indent the current line Insertion mode i Enter the insert mode from the current cursor. Enter the insert mode, and set the cursor to the line a. Append mode. Set the cursor to the current cursor. A append mode, set the cursor to the line. o Add a new line below the current line and enter insert mode O Add a line above the current line and enter insert mode Esc Exit insert mode Visual mode mark text v Enter visual mode, single character mode V enters visible Mode, line mode ctrl+v enters visual mode, column mode, similar to UE's column mode o Jump cursor to another endpoint of the selected block U Converts the contents of the selected block to uppercase O Jumps the cursor to the block An endpoint aw select a word ab to select all the content in the brackets, including the bracket itself aB select all the contents of the {} bracket ib select the content in the brackets, without the brackets iB select the contents of {}, without the {} pair of markers Move Action > Block Right Shift < Block Left Shift Copy Block d Delete Block ~ Switch the case of the contents of the block

Copyright © Windows knowledge All Rights Reserved