Tag Archives: shortcuts

I <3 vim !

I’ve been a vim user for a long time. I’ve always liked vim, because the modal interface fits my brain and the keybindings, my wrists (which never really liked emacs).

Now, although I have used vim for a long time, I often tend to use a small subset of the power that this awesome editor offers.

I would like to say that this is because “what I know, is all that I need to know”, but the simple truth is it’s because I am too lazy to read the docs.

That said, I *do* sometimes feel the urge to become more productive, which leads me to invest time into really understanding my basic tools (vim, firefox, thunderbird, pidgin, windowmaker, aterm/xterm/rxvt).

Today, I decided it was going to be vim. Here’s what I learned:

  • Since version 7.0, vim has a builtin spell checker (“:help spell”; I was using the vimspell plugin all this while).
  • The ‘-x’ option [1] ! Look it up !
  • vimgrep (“:help vimgrep”)

Since I was so impressed with what I learned today, I’m listing down some of the things that I do know about. Some of these, you might already know, and if you don’t, I think you should.

Note that I’m not explaining any of these. This is more like a quick-n-dirty, see-and-do, reference. So, I’d suggest open up a decently large text file (something with more lines than your window size) and try out what’s listed. If you like what you see, the vim doc is beautiful, just pull out the help topic mentioned to learn more.

Note also that most of these refer to ‘command’ mode, ie: You need to press ‘Esc’ before trying any of these out.

  • visual mode (“:help visual”) – Not spectacular, if you already know about it. If you don’t, do a ‘v’ and move around the text, yank-n-paste, you’ll get the idea.
  • visual-block (“:help visual-block) – Now, this one, I’ve seen a lot of ‘old’ unix guys didn’t know about (which is a bit strange). Anyways, do a ‘Ctrl-v’ and move a couple of characters left/right and then up/down, yank-n-paste, you’ll get the idea …..neat huh ??
  • folding (“:help fold”). In visual mode, select a few lines, do a ‘zf’. To open, do a ‘space’ or ‘zo’ on the fold.
  • Editing an entire block – Using a visual-block, select a set of lines. Now, without pressing Esc, try some editing commands, like type in ‘I’ followed by #. Now, press Esc.
  • Inserting special characters in your search-and-replace patterns: An example is best for this one. Do this:

    Create a file with the contents:
    <HTML><HEAD><TITLE>42</TITLE></HEAD><BODY>The answer is</BODY></HTML>
    Do a ":1,$ s/></>Ctrl-v+Enter</g"

    See what I mean ?

There is so much more, but now I am bored …and I think at least for those who have not invested time in learning vim by reading the docs, at least some of this stuff would be new.

Maybe, I’ll post about vim again later. Till then though, here’s something that you could possibly use — My vim files. Just untar, rename the contents correctly (ie: mv {dot_,.}virc && mv {dot_,.}vim) and copy them to you $HOME. The .vimrc is written from scratch and mostly well commented.

Thanks for reading.

[1] wtf !! …and I’ve been breaking my head over getting an nice, easy to use and small tool for storing sensitive stuff (like account numbers, login/passwords, etc) and was left unsatisfied with all the fancy GUI tools and the CLI one’s I’d have to install separately on each new system)

UPDATE: The default encryption algorithm used for the -x option is breakable. It is the same as that which Pkzip uses (and has documented). So, -x is probably not a good idea for ultra sensitive stuff, but good enough and convenient enough for short lived files which don’t need high level of security. For proper encryption support in vim, I would recommend using Noah Spurrier’s OpenSSL vim plugin. . (Now included in the vim files link above).

Bash command line editing for lazy, vim users

Here’s a list of shortcuts I use frequently to make my time on the bash command line prompt a bit more efficient. Some disclaimers …

  • Although, I am a vim user who never quite attained the precise finger deftness demanded by emacs and yes, I do know about the vim command line editing mode for bash. However, I have realized that the vim mode is even more painful than most of the emacs-inspired (or rather readline specific) shortcuts listed here.
  • This is not a comprehensive list of shortcuts for bash. These are just the ones I find useful but have difficulty remembering sometimes due disuse (which causes muscle memory loss).
  • Some of these are not required if you are using a capable terminal (for example, if the terminal maps the Home and End keys correctly, those can be used instead of C-a and C-e respectively … however, this is what causes the muscle memory loss mentioned earlier).

Note: C == Ctrl, M == Meta (or Alt)

  • Tab for command and filename completion
  • C-l to clear the screen
  • Up and down arrow keys for browsing command history one at a time

Moving about:

  • C-a or “Home” to move to start of line– C-e or “End” to move to end of line
  • M-b to move a word backward
  • M-f to move a word forward


  • C-k to delete till the end of line
  • M-backspace or C-w to delete a word backwards
  • M-d to delete a word in place

Searching and inserting:

  • C-r begin searching backwards for matching string
  • C-M-y insert argument from last command here
  • M-. cycle through last arguments of previous commands

if …
$ echo foo bar
$ echo xxx yyy
$ echo “M-.” yields yyy, another “M-.” yields bar

Major editing:

  • C-X C-E to edit the current command using $EDITOR

Well, that’s about all I can remember right now ! Thanks for reading.