[Ryedale] Vim tips

Al Girling acgirling at gcguk.demon.co.uk
Mon Feb 11 21:50:54 GMT 2008


Hi folks,

I recently posted this to the Sussex LUG list after attending a talk on
VI there in January.  It seemed sensible to use it here too, so here you
are.

Multiple files can be open in a vim session by opening with a:

$ vim *.txt

You can work your way through these file known as buffers in vi/vim with
ex/colon commands.  So:

:wn

Is short for Write and next buffer, similarly the following commands
work to reverse your flow through the list of open buffers.

ctrl-^ or :prev or key :ls to see the number of the previous buffer and use
:b<n> were <n> is the buffer number.

Something else I use regularly is the word completion as read from the system
dictionary.

Say your keying anaesthesiologists, but can't remember how many vowels and what
order they go in.  Start with an, and while still in insert mode, key ctrl-x,
ctrl-k to get a drop down list from which to choose.  You can also add other
dictionaries or your own word files too.  The ctrl-x commands also allow you to
use path and filename completion with ctrl-x, ctrl-f.  You can repeat lines
with ctrl-x, ctrl-l also.

During the vi talk, Steve described a method of doing search and replace across
multiple files.  I've done it like this for a while.

With the files you wish to edit placed in buffers and wanting to change <foo>
with <bar> use:

:argdo %s/<foo>/<bar>/gce |w

The flags gce mean:

g == replace all occurrences on a line.
c == confirm you wish to make the change.
e == if the pattern fails, continue and don't print an error message.

The |w is required to write each file before the next can be edited.

So this command runs through all matches to your pattern in all your chosen
files, stopping at each match and asking for a 'y', 'n' response.

This is one of my favourites.

To add characters to the end of a list with different lengths as seen below
using block select ctrl-v.

one
two
three
four
five

Place the curser on the 'e' in one.  Key ctrl-v and move to the bottom of the
list in what ever way you choose.  Key '$' for end of line and then 'A' to
append at the end of the line.  Add your chosen text and hit the ESC button.
Voila!  Your chosen text added to all the lines you selected.

Toodle pip,

Al


-- 
Al Girling

Linux User: #290080             <http://counter.li.org>
Home-page:                      <http://al.sdf-eu.org>



More information about the Ryedale mailing list