Started using vi probably 13 years ago and ever so often, still learn new tricks with it! 🙂
Some of my favorites are: turning on control characters; mapping function keys; performing global search and replace; remapping columns.
So to the basics, editing a file:
Editing a file from a specific line number or pattern:
vi +lineno filename
vi +/patt/ filename
To turn on control characters, once in vi – do the following (exactly)
To turn it off again:
Map function keys:
:map #1 :w![ctrl v ctrl m]
that is type colon,map,#,1,space,colon,w,!,^M then hit enter. More on this later.
:%s/(col1patt) (col2patt)/2 1/
To finish here is a cool but slightly bizarre one:
It reverses the lines of file. Effectively it says – global (all lines) with this pattern (a beginning line – so all lines), move to 0 – which is shorthand for the current line. So as vi applies the command to each line, it bubbles up to the top.
[tags]vim, regular expression, Unix Coding School[/tags]