Monday, August 24, 2009

vim: commenting-out lines of code esaily

For short ranges of basic prefixing comments (# or //), I've become fond of vim's visual block mode and block insert. To do this:
  1. start visual block mode (with Ctrl-V)
  2. adjust the selection with movement keys as needed. (marks can be used here)
  3. once the selections are made, start block insert with 'I' (or append with 'A')
    NOTE: don't use the usual lowercase 'i' or 'a'
  4. type the comment text (e.g. "#")
  5. when you hit escape, comments will be added to all selected lines

source

No comments: