Unix VI Commands Cheat Sheet

:wq or  ZZ To exit vi and save changes
:q! To exit vi without saving changes
:q To exit vi witout saving changes. ( if no changes done )
:e! reads the original file back in so that you can start over. When you open file and do some changes but now if you don’t want to save those change and wants original file name.
:w file_name vi Saves a file with new name specified
:wq file_name vi Saves a file with new name specified and exit
:w! To save a content even if it is in read only mode
:w! prevfile write current contents over a pre-existing file named prevfile
:n vi file1 file2 … To open next  file for edit when we give multiple files for vi
:p vi file1 file2 … To open previous file for edit when we give multiple files for vi
:n file_name To open new file to edit. Here we don’t need to give multiple files to “vi”
:! [unix_command] By using this we can execute any unix command in vi editor only.
:r! [unix_command] read output of command into VI
:r [filename] read filename into VI
:$r newfile read in newfile and attach at the end of current document
:r !sort file read in contents of file after it has been passed through the UNIX sort
:^g list current line number
:set number show line numbers
:set nu show line numbers
:set nonu Remove line numbers
:set nonumber Remove line numbers
:set showinsert show flag (“I”) at bottom of screen when in insert mode
:set all display current values of VI variables
:set ai set autoindent; after this enter the insert mode and tab, from this point on VI will indent each line to this location.  Use ESC to stop the indentations.
:set tabstop=n sets default tab space to number n
:sh escape temporarily to a shell. To come back to vi we need to “exit” from shell. Or CTRL-d
Related Posts Plugin for WordPress, Blogger...

Be the first to comment

Leave a Reply

Your email address will not be published.


*