Editing common Commands
The following commands are executed in command mode
- I,a,r: Insert character commands before, after, and above the cursor (I =insert,a=append,r=replace)
- O, O: Inserts an empty line before and after the current line
- Cw, dW: command to change (replace)/ delete the word at the cursor (c=change,d=delete)
- X, d$, dd: deletes characters at, after, and in the line where the cursor is located
The cursor
- K, j, H, L: Move the cursor up, down, left, and right respectively
- Ctrl+ F, Ctrl+ B: Scroll down and up, respectively
- N: Type a number and press Enter to move the cursor back n lines
- NG: moves the cursor to the specified line
- W, b: Causes the cursor to skip a word forward or backward
- Ma, MB, MC: Move cursor to start line, end line, paste line
- W or W: Move the cursor right one word to the beginning of the word
- B or B: Move the cursor left one word to the beginning of the word
- E or E: Move the cursor right one word to the end of the word
- (,) : Move the cursor to the beginning and end of the sentence respectively
- {,} : move the cursor to the beginning and end of the paragraph respectively
- H, M, L: Cursor moves to top, middle, and last lines of the screen
- 0 :(note that the number is zero) moves the cursor to the first position
- $: Move the cursor to the end
delete
- NDW or NDW: Deletes the n-1 word at and after the cursor
- Do: Delete to the beginning of the line
- D $: Deletes the file to the end of the line
- NDD: Deletes the current line and the n-1 line after it
- X or x: Deletes a character, x deletes after the cursor and x deletes before the cursor
- Ctrl+ U: Delete the text entered in the input mode
- N1,n2 d: Deletes the contents between lines n1 and n2
- %d: Delete all contents
- 1,$d: delete all contents
To find the
- / ABC: Searches for ABC at the end of the file from the beginning of the cursor
- ? ABC: Searches for ABC at the beginning of the file from the beginning of the cursor
- // ABC: Searches for/ABC at the end of the file from the beginning of the cursor, where/is escaped
- N: Repeat the previous search command in the same direction
- N: Repeat the previous search command in the opposite direction
replace
- S/Vivian /sky/ : Replace the first Vivian in the current line with sky
- S/Vivian/Sky /g: Replace all Vivian in the current row with sky
- N,$s/ Vivian /sky/ : Replace the first Vivian in each line from the beginning of line n to the last line with sky
- N,$s/ Vivian /sky/g: Replace all Vivian in each line from the NTH line to the last line with sky
- %s/ Vivian /sky/g :(equivalent to g/ Vivian /s//sky/) replace each Vivian in each line with sky
- S# Vivian /#sky/# : replace the first Vivian/in the current line with sky/.
- S/P1 /p2/g: replace all p1 in the current row with P2
- N1, N2s/P1 /p2/g: Replace all p1 in rows N1 to n2 with P2
- G/P1 / S //p2/g: Replace all p1 in the file with P2
Copy and paste
- Yy: Copy the current line
- Nyy: Copies n lines from the beginning of the current line
- Press V then arrow keys to select the area, and press Y to copy the selected row
- Dd: cuts the current row
- P (small) : Paste the content below the current cursor.
- P (large) : Pastes the content above the current cursor
- N1,n2 co n3: Copies the contents between lines n1 and n2 to line n3
- N1,n2 m n3: Move the contents between lines n1 and n2 under line n3
Common options Editor options
- Set number: displays the line number
- set number! : Do not display line number, other options add the same! No.
- Set all: Lists all options
- Set ignorance: Ignore case in search
- Set List: Displays TAB stops (Ctrl+I) and end-of-line flags ($)
- Set WARN: Displays NO write message if the current file is not saved when moving to another file
- Set nowrapSCAN: disables vi to search for files at both ends and start from the other end
- Set mesg: allows VI to display information written to its terminal by other users
Editor save
- :wq: Save the configuration and exit
- :q! : Exit without saving the Settings
- :w: Saves the changes
- U: Undo changes
- Ctrl+ R: Redo, used to undo changes