Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example - when coding in Perl, I need to sometimes comment out a bunch of lines.

  • What I do is something like

    :80,96 s/^\(.*\)$/#\1/
    
  • I want to create a custom shortcut for this so that I can do something like

    :80,96 cm
    

    for commenting and

    :80,96 uc
    

    for uncommenting.

What should I put in my ~/.vimrc?

share|improve this question
up vote 2 down vote accepted

You could define a pair commands, like this:

command -range Cm <line1>,<line2>s/^/#/
command -range Uc <line1>,<line2>s/^#//

Note that a user-defined command must start with an upper-case letter. See

:help :command
:help user-commands

There is also a Vim plugin that many people use for this, Enhanced Commentify, but I don't have any experience with it myself.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .