Like learning a language from a book (or extending your vacabulary from the 'net, where you see but don't hear words), you miss subtleties. Such has been my vi-fu. Going back into a real job for the first time in six years, and the first time in perhaps nine years where I've worked with other programmers who used vi seriously, I'm finding that my self-taught vi skills are, uh, incomplete. Finding these holes sent me on a mission to find other holes, going back and finding and reading good ex and old vi documentation, and here are the fruits of my labor. This list is just stuff that's in nvi -- I might switch to vim, but, for now, I wanted a list of things that were right under my nose for years and years.
^A -- search forward for the word under the cursor
R -- like i, except overtypes instead of inserts
A -- jump to last non-blank character in line and enter append mode (like insert mode)
I -- jump to first non-blank character on the line and enter insert mode
^Y -- staying on same line, center screen on line, then subsequently, still staying on same line, scroll screen down one line, exposing stuff above the current line
^] -- find the definition or next occurance of the tag under the cursor
^T -- return to where we were before the last jump-to-tag with ^]. nvi has a whole tag stack, but I won't get into that here.
% -- as an address (eg, instead of 10p or 1,$!), means the entire file (same as 1,$)
%!sort -- sorts all of the lines in the file
> -- indents the current line by whatever tabstop is set to
^W -- change which split window you're in of the those on the screen
I'm an nvi user -- I started with the *real* AT&T ex, pre-Bill Joy, so keep in mind that vim is a radical departure for me. Some of the defaults annoy the hell out of me -- syntax highlighting, automatic indenting... yes, I can turn them off, but I couldn't seem to make an rc file to do so -- the normal vi conventions for doing so are broken, and even vim users had lots of trouble doing so because of this brokeness. I'm not sure how or where, but it seems like there are lots of other pieces of brokenness. Or maybe not. But now I have incentive to find out. That'll be another article, though.
-scott
More vi (Score:1)
I've rarely found that useful...more often it's:
Re: (Score:1)
In vim, I use a visual selection for the job. Shift-v in normal mode takes you to visual line mode; select the line range you want to manipulate, then type :!sort. Note that vim will automatically type '<,'> for you when you go from visual mode to command mode, so the command actually executed is
'<,'>!sort, which filters the selected lines through sort.Very handy. Also nice for selectively perltidying code and such.
Config file (Score:1)
another vi indent trick (Score:1)
>i{ -- indent the enclosing {
--Brock