Skip to main content

vi editing notes

vi is a Unix text editor that is almost always available, on any Unix or Linux system. Knowing how to edit in it means you’ll always have an editor available, for editing config files or whatever.

To convert a unix text file to a windows/dos text file:%s/$/\^M/  % - the whole file (same as 1,$)   s - substitute   / - substitution delimeter   $ - end of line   \ - (1 backslash) escape next character   ^M - carriage return (enter ctrl-v ctrl-m)Uppercase a file%s/.*/\U&/from: http://sites.netscape.net/ianjdonaldson/Replace tabs with a comma in vi:1,$s/\([TAB]\)/,/gReplace tabs with two spaces. Do it with Perl: perl -pi.anytabs -e 's/\t/  /g' isisboth.incdeletes every line that contains "string":g/string/d   (came from http://bounce.to/vi )deletes every line that does not contain "string":v/string/dor:g!/string/ddelete every empty line:g/^$/dremove trailing blanks :%s/ *$//gReplace the following linescreate user user103 identitified by user103create user user104 identitified by user104create user user105 identitified by user105withgrant connect to user103grant connect to user104grant connect to user105:%s/^.*\(user.*$\)/grant connect to \1/gcopy lines 1 through 5 after line 35:1,5t35copy lines 1 through 5 at the end of the file:1,5t$remove null lines in the file:g/^$/dReplace commas with Carriage Returns:1,$s/,/CTRL-V then press Return and ^M will pop up, then /g10/23/2001Trying to do regex but even simple ones won't work:%s#\(dec.*\)#\1\1#  Substitute pattern match failed:%s#\(dec.\)#\1\1#Anything with .* in it fails.Found that we were pointing at the /usr/ucb version of vedit. Using /usr/bin/vi  it works. Changed the alias to point to right one. This is a common problem where the man entry talks about the version you aren't using.vi - :set ignorecase for case-insensitive searching      :set noignorecase[/literal]To do a quick indent of several lines -Go to the first line that you want to indent and type in the number of lines after that that you want to shift. Then push SHIFT + > (the greater than sign) to move your lines to the right and click SHIFT + < to move your lines to the left (you might have to push the carrot button twice). To change the indention size, you have to set the width in your vi config file. Go to your home directory and add the following line to the .exrc file: "sw=2".