vi / vim Shortcuts

Open file
vi filename
As i am newb on linux macine, i dont know vi shortcuts.
so, i am listing down shortcuts which i am getting familier. 🙂

Insert in file

Exit file

forced exit

save file

forced save

Copy no of lines

Paste copied lines

Undo changes

Delete lines

To search and replace string in vi

To find particular word in file

If you have any quick list. please, let me know

2 thoughts on “vi / vim Shortcuts

  1. original post at is a very powerful editor that has been part of nearly every linux/unix distro for a very long time. Many people stray away from Vi due to the curve involved in learning this editor. This guide will help you dive into the world of Vi. Once you do, you will understand why many prefer Vi over other editors.There are countless options for Vi that can be set up inside the /etc/vimrc file.Auto-indent and creating a macro to change the color of the background.# vi /etc/vimrcAuto-Indent Option -This option is so when you tab-space out a line and then press enter, the cursor will move to the next line, automatically indented to the start of the previous line. This helps programmers indent out code easily to create clean looking code. To implement this feature, please add the following line to the bottom of your /etc/vimrc file:set aiPlease note that generally speaking only programmers will want to turn ON auto-indent.Background Color -Some SSH clients have white backgrounds and some have black backgrounds. This can make it very difficult to see the screen depending on the color of the text. This macro allows you to configure F11 to change the background color & color of the text. To implement this feature, please add the following lines to the bottom of your /etc/vimrc file:set background=darkmap :let &background = ( &background == “dark”? “light” : “dark” )I would highly recommend adding in the Background Color option. However if you do not wish to implement either of these features, then please proceed on in the guide.CommandsCursor Movement0 (Zero) Start of Line^ – First non-Blank Character of Line$ – End of LineG Go To Command (prefix with number 5G goes to line 5)Insert Mode Inserting/Appending TextInsert Start Insert Mode at CursorA Append at the end of the Lineo open (append) blank link below current lineI Open blank line above current lineEsc Exit Insert ModeEditingr Replace a single character (does not use insert mode)J Join line below with the current onecc Change (replace) an entire linecw Change (replace) to the end of wordc$ – Change (replace) to the end of lines Delete character at cursor and substitute textS Delete line at cursor and substitute text (same as cc)u Undo. – Repeat last commandCut and Pasteyy Copy(yank) a line2yy Copy(yank) two linesyw Copy(yank) wordp Paste the clipboard after the cursorP Paste the clipboard before the cursordd Delete a linedw Delete the current wordx Delete the current characterExiting:w Write (save) the file, but don’t exit:wq Write & Quit:q Quit:q! – Quit and don’t save changesSearching/pattern Search for a pattern?pattern Search backward for a patternn Repeat last search in same directionN Repeat last search in opposite direction:%2/old/new/g Replace all old with new throughout file:%s/old/new/gc Replace all old with new throughout file with confirmationsWorking with Multiple Files:e filename Edit a file in a new buffer:bn Go to next buffer:bp Go to previous buffer:bd Close file(buffer):sp filename Open a file in a new buffer and split windowctrl-ws Split windowsctrl-ww Switch between windowsctrl-wq Quite a windowctrl-wv Split windows verticallyctrl-wq Quite a windowctrl-wv Split windows vertically

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.