minibufexpl.vim icon indicating copy to clipboard operation
minibufexpl.vim copied to clipboard

Switching buffers with modifier + number

Open raine opened this issue 14 years ago • 7 comments

Similarly to TextMate's Cmd-n for switching buffers.

raine avatar Oct 12 '11 07:10 raine

You can put something like the following into your ~/.vimrc

" switching to buffer 1 - 9 is mapped to Alt-<buffer_no>
for buffer_no in range(1, 9)
  execute "nmap <A-" . buffer_no . "> :b" . buffer_no . "\<CR>"
endfor

I personally have this in my ~/.vimrc

" switching to buffer 1 - 9 is mapped to ,[nOfBuffer]
for buffer_no in range(1, 9)
  execute "nmap <Leader>" . buffer_no . " :b" . buffer_no . "\<CR>"
endfor

" switching to buffer 10 - 100 is mapped to ,0[nOfBuffer]
for buffer_no in range(10, 100)
  execute "nmap <Leader>0" . buffer_no . " :b" . buffer_no . "\<CR>"
endfor

which works well with combination with Mini Buffer Explorer plugin.

Cheers,

  • m.

mkrauskopf avatar Oct 13 '11 18:10 mkrauskopf

Hello,

I think the problem with that is that it follows vim's buffer numbering instead of the order of buffers that is visible in minibufexpl. Also, I haven't found any way to make vim's buffer numbering manageable, vim seems to be giving my buffers ever increasing numbers regardless of how few buffers I have open.

I'm essentially looking for a solution that shows me the open buffers all the time, analogously to TextMate's buffers. This is to give me context on which files I'm working on — somehow it's very helpful to me. Now, if the buffers in minibufexpl were always numbered from 1-9, there could be an associated mapping for switching to each buffer, Ctrl-<1-9> and so forth.

I should've been more specific in the beginning.

raine avatar Oct 13 '11 19:10 raine

I see. It still works well since minibufexpl put in front of each buffer/file name the number used by Vim's buffer numbering scheme as might be seen on e.g. this screenshot. So usually minibufexpl give me quickly a buffer and its number and then I just press e.g. ,6 and I'm there instead of explicitly navigating. But most of the time I'm using FuzzyFinder. Anyway, getting off topic :) ....

mkrauskopf avatar Oct 13 '11 19:10 mkrauskopf

That's an interesting approach. I would suggest using something like ctrl-p (https://github.com/kien/ctrlp.vim) in "most recently opened" mode to find buffers.

I haven't played with TextMate's functionality that you mention, and I recently have started using CMD + # for switching tabs in Chrome. I'll keep it in mind.

fholgado avatar Feb 27 '12 03:02 fholgado

There is a plugin called buf_it providing this functionality, it shows the buffers' list in information line. Meanwhile, I am tring to integrate this functionality into MBE, so, please hold on for a while.

weynhamz avatar Nov 23 '12 22:11 weynhamz

@mkrauskopf 's answer works and it is great !

huangyg11 avatar Oct 20 '13 06:10 huangyg11

Also, there is old MBE fork called TabBar which does excatly the requested thing. vim-script's version is very old and behaves oddly in many scenarios (trying to open buffer in NERDTree window for example, etc,) so if you want to try it you should search for latest forks on GitHub. They have a lot of issues fixed. I'm trying at the moment the latest one with mappings like <Space>1 for first buffer and <Space><Space>1 for 11th.

iw-kuchin avatar Mar 14 '14 07:03 iw-kuchin