Vim-1-basic usage

Source: Internet
Author: User
Tags add numbers
------------------------------------------------------------------------------------ Gvim has four modes: Normal Mode, insert mode, replace mode, and command mode.
Normal Mode insert mode I/I insert a/A at the beginning of the cursor/line at the beginning of the line insert a/A at the end of the cursor/line insert O insert at the beginning of the next line o insert s at the beginning of the last line delete the cursor enter the character and start to insert it. For more information, see X) c. Start deleting, and enter the insert mode (for specific usage, see D). The insert mode is the same as that in windows. All shortcut keys can be used. In normal mode, CTRL + S is still saved.
Normal Mode replace mode R: Replace the character number where the cursor is located R: Replace the n characters behind the cursor R: Replace the character where the cursor is located, and Press ESC to return to normal mode
Normal Mode Command mode: Press:
Insert mode, command mode, normal mode: Press ESC. Note: I have mapped the ESC in insert/replace mode to KK, in the insert/replace mode, press KK to return the normal mode. In the swap mode, press the default mode -------------------------------------------------- move: h j k l: Move the number h j k l to the bottom left: bottom left top right move n bottom w/E: Move to start/end B/B (GE): Move to the beginning/end of the previous word F/T A: In the current row, move to the next position where a appears/Front F/t a: In the current row, move to the previous position where a appears/front number F/t: move the current row backward to the position where a appears n times/the first digit F/t a: Move the current row forward to the position where a appears n times/the first 0/$: locate the beginning/End of the line ^/g _: locate the beginning/End of the line without spaces %: In two matched symbols ((,",{) and so on (the cursor must first move to one of the symbols, if not, it will find the nearest one) Number %: locate the position of the document by percentage G: locate the first line of the last line G: locate the first line of the corresponding line GG: Move to the first line of the first line h: locate to the top of the current screen M: locate to the middle of the current screen l: go to the bottom of the current screen Ctrl + U/D: Scroll up/down half screen Ctrl + F/B: Scroll up/down the whole screen ZZ: set the current row to the center of the screen J: Move the next row to the end of the row (merge the current row and the next row) about the number key: Number + command to execute multiple operations, the number is usually placed before the command.
>>/<: The current row increases/decreases indent =: The current row is automatically indented.
'': The backticks switch between two jump points. If you are in row 33 and jumped to line 55, you can use this command to return to line 33. If you use this command multiple times, you can switch back and forth, note: The jump caused by J and K cannot be, and must be switched between positions in different rows Ctrl + O/I: Jump to the previous/next cursor position (not in the same row, and the cursor is not moved due to hjkl)
------------------------------------------------ Search:/XXX: Search for XXX in the whole text and highlight it. * [] ^ % /?~ $ Has a special meaning. Do I need to use \ escape? XXX: The same as/, but the reverse direction is n/n: switch between the highlighted positions. You can add a number to the front, it indicates that Vim records the content that has already been searched at the nth position. When searching again, you can switch through the up/down key #/*: move to the previous/next word that is the same as the word where the cursor is located/\ <XXX \>: match the complete word. If a word only contains XXX, it will not be matched.
Pattern Search (Regular Expression search): ^ indicates the beginning of a row, $ indicates the end of a row, ^ The indicates. represents any character ., you need to escape a useful command: nohlsearch, which can cancel the current highlight, abbreviated as nohl -------------------------------------------------- copy, cut, delete, and paste: in Vim, cut and delete are the same. In the following commands, there are no spaces in the middle. This is just for ease of reading. Note: You can add numbers before almost all the commands, such as move, copy, and paste, indicates the number of duplicates, or you can add a move key to almost all of them, indicating to copy/cut y to a certain direction: Start to copy YY/Y: copy the current row YY: Start from the current row, copy multiple lines Y 0/$: copy a word from the cursor to the beginning/End of the line y w/E: copy a word, or copy from the cursor to the end of the word yt: copy from the light mark until a, a does not copy YG: copy from the current row until the last row yyg: copy from the current row until the first row X: cut/Delete the character where the cursor is located, still staying in Normal Mode X: Delete the character number on the left of the current cursor X: Cut/delete n characters from the beginning of the cursor, still stuck in normal mode d: start to cut/delete (usage is similar to Y, not to mention) dd: Cut the entire line D: cut to the end of the line content (this is different from Y) p: paste the copied/cut content to the end of the cursor. If it is an entire row, paste it to the top of the current row. P: paste the copied/cut content to the front of the cursor, if the row is a whole row, paste it to the number P/P below the current row: paste DDP multiple times: in fact, it is to delete the current row and then paste it, but you will find that, the current row and the next row are replaced by XP: in fact, it is to delete the character where the current cursor is located and then paste it, but you will find that the two character switching positions are
.: In normal mode, repeat the previous command. Except for the U command, this command can only repeat the latest one. For example, you can first search for XXX in the full text and then cwyyy to change it to yyy, then return to normal mode, N. n. n. keep pressing, and then the XXX will be converted to yyy. The command cwyyy will always repeat ---------------------------------------------- copying and deleting a Text object is a character, the unit of action, W, E is used from the cursor to the start of the next word or the end of the word. to delete the entire word, you must first move the cursor to the beginning of the word, which is very troublesome, you can use a Text object to get AW: a word, indicating a word and its trailing blank space. Daw indicates deleting the word where the cursor is located and the blank IW: inner word, which also indicates a word, however, it does not include the blank space after the word as: a sentence, which indicates a sentence and the blank space behind it. Das indicates that the sentence where the cursor is deleted and the blank space is: inner sentence, which also indicates a sentence, but it does not include the white space behind the sentence.
------------------------------------------------ Visual Selection: V: Visual selection, Press ESC or press V again to exit. The selected content will be copied in the visual selection mode. The mobile key and numeric key can all be used. V: select Ctrl + q for the whole line of visualization: The Block visualization selection should actually be Ctrl + V, but in Windows this is paste, So GG is not used, then press Ctrl + q (CTRL + V) and press g to select the first column of the text, move the cursor to the other end of the selected area. O: move the cursor to the other end of the line in the block visualization selection status ---------------------------------------- macro: Press Q to start recording macros, generally, keep up with the register name. The register can use 26 letters, such as Qm, to record the macro into the M register. Then, a series of operations will be recorded, and Q will be re-pressed, exit macro recording and Press @ M to display the macro in the M register. You can add a number to indicate the number of playbacks. Press @ to indicate the macro that has been played before. ------------------------------------ Automatic completion: CTRL + P: Awesome
------------------------------------------------ Clipboard: Y, D, C, X and other commands are all stored in the vim clipboard. How can we interact with the clipboard in windows? Add "* before these commands.
---------------------------------------------- Others: U: undo the last operation, u: undo the row, can cancel all the edits on the last row. CTRL + R: Restore the last operation (CTRL + y, but it is the shortcut key in Windows) Ctrl + L: sometimes some text in VIM will be spent, this shortcut key refreshes the view Gu/Gu: converts the selected content to uppercase/lowercase Ctrl + P: automatically fills in the previously edited words, phrase ZZ: exit the currently edited file ghost command mode -------------------------------------------------- General Command: The command mode has a ":" W: Save and do not exit WQ/X: Save Save and exit Q/Q!: Do not save exit/force do not save Exit E!: Discard all modifications and load the initial state of the file. Use it with caution! PWD: displays the current directory! Shell Command: execute shell (DOS) command R! Shell Command: Write the execution result of the shell (DOS) command to the current line. In command mode, press the up and down arrow to switch the command that was previously entered ------------------------------------ edit multiple files: e/edit file path: open the file on the current tab, and use/or \ in the path. You can use the tab key to automatically complete the file name. You can also open multiple files at a time. Previous/next is separated by spaces in the file path: switch to the previous/next open file wprevious/wnext: Save the current file, switch to the previous/next open file BP/BN: switch to the previous/next file vim-r filename on the current tab, and open the file as required.
------------------------------------------------ Split window: Split a window above the current window, the new window is still the current file new: Split a new empty window split filepath: open the file new filename in the new window: edit the file split in the new window. You can add a number to the front of the new command to indicate the height (number of rows) of the new window Ctrl + W: in two or more windows, press Ctrl + W +/Ctrl + w-: the current window expands/shrinks a row. You can add a number to the front, CTRL + W _: Convert the window to the specified height: Close/: Q/ZZ: All other windows can exit the current window. Only: Close all other windows, only keep the current window wall, save all, qall, close all
CTRL-W H to the left of the window CTRL-W J to the following window CTRL-W K to the above window CTRL-W L to the right of the window CTRL-W T to the top of the window CTRL-W B to the bottom of the window Ctrl-W H, j, K, L, move the window up and down

---------------------------------------------- Tabs generally use tabe, tabedit, and tabnew. tabe is used below unless in special cases tabe: open a new tab tabe:/XXX: open the file tab in the new tab: The following command can open a new window (such as help), open a new window in the new tab, such as Tab help
---------------------------------------------- Replace: [range] S/from/to/[flags], which means to replace the range from with to, and flags matches the range S/AAA/BBB /: replace the first AAA of the current row with BBB. If the flag is not specified, replace the first % S/AAA/BBB/G: replace all AAA in the full text with BBB, G indicates that all matched row numbers 1 and row numbers 2 S/AAA/BBB/G: replace AAA between Row 1 and row 2 with BBB row number 1, row number 2 S/^/AAA/G: Add AAA (that is, you can use regular expressions) before the row between Row 1 and row 2 ,. indicates the current row. $ indicates the row number 1 of the last row and the row number 2 S/^/\/G: add // comments to the rows between line number 1 and line number 2 (this is because/has a special purpose and needs to be escaped) line number 1, line number 2 S // \/G: remove the lines between Row 1 and row 2 // another escape method is to use + to replace/,/normally, for example, 4,8 S + AA/BB + AA or BB + ---------------------------------------------- locate the following command and return the normal mode G: locate the last row: locate the corresponding Row 1, row 2D: delete the content line 1 from row 1 to row 2, Row 2 >>: move a tab line 1 to the right from row 1 to row 2, Row 2 >>: move a tab/XXX from line 1 to line 2 to left: Search for XXX in the whole text and highlight it. Press the n key to switch between the selected items ------------------------------------------------------------------------------------



From Weizhi note (wiz)

Attachment List

     

    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.