Is there a way to map a sequence of keystrokes to a command-line commmand (a command entered after : in the Ex mode) in vim?
Is there a way to map a sequence of keystrokes to a command-line commmand
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, and it’s intuitively called :map
Example:
No when in insert mode you press the keys
foovim will respond with “bar”.Type
:help :mapin vim for more information.You can place mappings you want to load by default in your .vimrc file.
You can independently map keystrokes for different modes, such as insert mode (:imap) and visual mode (:vmap). See also vim help on the subject of remapping (:noremap)
Update
If you want to use an alias for command mode (but this can be done for insert mode too), you’ll want to use abbreviations.
To define an abbreviation for command mode, use :ca (which is a shorthand for :cabbrev). See vim help
:help :caand for more info:help :abbreviations.Notice that unlike map, abbreviations are not replaced by vim commands but by literal characters. Abbreviations are triggered when you press space or enter.
Examples: