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:file
:%s/$/\^M/-– the whole file (same as 1,$)s-–substitutesubstitute// -– substitutiondelimeterdelimeter$$ -– end oflineline\\ -– (1 backslash) escape nextcharacter ^character^M-– carriage return (enter ctrl-v ctrl-m)Uppercase a
file%file
%s/.*/\U&/
from: http://sites.netscape.net/ianjdonaldson/Replace tabs with a comma in
vi:vi
:1,$s/\([TAB]TAB]\)/,/gReplacegReplace tabs with two spaces. Do it with Perl:
perl -pi.anytabs -e'‘s/\t/ /g'g’ isisboth.incdeletesincdeletes every line that contains
"string"“string”
:g/string/d (came from http://bounce.to/vi )deletes every line that does not contain
"string"“string”
:v/string/dor:d
or
:g!/string/ddeleteddelete every empty
line:line
:g/^$/dremovedremove trailing blanks
:%s/ *$//gReplacegReplace the following
linescreatelines
create user user103 identitified byuser103createuser103
create user user104 identitified byuser104createuser104
create user user105 identitified byuser105withgrantuser105
with
grant connect touser103grantuser103
grant connect touser104grantuser104
grant connect touser105:user105
:%s/^.*\(user.*$\)/grant connect to \1/gcopygcopy lines 1 through 5 after line
35:35
:1,5t35copy5t35copy lines 1 through 5 at the end of the
file:file
:1,5t$remove null lines in the
file:file
:g/^$/dReplacedReplace commas with Carriage
Returns:Returns
:1,$s/,/CTRL-CTRL-V then press Return and ^M will pop up, then /g10/g10/23/
2001Trying2001
Trying to do regex but even simple oneswon'won’twork:work
:%s#\(dec.*\)#\1\1# Substitute pattern matchfailed:failed
:%s#\(dec.\)#\1\1#Anything1#
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 youaren'aren’t using.vi
-– :set ignorecase for case-insensitive searching
:setnoignorecase[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"2”.