3

How can I disable all user mappings only for current buffer in vim? I've tried :mapclear but it removed mappings for all buffers.

2
  • if there is a global mapping xxx, do you also need to have xxx disabled for the current buffer?
    – doraemon
    Nov 1, 2018 at 9:53
  • @LiuSha Yep, all mappings if possible.
    – theJian
    Nov 1, 2018 at 15:33

2 Answers 2

1

You might be looking for <buffer> argument.

This argument ensures that the command or the mapping will be effective only in the local buffer rather than the global buffer.

To clear all the user-mapping in the local buffer, :mapclear <buffer> should be used.

For more information, look at :h :map-<buffer>

3
  • You might misunderstand my question. The <buffer> argument is for removing local buffer mappings, but what I want to do is remove all mappings temporarily for the current buffer.
    – theJian
    Jan 20, 2018 at 10:35
  • @theJian.. I'm looking up for this as well and ended up here. have you solved this? Oct 31, 2018 at 12:32
  • @JohnFredFadrigalan Unfortunately no, this snippet is the temporary solution I've used. gist.github.com/theJian/beb8519127b9209f644197a09620d939
    – theJian
    Nov 1, 2018 at 8:41
1

Here is the temporary solution I've found so far.

let lowercase = 'abcdefghijklmnopqrstuvwxyz'
let uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
let numbers = '0123456789'
let punctuation = "<>`@#~!\"$%^&/()=+*-_.,;:?\\\'{}[] " " and space
for str in [lowercase, uppercase, numbers, punctuation]
    for key in split(str, '\zs')
        execute printf("noremap <silent> <buffer> <nowait> %s :call DO_SOMETHING_OR_NOTHING<cr>", key)
    endfor
endfor

Basically this snippet will remap all the normal mappings for local buffer.

1
  • how about the <f1>-<f12> mappings
    – doraemon
    Nov 1, 2018 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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