by dmix · 13y ago · 0 comments
For ex: working on an HMTL+CSS+JS documents all at once. Assuming smaller screen where I can't have a vsplit screen.
How to I jump between them quickly? Buffers/tabs?
I love VIM but I haven't found a good tab/file switching solution. In Textmate tabbing was straight-forward. VIM doesn't seem well suited for tabs (especially with things like NERDTree and control-p).
nnoremap <Leader>b :buffers<CR>:buffer<Space>
nnoremap <Leader>n :bn<CR>
nnoremap <Leader>p :bp<CR>
My <Leader> is space. So "space+b" opens up my buffers, I type a few letters that match a file and Tab to autocomplete it, then press enter to open it. I also use ctrl+shift+6 to quickly switch between the 2 most recent buffers.So I'd give that a shot. If that doesn't work for you, try just ":tabe <file>" for your three files, then ctrl+pageup, ctrl+pagedown (or gt, gT) to quickly switch between them.
I just switched b/p (since I use p w/ ctrl-p as a fuzzy finder to list all files).
https://github.com/kien/ctrlp.vim
For switching quickly between the 10 most recently used buffers:
https://github.com/vim-scripts/LustyJuggler
I suggest adding this to your .vimrc (the default mapping is <Leader>lj; my leader key is the spacebar, and I find space space to be much better):
let g:LustyJugglerDefaultMappings = 0
nnoremap <silent> <Leader><Leader> :LustyJuggler<CR>
For very quickly jumping between the current buffer, and the last buffer I have a mapping:
nnoremap <leader>dd <C-^>
because <C-^> is a bit awkward; <leader>dd could be anything that's very easy to type.
So most of the time I'm alternating between two files using the <C-^> mapping. When I need to jump to a less recently used buffer I double tap <space>, opening LustyJuggler, then double tap the appropriate home row key to jump to the buffer I want. If the buffer I want isn't in the ten most recently used, I open Ctrl-P, type enough characters from the file path of the file I want to make it the first choice, then hit enter.
You can make use of command-line completion:
:b <Tab>
which does partial words too: :b js<Tab> completes with teh name of your JS file
You can make command-line completion even faster: set wildcharm=<C-z>
nnoremap <leader>b :b <C-z>
You can try quick, generic, mappings: nnoremap <PageUp> :bnext<CR>
nnoremap <PageDown> :bprevious<CR>
You can try more precise ones: nnoremap <leader>1 :b1<CR>
nnoremap <leader>2 :b2<CR>
nnoremap <leader>3 :b3<CR>
...
to mimic TextMate.You can try listing and choosing in one move:
nnoremap gb :buffers<CR>:b<Space>
You can try the builtin Ctrl+^: 3<C-^> is equivalent to :b3<CR>
You can remap it if you want: nnoremap & <C-^>
and do: 1&map <C-n> :bn<Cr>
map <C-p> :bp<Cr>
It probably helps that I've mapped caps-lock to ctrl so using ctrl is very convenient for me.
I have a friend who has a sweet setup with gvim that has a lot of tab and file management tools, so you might look into gvim, but I don't use it.