"vim--Study Notes"

Source: Internet
Author: User
Tags save file

Vim is divided into three different modes: Command mode, edit mode, last line mode.

Command mode: Copy, paste, replace, move cursor search and so on.

Edit mode: Used to add, delete, modify, and so on the document.

Last-line mode: File save, launch, position cursor, find replace, set line label and so on.

Enter edit mode commands and explanations:
I: Inserts text from the beginning of the cursor position, similar to the Insert key.
I: Inserts text from the beginning of the line where the cursor is located.
A: Insert text from behind the cursor position.
A: Inserts text from the end of the line where the cursor is located.
S: Deletes the character of the cursor and begins inserting text.
S: Deletes the line of the cursor and begins inserting text.
O: Add a line below the line where the cursor is located and start inserting text.
O: Add a line above the line where the cursor is located and start inserting text.
R: The character that replaces the position of the cursor.
R: Replace the cursor with the position, and always replace until you press ESC.
U: Restores a single character operation at the location of the cursor.
U: Restores the action of the line where the cursor is located.
Ctrl+r: Repeats the last action.
J: Merges the row and the next line of the cursor.

Enter the last-line mode command and explanation:
: Enter the command you want to execute below the command mode.
/Enter the search string below the command mode, search down from the cursor position, press N to repeat the previous search action, and repeat the previous search action in n direction.
? Enter the search string below the command mode, search up from the cursor position, press N to repeat the previous search action, and press N to reverse the previous search action.

Launch Vim editor commands and explanations:
Q: No changes have been made to the document, exit.
q!: There have been modifications to the document, but the wallpaper does not save the exit.
QW or x: Save the changes to the document and add it after the command! Indicates that the save is forced to exit.
ZZ: If the document is not modified, the exit is not saved, and if the document has been modified, it is saved and then exited.

Shortcut command:
X/X/NX: Delete one or n characters backward/forward
DD/NDD: Delete Row of cursor or delete n rows down
D1G/DGG: Removes all data from the cursor position to the first row
DG: Remove all data from the cursor position to the last row
d0/d$: Deletes the cursor position to the beginning/end of the line
CW/NCW: Change a character or n characters of the cursor position
Yy/nyy: Copy cursor position to first row or down n rows
Y1g/ygg: Copy the cursor position to all rows in the first row
YG: Copies all lines of the cursor position to the last line
y0/y$: Copy the cursor position to the beginning or end of the line
YW/NYW: Copy cursor position of one character or n characters
p/p: Paste to the next/previous line in the cursor position

Cursor Movement shortcut keys:
H/J/K/L: Cursor left/bottom/up/Right
NJ: Move Down n rows
CTRL+F/B/U/D: Screen down/up/move half page/move one page
N<SPACE>: The cursor moves backwards n characters
N<ENTER>: Move the cursor down n rows
H/M/L: Cursor moves to screen/middle/Bottom
+/-: Cursor moves to the next/previous line of non-null characters
o/^: Cursor moves to the beginning of the line
$: Cursor moves to end of line
GG: Cursor moves to first line
G: Cursor moves to the last line
NG: Cursor moves to nth row

Vim in the last-line mode of common operations:
N1,n2s/word1/word2/g: The word1 from the N1 line to the N2 row is replaced with Word2, and if not, G replaces only the first match.
1, $s/word1/word2/gc: replace the word1 between the first line and the last row with Word2,c for each acknowledgment.
%s/^/word2/g: Insert Word2 at the beginning of each line of the file
%S/$/WORD2/G: Inserts the entire file at the end of each line Word2
%/var/char-&/g: After matching to Var in the entire file, replace with char-var,& to refer to the result of the match, may be a regular match of multiple results, may be a regular match multiple results.

Other commands commonly used in last-line mode:
w/w! : Save File/Force save file
W FileName: Save as FileName file
N1,N2 w FileName: Save as FileName file from N1 to N2 row
R filename: read a different file to the file you are editing
! Command: Temporarily leave VI to execute commands
R! Command: Inserts the output of the commands into the current
SH: Turn the shell, enter exit to return
e!: Restoring a file
Set Nu/set Nonu: Sets line number/Cancel line number
Set Autoindent: Sets Auto-Gill (cancels set noautoindent)
Set ruler: Setting the bottom of the screen displays the row and column position of the cursor
Set ignorecase: Ignores casing in regular expressions
No HL search: Remove highlighted keywords from search

Other actions of Vim
Block Operation:
Press V in command mode to enter operation, move cursor selected action block, press Y to copy, press C to cut, press p to paste.
Horizontally separates window commands while horizontally arranging open files File1.txt and file.txt
[[email protected] ~]# vim -o file1.txt file.txt

Vertically separates window commands while vertically arranging open files File1.txt and file.txt
[[email protected] ~]# vim -m -o file1.txt file.txt

Window move shortcut key: ctrl+w

Problem:
If the file editing process VI is not properly closed, then re-open the VI test.txt is, the system will be prompted to find the swap file. Test.txt.swp, possible reasons are:
1. Another program is also editing the same file
2. Last edited this file is a crash

Workaround:
1. You can press O read-only open, or R for repair, or E to edit directly, or Q to exit
2. After you manually delete the. TEST.TXT.SWP, the prompt does not appear again.

"vim--Study Notes"

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.