Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

How can I map a command in vim which does something like:

:command (I write here and press enter) (Executes another command with the things that I wrote)


:badd my_buffer_name
:b my_buffer_name

I want to map this with "\ff" and it should work like this: \ff my_buffer_name. How can I map such commands?

share|improve this question
up vote 1 down vote accepted

Assuming that you want your mapping to execute one of those buffer commands, use this:

:map \ff :badd 

Make sure that you include a space character after ":badd". See

:help 05.3
:help map.txt

If you meant that your mapping should execute both of those commands, then use this:

:command -nargs=1 BuffAdd badd <args> <bar> b <args>
:map \ff :BufFAdd 

Again, include a space after ":BufAdd" in the mapping. See

:help 40.2
:help user-commands

For more complicated tasks or argument-handling, you could write a function. See

:help 41.7
:help user-functions

A function that included the use of the input() function could allow you to type \ff followed by the buffer name without seeing :BufAdd on the command line, like this:

function MyFunc()
    let my_buffer_name = input("Buffer name: ")
    exe 'badd' my_buffer_name
    exe 'b' my_buffer_name
map \ff :call MyFunc()<CR>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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