10

I use plugin "Buffet", and there's local-to-buffer mapping "d" to delete buffer under cursor.

I also use plugun Surround, and there's global mapping "ds" that means "delete surround".

So, when i press "d" in the Buffet's window, Vim waits for a second before execute mapping "d". I know about &timeoutlen, but i don't want to change it. So that I want to resolve ambiguity of key mappings for "d" in the Buffet's window to avoid timeout to delete a buffer.

To resolve the problem, I want to unmap in Buffet window all the mappings that start with "d", but except Buffet's own mappings. How can i do that?

P.S. I have read about maparg() and mapcheck(), but they seem not to be what i need, unfortunately.

6 Answers 6

4

It seems like i found the solution myself:

au BufEnter buflisttempbuffer* nunmap ds
au BufLeave buflisttempbuffer* nmap   ds <Plug>Dsurround

I hoped that there's more universal approach (to remove really all mappings starting from "d"), but at this moment i failed to find it.

Even if i found out how to get all these mappings, unfortunately i can't do unmap <buffer> ds, because ds is a global mapping. I'm sure that i should be able to disable global mapping for some buffer, though. Vim is great but not perfect.

Well, it works for me now.

2

Now that the question has been "rephrased", this solution is no longer relevant, but I'll post it anyway since I spent a few minutes on it.

Here's a function that grabs the output of map <letter> and extracts the individual maps. Then it unmaps them all.

function! Unmap(leader)
    redir => maps
        sil exe "map " . a:leader
    redir END
    let maps_list = split(strtrans(maps),'\^@')
    if len(maps_list) > 1
        for this in maps_list
            let mapn = matchstr(this,"^\\w\\s*\\zsd\\w*\\>")
            exe "unmap " . mapn
        endfor
    endif
endfunction

Example usage: call Unmap("d"). This will remove all mappings that begin with d, leaving only Vim's defaults.

Disclaimer: this has not been rigorously tested. In particular I don't know how portable the \^@ character is, but that's how it looks on my (Win32) machine.

1
  • Thanks, actually i wanted to get something like that, and then i would put it in buffet.vim just before its own mappings definition, but the main trouble is that all global mappings will be removed permanently, not only for local Buffet's buffer. Very pity that Vim does not allow to unmap some global mappings for just local buffer. Feb 2, 2012 at 17:33
0

The easiest way to do it is:

:e /WHERE/YOU/HAD/INSTALLED/buffet.vim
:%s:map <buffer> <silent> d:"&: 
:wq
$ vim # Restart Vim to take effect...

Generally you can't unmap based on a pattern.

If you want to use another key (e.g. with <leader>, just change this line in the plugin:

map <buffer> <silent> d :call <sid>deletebuffer(0)<cr>
4
  • Hmmm, it seems like you misunderstood me. You just suggested to disable "d" mappings for Buffet (actually comment these mappings), but that's totally not what i need. Conversely, i want to use d, but i want to use it without this timeout. Pity that there's no way to unmap by pattern, but maybe there's some tricky way. I tried to found it myself (i wrote about maparg() and mapcheck()), but still no luck. Feb 2, 2012 at 13:05
  • Well from my point of understanding, what you had written: 'I want to unmap in Buffet window all the mappings that start with "d"' means you don't want it anymore. Feb 2, 2012 at 13:18
  • I meant that i want to unmap all the mappings that start with "d", but except Buffet's own mappings =) well, i found the local, non-universal solution (look my answer to my own question) Feb 2, 2012 at 13:33
  • Well if you had had written that, I had given another advice. Feb 2, 2012 at 13:48
0

This question is rather old, but if you're still interested, you might want to give Bufstop a try.

This issue is handled by the plugin, you can press the d key to delete a buffer, and you won't get any timeout if you installed other plugins which have global mappings.

0

A cheap trick that worked for me was to make the timeoutlen so short it becomes pretty much instantaneous. As long as you don't use multiple key mappings yourself, that will cover all plugins in one shot.

We don't want that setting to stay however, so we remove it every time we leave the buffer.

Add this so that it runs inside your custom buffer:

augroup no_map_chords
  autocmd!
  autocmd BufEnter <buffer> let g:bak_timeoutlen = &timeoutlen | set timeoutlen=1
  autocmd BufLeave <buffer> let &timeoutlen = g:bak_timeoutlen | unlet g:bak_timeoutlen
augroup END

A similar technique could be used for a specific file type, or other such "global" settings.

-1

Buffet is a very young plugin, I don't think it's used by as many people as Command-T or NERDTree so you may not receive lots of answers. Its author has been very responsive on the numerous threads he created there about it you should contact him directly or create an issue on Buffet's github.

1
  • 4
    I don't think he should. It's a local configuration issue. Feb 2, 2012 at 12:36

Your Answer

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

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