Jay Taylor's notes

back to listing index

dictionary - How to map (alias?) a command in vim - Stack Overflow

[web search]
Original source (stackoverflow.com)
Tags: vim aliases howto editor vimrc vimscript stackoverflow.com
Clipped on: 2024-08-10

    1. Home
    2. Questions
    3. Staging Ground
    4. Tags
    5. Saves
    6. Users
    7. Companies
    8. Labs
    9. Jobs
    10. Discussions
    11. Communities for your favorite technologies. Explore all Collectives

  1. Teams

    Now available on Stack Overflow for Teams! AI features where you work: search, IDE, and chat.

    Learn more Explore Teams
  2. Looking for

Asked 11 years, 3 months ago
Modified today
Viewed 10k times
10

Lets say, hypothetically, that I always forget the command :vsplit, and always think it’s :vdivide.

Is there a way to map (I’m not sure if that’d be the right thing to call it, since it’s a command) one to the other?

asked Apr 15, 2013 at 17:33
user137369
5,58355 gold badges3232 silver badges5959 bronze badges

3 Answers

Sorted by:
12

User defined command can only start with an uppercase letter, so you can only add :Vdivide but not :vdivide.

Add in your .vimrc

 command Vdivide vsplit
answered Apr 15, 2013 at 18:04
Xavier T.
41.6k1010 gold badges7474 silver badges9999 bronze badges
7

To get around the limitation that user-defined commands must start with an uppercase letter, I recommend the cmdalias.vim - Create aliases for Vim commands plugin. With it, you can do:

:Alias vdivide vsplit
answered Apr 16, 2013 at 15:18
Ingo Karkat
171k1616 gold badges258258 silver badges336336 bronze badges
0

2024 Vim Aliasing Update:

After extensive testing and research, I learned the following is the most resilient way to alias a command in Vim. I wanted to alias :Set to :set, because it's a frequent typo when I'm trying to quickly do :set paste.

Many of the alias techniques on StackOverflow and the internet at large do not take into account handling aliased command arguments, but this solution works perfectly or can be trivially tweaked for every case I've encountered.

Add this to your .vimrc file:

" Aliasing: This is a robust technique
" n.b. For further details about nargs behavior, see: `:h command'
command -nargs=* Set set <args>
answered 3 mins ago
Jay Taylor
13.5k1111 gold badges6262 silver badges8585 bronze badges

Not the answer you're looking for? Browse other questions tagged or ask your own question.