Vi Editor Tips and Tricks

7 Jun
typed command what it does
u undo the last change to the file (and type “u” again to re-do the change)
U undo all changes to the current line
^G show the current filename and status and line number
:set nu Rtn show all line numbers (“:set nonu” gets rid of the numbers)
^L clear and redraw the screen
:%s/Joe/Bob/g Rtn change every “Joe” to “Bob” throughout the document
J join this line to the next line
5J join 5 lines
xp exchange two characters (actually the two commands x=delete and p=paste)
:w Rtn write (save) the current text, but don’t quit VI
:12,17w filename Rtn write lines #12-17 of the current text to a (new) text file
:r filename Rtn read (and insert) contents of a text file
!]]sort -u | cat -n sort all lines from cursor downwards, deleting duplicates, and number the lines
:26,$s/\<[a-z]/\U&/g Rtn Capitalize the first letter of each word from line #26 through the end of the file

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 )

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

%d bloggers like this: