Wherever possible I use vi or a newer incantation of it called vim, but I try to stick to low common denominators so that my editing is “portable” across platforms.
I learned vi the hard way, on a terminal for which (thankfully) no cursors or function keys were defined in termcap/terminfo. This forced me to spend a quarter of an hour practicing and learning that l
or <space>
moves the cursor to the right and j
moves it down. (And that J
is something completely different.)
The worst part of my learning experience was the bell: I couldn’t turn it off on that terminal, and it drove me crazy the first day. I quickly understood command mode and text enter mode in order to avoid the beep, and I’ve not looked back.
Why “thankfully” no cursor block? The .
command works properly, movement (65l
or 7W
) becomes easy. Finding a $
in the line becomes f$
or reverse F$
, and performing a bunch of changes (but not global search/replace) becomes /search
, then a change, say, cwblablaESC
, then n
next and n
next, and finally .
to repeat whichever change I did last (yes, also deletes, or appends, or inserts: any change).
I think for close on twenty years I had a .exrc
which consisted of two lines:
:set ai
:ab KK /*x */ESCFxs
A few years ago I went all out when I started doing Python, and my .exrc
became a .vimrc
which still contains those two lines plus
filetype plugin on
" au BufRead,BufNewFile *.py set expandtab
" au BufRead,BufNewFile *.py set tabstop=4
" au BufRead,BufNewFile *.py set backspace=indent,eol,start
" autocmd BufRead,BufNewFile *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
There have been times when I’ve been a bit jealous of people who master Emacs: the fact that they can, from their editor, read mail, post news (Usenet news; you probably don’t know what that is), and do all sorts of crazy things tempted me to learn it, and I have done a bit of that: I tend to write up notes in Org mode, but I’ll confess that muscle-memory for vi commands is an order of magnitude more developed than it is for emacs.
I’m writing this to drive home that whatever editor a person uses is fine, as long as that person utilises the editor properly, and if you’re good with Microsoft’s VS-Code, I might be in awe at what you can do with it. (Although you need a graphical terminal; I don’t.)
I give lots of trainings, and I almost literally cry when I see people stumbling in vi, hitting ESCape three times after adding a bit of text, adding a character by inserting, then ESCaping, then moving back a key deleting the superfluous character – it’s horrid. It’s almost as bad as watching people go up 17 times in their shell history to find .. ls
. (There have been cases of me honestly yelling at people for doing that, but I fear they’ve forgiven me meanwhile.)
Use a text-editing utility that you can handle and like to use. Unix has lots of editors. I’m not going to say ed(1), but there’s Nano and Pico and mg, and loads of them. Use one which is convenient and simple to wield. Become proficient in editing. Please.
If you don’t have the time or the patience to learn vi or emacs, don’t; you’ll find I’ll respect you more if you stick to notepad.exe
, nano
, or whichever. :-)
Way back then, I also learned how to exit vi, and that was not using :wq!
because that broke how make
works and incremental backups again picked up files which didn’t have their content modified. If you use vi, learn about ZZ
or :x
and save on a key press… It’s all about being efficient when editing text, and :wq
still does things you need to be aware of.
I wrote a 700-page book using vi. True story.