How to get by in vi

I’m not embarrassed to say that these are the vi commands that I’ve been getting by on forever. In the order that I learned them. Thus they are probably a fair representation of the bare minimum one needs to know to survive in the wild and woolly world of vi.

i enter insert mode (for editing)
[Esc] return to normal mode (for commands)
:w save
:wq save and close
:q close
:q! close and ignore changes
x delete one character
dd delete one row
/[text] search for [text]
n find next

Anyway, I just learned three more at work this week.

u undo (last command)
yy cut (or yank) line
p paste

That should hold me for what, another 10 years?

7 Comments

A link I saw today about VIM seems appropriate to link to.

chuck

I have three more commands. The first is a substitute for :w — ZZ. To me its just easier to type the same letter twice than two separate letters.

Also, if you are using vim and you can use the built in spell checker. Add :setlocal spell spelllang=en_us to .vimrc then spellcheck will always be activated.
Spellcheck commands
]s – move to the next mispelled word
[s – move to the previous
zg – add word
zug – undo the addition of a word to the dictionary
z= – word suggestions

Lastly, if you are using vi in mutt it is helpful to read signature files for your e-mail footers. You can do this using this command

:r /path/to/signature/file

Just a few commands that I have learned in the last month using vim.

N: find previous
v: visual selection
V: linewise visual selection
:red: redo

Couple not on the list that I use a lot:

“set number” – to show line numbers.
A – append to end of line.

Also, peep this handsome website.

Man, people are passionate about sandals and vi! What does that say about the people who read my blog? You all must be sandal-wearing programmers, hahaha…

Thanks for all the links and hints.

The other one I love, is string replacement

:1,$ s/stringA/stringB/g

1 = from the first line
$ = to the end of the file
s = substitute
g = all instances

— vIM woot!

Danny Dawson

^: move to start of line
$: move to end of line
gg: move to start of file
G: move to end of file

Yank and paste are indispensable. I assume by now you’ve figured out that paste will paste both yanked and deleted content, yes?

I only recently started using :split filename to open up a second file in the current window. You then use Ctrl-w to navigate between them. :vsplit is good for side-by-side comparisons.

Care to Comment?

Or if you'd prefer to get in touch privately, please send me an email.

Name

Email (optional)

Blog (optional)