Wednesday 3 October 2018

linux - How to create custom keyboard shortcuts in vim?


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?



Answer



You could define a pair commands, like this:


command -range Cm ,s/^/#/
command -range Uc ,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.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...