May 15, 2025 - 15:49
Linux Vi / Vim Text Editor Commands Image
Server Management

Linux Vi / Vim Text Editor Commands

Comments

What is Vi?

The Vi editor is a text editor. It comes pre-installed on every Linux system by default. In other words, it can be used across all Linux distributions. It works consistently on different distributions and platforms. It is a powerful tool. The improved version of the Vi editor is called vim.

The Vi/Vim text editor may appear complex to beginners, but it’s not as complicated as it seems.

Below are the most commonly used commands in the Vi/Vim text editor and their meanings.

ESC is used to switch from insert or visual mode to command mode. You must be in command mode to execute commands. If you are not, press the ESC key to return to command mode.

SWITCHING TO THE INSERT MODE

i Switch to insert mode before the character it is on I Switch to insert mode from the beginning of the line a Switch to insert mode after the character it is in A Switch to insert mode from the end of the line o Switch to insert mode on new line after current line O Switch to insert mode on new line before current line EXIT FROM THE EDITOR :wq Save and Exit :w Save Only :q Exit :w Filename Save with my name as filename ZZ Save and Exit :q! Exit without saving changes :w! Save (for writing to readable file ONLY) SKIP TO REQUESTED LINE j To go down (Same function as Down arrow key) k To move up (Same function as Up arrow key) h To go left (Functions same as left arrow key) l To move right (Same function as Right arrow key) *** If you type NUMBER before j, k, h, l, you can move up, down, left and right quickly. G Go to the last line of the file '' Takes you to your last location in the file DELETE COMMANDS x Delete current character X Delete character before cursor r Replace current character xp Change two characters dd Delete line with cursor D Delete from current character to end of line dG Delete from current line to end of file UNDO / REPEAT u Undo the last command .(POINT) Repeat the last command CUT, COPY and PASTE dd Cut a line yy Copy one line (burned) p Paste after the current line. P Paste before the current line. NUMBERdd Cut / delete rows up to NUMBER NUMBERyy Copy number as many as NUMBER TRANSACTIONS WITH ROWS 0 Move to the beginning of the line with the cursor ^ Go to the beginning of the line with the cursor $ Go to the end of the line where the cursor is located d0 Delete from cursor position to the beginning of the line d$ Delete from where the cursor is located to the end of the line J Merge two (2) lines yyp Repeat the current line (copy / paste) ddp Move rows TRANSACTIONS WITH WORDS w Vocabulary is used to advance the word. b Vocabulary is used to go back NUMBERw Go as far as NUMBER NUMBERb Say back to NUMBER words dw Delete a word yw Copy a word NUMBERdw Delete as many words as NUMBER SEARCH /SEARCH Search from beginning to end of the file ?SEARCH Search right from the end of the file /^SEARCH Search for the expression at the beginning of the line /SEARCH$ Search the expression at the end of the line n To go forward / back in search /\<WORD\> Search by matching exact words (Cannot find any attachments in the word) FIND / REPLACE :START LINE,FINISH LINE s/EXPRESSION WE SEEK/NEW EXPRESSION/g (If we write c instead of g, confirmation is requested each time.) SAMPLE; : 1,$ s/lorem/LOREM IPSUM/g OTHER SOME COMMANDS :sh linux is used for temporary return to the command line (i.e. console). Exit returns to the editor. :! Allows running commands without leaving the COMMAND editor. After the command, you return to the editor. gg Go to top of file GG Go to end of file <CTRL>e Scroll up the file without moving the cursor <CTRL>y Scroll down the file without moving the cursor zt Shows the line with the cursor at the top of the page zb Shows the line with the cursor at the bottom of the page zz shows the line with the cursor in the middle of the page

Related Articles

Comments ()

No comments yet. Be the first to comment!

Leave a Comment