Bootstrap FreeKB - Linux Commands - Common vi editor commands
Linux Commands - Common vi editor commands

Updated:   |  Linux Commands articles

Toggle between Command / Insert / Replace Modes

Mode Command What it does
Command i Changes the mode to "Insert" with the cursor before the current position
Command a Changes the mode to "insert" with the cursor after the current position
Command I Changes the mode to "insert" with the cursor at the beginning of the current line
Command A Changes the mode to "insert" with the cursor at the end of the current line
Command o Changes the mode to "insert" and inserts a new line below the current line
Command O Changes the mode to "insert" and inserts a new line above the current line
Command R Changes the mode to "replace" and lets you replace characters
Insert esc Changes the mode to "Command"

 

Save / Quit

Mode Command What it does
Command :w Writes / save
Command :q Quits vi editor
Command :q! Quits vi editor without saving
Command :x Write, save, and exit
Command Shift ZZ Write, save, and exit
Command :e! Returns the document to the last saved copy (undo)

 

Copy / Paste / Change / Replace / Delete Text

Mode Command What it does
Command yy "yank", copies the entire line
Command yw / y2w / y3w "yank", copies the word / copies 2 words / copies 3 words
Command p (lower case) "paste", after the cursor
Command P (upper case) "paste", before the cursor
Command cc "change", erases the entire line so you can "change" the line
Command cw / c2w / c3w "change", allows you to change the word you are on / change 2 words / change 3 words
Command r Let's you replace the character the cursor is on
Command :%s/old/new/g Finds every occurrence of "old" and replaces it with "new".
Command :%s/old/new/gi Finds every occurrence of "old" and replaces it with "new". i means "old" is not case sensitive.
Command :%s/old/new/gc Finds every occurrence of "old" and replaces it with "new". c means there is an interactive prompt.
Command dd Deletes entire line
Command dw / d2w / d3w Deletes the word the cursor is on / deletes 2 words / deletes 3 words
Command u undo the last change
Command U undo all the changes to the current line

 

Searching

Mode Command What it does
Command / Searches, starting at the beginning of the file
Command ? Searches, starting at the end of the file
Command n Search down for the next match of the string
Command N Search up for the next match of the string

 

Moving the cursor

Mode Command What it does
Command h Moves the cursor to the left
Command j Moves the cursor down one line
Command k Moves the cursor up one line
Command l Moves the cursor to the right

 

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter faf1b1 in the box below so that we can be sure you are a human.