Wednesday, February 10, 2010

vim command to delete lines

My fingertips know the command to delete all the lines starting from current line till EOF (that's d + shift g) but I rarely remember the command to delete all the lines up to head of the file.

Luckily, vim offers a simple approach to delete desired lines, all we need to be aware is the following
  • . (dot) - represents current line
  • $ - represents EOF
  • syntax: start_line_num,end_line_num vim_cmd
Some example usages (Note: these commands are run in the editor, hence the beginning colon)
  • Delete all the lines starting from current line : .,$ del
  • Delete lines starting from 1 to so far : 1,. del
  • Delete all lines between 10 and 25 (inclusive) : 10,25 del
  • Delete all lines between 10 and 25 (inclusive) : 10,+14 del
  • Delete next 15 lines including the current : .,+14 del
  • Delete last 15 lines including the current : .,-14 del

No comments: