Pages

Add some pages here, or start a new chapter.

Linkdump

» Belkin WeMo This kind of looks like the future of home automation.
Belkin WeMo

Nice feature overview here.

X10 is cool but complicated; whereas this looks cool and simple.   |
» Bookcrossing A friend pointed me at Bookcrossing.

Seems like a great way to redistribute your old books and having some fun doing it.

The basic idea - label your old books with a unique identifier, then drop them off wherever you like. Log the 'drop' on the Bookcrossing website for someone to pick up. If they log the collection you can track who and where the book goes. Obviously there are the usual anonymity options and if a non-Bookcrossing person picks up the book they may choose not to join-up (its free, they make money selling accessories like custom labels and bookplates).

Pretty cool.   |
» Mailorder Beer A plug and a bit of a bookmark for myself - Beerstore in NZ does a great job of distributing beer of all kinds delivered to your door.

I've used them a few times now and they're quick and efficient - I even had one delivery with broken bottles which the couriers obviously screwed up and within a couple of days Beerstore had another order on my doorstep no questions asked. Now thats service !   |
» What is a karonkka? A friend of mine recently returned from Finland where he was examining a PhD defence - the process is called a Karonkka.

As well as getting decked out in a full-on tux & tails they actually had ceremonial swords to boot. How cool is that ?

Be sure to read Shauns other posts on the nature of research, patents, science and technology in New Zealand.   |
» TED Talks A friend of mine (cheers Eddie!) pointed me at the excellent TED Talk series.

Subscribe to their RSS feed now.

Theres always something you can set aside 15 minutes of your time to learn about or dump to your mp3 player to listen/watch while you commute.

Recent favourites of mine have included - 'Build a brain in a supercomputer', 'Our buggy moral code', 'What brain damage can point out about our mind', 'Why are babies cute? Why is cake sweet?'   |
» Useful Ways to be Persuasive I realised my Linkdump category hadn't been updated in a looong time so I'll kick start it with this link to some common-sense ways to be persuasive.

As per the link comments in the preamble, its a bit pop-psych but theres some useful stuff to help get your head around how you can get your point of view across to other people.   |
» Because you need to know - Tracking the $700 Billion Bailout It'll be interesting to see if the New York Times keeps this table up to date - Tracking the $700 Billion Bailout.

See which financial institutions receive money and how much they get.   |
» Good Music - Le Pop by Katzenjammer Discovered while reading Popmatters list of Also-rans for 2008 - Katzenjammers 'Le Pop' is one of those joyful albums by a band determined to put a stupid grin on your face at all costs or die trying (cf early Violent Femmes, Crowded House, Pogues).

Check out a couple of videos on YouTube - 'A bar in Amsterdam' and 'Aint no thang'   |
» Good Books - The Shock Doctrine Another excellent read from Naomi Klein - The Shock Doctrine. I have to admit I'm only halfway through this book - mans inhumanity to man makes for tough going - however its pretty much compulsory reading for anyone that wonders how the worlds free market economy's were lead down the track they're currently on.

Essentially what Klein does is posit the idea that free market economies and reforms can only be forced through on the back of an external crisis (sometimes real and sometimes engineered). As a result those people best placed to take advantage of the reforms do extraordinarily well and the vast majority of us end up worse off - with globalisation these disparities keep getting worse as multi-nationals cease to be bound by georgraphy.

As the recent recession and American bank / finance / auto bail-outs have shown - the free market has failed to a certain extent - their own calls for deregulation have bit them on the ass and now they're going cap in hand to the very regulatory bodies they once reviled for assistance.

So even when things go wrong for the wheelers and dealers of the world - they still come out on top.   |
» Good Books - Killing Rommel by Stephen Pressfield Another quick summer read - Killing Rommel is a return to form for Stephen Pressfield - his 'Gates of Fire' was a masterpiece but after that I found 'Tides of War' and 'Last of the Amazons' to be a little dry.

His latest novel tells the tale of the Long Range Desert Group (LRDG) and their various exploits in the North African campaign, culminating in a mission to track down and kill Rommel.   |

« Interesting stuff for… | Home | Useful Bash shortcuts… »

VI Keybindings

Tuesday 02 March 2004 at 10:50 pm. From Tom Fine

Complete key binding reference


















































































































































KeyActionFollowed by
aenter insertion mode after current charactertext, ESC
bback word
cchange commandcursor motion command
ddelete commandcursor motion command
eend of word
ffind character after cursor in current linecharacter to find
gUNBOUND
hmove left one character
ienter insertion mode before current charactertext, ESC
jmove down one line
kmove up one line
lmove right one character
mmark current line and positionmark character tag (a-z)
nrepeat last search
oopen line below and enter insertion modetext, ESC
pput buffer after cursor
qUNBOUND
rreplace single character at cursorreplacement character expected
ssubstitute single character with new texttext, ESC
tsame as "f" but cursor moves to just before found charactercharacter to find
uundo
vUNBOUND
wmove foreward one word
xdelete single character
yyank commandcursor motion command
zposition current lineCR = top; "." = center; "-"=bottom
Aenter insertion mode after end of linetext, ESC
Bmove back one Word
Cchange to end of linetext, ESC
Ddelete to end of line
Emove to end of Word
Fbackwards version of "f"character to find
Ggoto line number prefixed, or goto end if none
Hhome cursor - goto first line on screen
Ienter insertion mode before first non-whitespace charactertext, ESC
Jjoin current line with next line
KUNBOUND
Lgoto last line on screen
Mgoto middle line on screen
Nrepeat last search, but in opposite direction of original search
Oopen line above and enter insertion modetext, ESC
Pput buffer before cursor
Qleave visual mode (go into "ex" mode)
Rreplace mode - replaces through end of current line, then insertstext, ESC
Ssubstitute entire line - deletes line, enters insertion modetext, ESC
Tbackwards version of "t"character to find
Urestores line to state when cursor was moved into it
VUNBOUND
Wforeward Word
Xdelete backwards single character
Yyank entire line
Zfirst half of quick save-and-exit"Z"
0move to column zero
1-9numeric precursor to other commands[additional numbers (0-9)] command
 (SPACE) move right one character
!shell command filtercursor motion command, shell command
@vi evalbuffer name (a-z)
#UNBOUND
$move to end of line
%match nearest [],(),{} on line, to its match (same line or others)
^move to first non-whitespace character of line
&repeat last ex substitution (":s ...") not including modifiers
*UNBOUND
(move to previous sentence
)move to next sentence
\UNBOUND
|move to column zero
-move to first non-whitespace of previous line
_similar to "^" but uses numeric prefix oddly
=UNBOUND
+move to first non-whitespace of next line
[move to previous "{...}" section"["
]move to next "{...}" section"]"
{move to previous blank-line separated section"{"
}move to next blank-line separated section"}"
;repeat last "f", "F", "t", or "T" command
'move to marked line, first non-whitespacecharacter tag (a-z)
`move to marked line, memorized columncharacter tag (a-z)
:ex-submodeex command
"access numbered buffer; load or access lettered buffer1-9,a-z
~reverse case of current character and move cursor forward
,reverse direction of last "f", "F", "t", or "T" command
.repeat last text-changing command
/search forwardsearch string, ESC or CR
<unindent commandcursor motion command
>indent commandcursor motion command
?search backwardsearch string, ESC or CR
^AUNBOUND
^Bback (up) one screen
^CUNBOUND
^Ddown half screen
^Escroll text up (cursor doesn't move unless it has to)
^Fforeward (down) one screen
^Gshow status
^Hbackspace
^I(TAB) UNBOUND
^Jline down
^KUNBOUND
^Lrefresh screen
^M(CR) move to first non-whitespace of next line
^Nmove down one line
^OUNBOUND
^Pmove up one line
^QXON
^Rdoes nothing (variants: redraw; multiple-redo)
^SXOFF
^Tgo to the file/code you were editing before the last tag jump
^Uup half screen
^VUNBOUND
^WUNBOUND
^XUNBOUND
^Yscroll text down (cursor doesn't move unless it has to)
^Zsuspend program
^[(ESC) cancel started command; otherwise UNBOUND
^\leave visual mode (go into "ex" mode)
^]use word at cursor to lookup function in tags file, edit that file/code
^^switch file buffers
^_UNBOUND
^?(DELETE) UNBOUND

Definitions



  • UNBOUND - this key is not normally bound to any vi command

  • word - a lower-case word ("w", "b", "e" commands)
    is defined by a consecutive string of
    letters, numbers, or underscore, or a consecutive string of characters
    that is not any of {letters, numbers, underscore, whitespace}
  • Word - an upper-case word ("W", "B", "E" commands) is a consecutive
    sequence of non-whitespace.

  • sentence
  • paragraph
  • cursor motion command - any command which positions the cursor is
    ok here,
    including the use of numeric prefixes. In addition, a repeat of the edit
    command usually means to apply to the entire current line. For example,
    "<<" means shift current line left; "cc" means
    replace entire current line; and "dd" means delete entire current line.



Key Bindings in Editing Modes


While in any edit mode (insert, replace, etc.) there are some keys that
are used to adjust behaviour, rather than just to insert text.

  • ESC - leave edit mode, return to command mode
  • ^D - move line backwards one shiftwidth. shiftwidth must be set, and
    either the line must be newly added, or ^T must have been used.

  • ^T - move all after cursor forwards one shiftwidth
  • ^H - deletes text that was entered during the current edit mode.
    Most versions of vi do not allow deleting to previous line.
  • ^V - insert next character even if it is a editing character.


Repitition Counts


Most commands can be prefixed with a multidigit number, that influences the
way the command works.












zposition nth line number
Ggoto nth line number
|goto nth column number
rreplace next n characters
ssubstitute for next n characters
<<shift n lines left one shiftwidth
^ignored?
_advance n-1 lines

Need to differentiate between such things as 5yj vs. y5j?

Multibuffer



Standard vi does have an ability to toggle between two different files.
These will be the last two edited files (edit new files with :efilename)
To switch files, use control-^.

These filenames can be reffered to in ex commands, and subshell filters,
using two special characters: "%" refers to the current file, and "#"
refers to the previous file. Here's some handy things you can do with
this feature:


:map v :!chmod 644 %^[ make world-readable
:map q :!ci -l %^[ RCS checkin
:map V :!diff # %^[ compare previous and current files

Tags


Tags are cool, but I don't use them. Go figure. Maybe I'll write something
up here someday.

Mappings and Abbreviations


:map lets you bind a list of keystrokes to a shortcut in command-mode.
This shortcut can be a multiple-key sequence (with limitations),
and the commands within can enter and exit edit-mode.
Some examples of :map can be found above, in the multibuffer section.
Below is a list of all the normally unbound keys in vi command-mode.


g q v K V # * \ = ^A ^C ^I ^K ^O ^V ^W ^X ^[ ^_

When you try to map multiple key sequences, you won't be able to start
them with lower or upper case letters ("Too dangerous to map that"),
but the punctuation and control characters are fair game.
In addition, : can't be mapped, and sometimes a few other keys. Multiple
key sequences can also be very useful with terminal-generated sequences,
which is why the escape key is bindable. I have my xterm set to generate
=f1 for function key one, and so on, so all the function keys are easier to
use with bindings.

If you use multiple key shortcuts, you'll want to know about the timeout
variable. With :se timeout, you have a limited time to generate
the key sequence. This is useful if the key sequences are terminal generated.
With :se notimeout, it just keeps waiting until the next character
does or doesn't match any possible current sequences.

:map! lets you bind a list of keystrokes to a shortcut in edit-mode.
This is useful for adding editing commands to edit mode. One popular
trick is to bind the arrow keys to move up and down while (apparently)
staying in edit-mode, as in the last four lines below.


:map! ^? ^H Make delete act like backspace
:map! ^[OA ^[ka xterm arrow sequences will
:map! ^[OB ^[ja exit edit-mode, move the
:map! ^[OC ^[la cursor, and re-enter edit-mode.
:map! ^[OD ^[ha


If you use the above
trick for arrow-keys in edit-mode, you'll want to set timeout, because
otherwise you won't get beeps at all when you hit escape, only when you
use the next keystroke. With timeout, you get the beep, but after the
timeout. Since both of these are annoying, it may be a useful choice to
avoid multikey sequences that involve escape, as a matter of taste.
Also, many systems now set up command-mode arrow keys in vi by default,
which also leads to the same problem.

:ab lets you bind a key sequence to an abbreviation,
for use in edit-mode.
Abbreviations don't fire until vi decides that you've typed the shortcut
as a whole word. So if taf is a shortcut for Thomas A. Fine, and I type
taffy, it won't substitute because I didn't enter taf as a word by itself.
(If I'd used :map!, then taffy would do the
replacement before I got to the second "f".)

Abbreviations are echoed normally until complete, therefore the abbreviation
can't contain escape (you'd leave edit-mode before completing the
abbreviation),
but the replacement expression can contain escape, and can leave and return
to edit-mode.


:ab teh the
:ab #d #define
:ab #i #include
:ab cmain main(argc,argv)^Mint argc;^Mchar **argv;^M{^M}^[O
:ab mmap(NULL,st.st_size,PROT_READ,MAP_SHARED,fd,0); mmap(NULL,st.st_size,PROT_READ,MAP_SHARED,fd,0);
:ab readsig ^[G:r ~/misc/sig^M
}

To keep a live abbreviation from going off in your hands, use ^V. For
instance, if I want to type teh but have the the abbreviation above, I
can let it "fix" it, then back up and unfix it; or I can type "teh^V..."
and it won't expand the abbreviatoin.

vi macros document

Repeating with .


Commands can be repeated with the redo command, normally bound to ".",
but I've found this to be occasionally unpredictable. If you use multiple
key sequences in a macro, and vi is waiting to see if one of those sequences
might complete, and you start a new command here, it won't be noticed by
the redo. (Solaris, HPUX at least).

System Differences



  • Older versions of vi didn't automatically set up arrow-keys in
    command-mode; they didn't interfere with the beep. (Maybe multiple
    key bindings were new at the same time???)
  • Some versions of vi have encryption, some don't.
  • Options processing is handled differently from version to version.
    Solaris prefers -c command in place of +command, and
    -L instead of -r.

  • Differnt systems may have other keys besides : that are "Too dangerous
    to map that".
  • The size of macros (:map, etc.) are limited in different ways on different
    systems.
  • On some systems the environment variable EXINIT overrides .exrc files (Solaris, HPUX), other systems it enhances it (SunOS???, FreeBSD).
  • nvi allows backspace to previous line in edit-mode (if previous line was edited) (FreeBSD).
  • variants of vi that have multiple undo have different styles. One style
    (linux) uses u as undo, and control-R as redo. The other style (FreeBSD)
    u acts normally, but . continues on in the same direction as the last u
    (whether it was undo or redo). I prefer the latter because it doesn't
    interfere as much with traditional vi behaviour.

VI Reference Manual from the University of Michigan at Dearborn

Trick


I've seen various replacements for the fmt command that you can use to format
paragraphs almost automatically. Mine's better:

:map v 0ma}b:'a,.j<ctrl-v><enter>070 ? *<Escape>dwi<ctrl-v><return><ctrl-v><escape>

It's better because you don't have to prejoin the paragraph by hitting J
an arbitrary number of times. Just hit v (or whatever you've mapped it to)
starting at the beginning or in the middle of the paragraph, and it joines the
rest of the paragraph together, formats one line, and moves the cursor down
again. Just keep hitting v and it will keep formatting. You have to stop one
before the end or you'll end up with an extra short line. It also does not
leave spaces at the end of the line.



 

About

Yet another blog about stuff.

The image in the header is mine.

Tag Cloud

Visitors

Archives

Categories

Links

[ The Doors ]
[ Arstechnica ]
[ Gizmodo ]
[ Pitchforkmedia ]
[ Popmatters ]
[ Google ]
[ BBC News ]
[ Stuff NZ News ]
[ Free Tibet ]
[ Scoop ]
[ Metafilter ]
[ Long Now ]

[ Shaun ]
[ Stuart ]
[ Chris ]
[ Lex ]
[ Vanessa ]
[ Alec ]
[ Damien ]

Stuff

Powered by PivotX - 2.3.6
XML: RSS Feed
XML: Atom Feed