Jay Taylor's notes
back to listing indexdictionary - How to map (alias?) a command in vim - Stack Overflow
[web search]-
-
Home -
Questions -
-
Tags -
Saves -
Users -
Companies -
Labs
-
Jobs
-
Discussions -
Communities for your favorite technologies. Explore all Collectives
-
-
Teams
Now available on Stack Overflow for Teams! AI features where you work: search, IDE, and chat.
Learn more Explore Teams -
Looking for
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?
-
-
Seems very similar to this question: stackoverflow.com/questions/7513380/… Commented Apr 15, 2013 at 18:40
-
Pretty much, yes. Like the poster there, I had no idea how to correctly define what I was trying to do, hence the difficulty searching for it. Commented Apr 15, 2013 at 22:48
3 Answers
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
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
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>