0

I have a problem with adding a keymap to delete all my buffers.

Namely, I used the following map in my init.vim file (source):

nnoremap <leader>B :%bd|e#|bd#<CR> 

And I get the following error, saying there is no substitute for the "#" character:

E194: No alternate file name to substitute for '#': e#

The above command works fine when run outside of a mapping.

Is there anyway to actually implement what I want to achieve?

2
  • What do you mean by "outside VIMRC [sic]"? Do you mean "when I type :%bd|e#|bd# + Enter" or "when I type <leader>B in a buffer that isn't my vimrc" or something else?
    – D. Ben Knoble
    Commented Jan 15 at 21:09
  • @D.BenKnoble The first one. Typing ":%bd|e#|bd# + Enter". Including # character in VIMRC config leads to this errors.
    – satk0
    Commented Jan 15 at 22:02

1 Answer 1

0

Escaping | characters does the trick:

nnoremap <leader>B :%bd\|e#\|bd#<CR> 
2
  • 1
    You can also write <bar> (:help key-notation). The reason this works is at :help map-bar. The first version is equivalent to typing :nnoremap <leader>B :%bd<enter>:e#|bd#<enter>, which won't make sense when executing your vimrc at startup.
    – D. Ben Knoble
    Commented Jan 16 at 14:05
  • @D.BenKnoble Oh, I was wondering why it works, now I finally know. Big thanks !
    – satk0
    Commented Jan 17 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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