The wonderous colon mode (aka ex commands)


Previous Index Next



Most file level operations start with a :

:efilename Edit another file - :e! forces discard of current edits, :e! with no name reloads current file
:n Edit the next file (vi file1 file2 file3 etc)
:p Edit the previous file (vi file1 file2 file3 etc)
:w Write the current file (can give a name for save as)
:q Quit - :q! to quit with unsaved data
:r Insert a file at the current cursor position
:!Shell command Just start a shell command, when it exits return to vi.
:set Set options - More in a few slides time
:addresss/regexp/replace term/options Very powerful search facility. Address is area to search over - e.g.
:%s/hello/goodbye/gSearch entire file (the %), replacing hello by goodbye. The 'g' option gives multiple replaces per line
:'a,'b/hello/goodbye/gAs above but only between marks a and b
:%s/hello/goodbye/gcEntire file, ask for each replacement
:%s/$/;/Tack a ; on the end of each line
:%s/(.*)/{&}/Tack a {} pair round each ()'d thing - note line based
:address operatorMost vi operators can be used in colon mode; e.g. :'a,'b> to indent an area
:addressg/search pattern/colon commandExecute a colon command for every matching line

Copyright Dr. David Alan Gilbert 2001. vitalk @ treblig.org - Hacked together with dsh