People new to vim will immediately jump on splits or tabs because of how their previous editor work flow worked, but you aren't going to unlock the full power of vim until you get used to buffers.
:b# last buffer used
:b num Switch to various buffers by number
:buffers See a list of buffers
:bd delete buffer
^^ map those to keys
cntrlp for easy buffer switching and opening: https://github.com/kien/ctrlp.vim
My work session has about a hundred or two "open" files in the buffer, and I split and un-split windows often so that I can view multiple files at once.
But my most common way to change current file is :b <first few letters + tab complete>
I occasionally prune my buffers for files that have been deleted, but it's mostly unnecessary to. When I close it, I just save the session in a file and re-open the session.
map <M-right> <C-w>l
map <M-left> <C-w>h
map <M-down> <C-w>j
map <M-up> <C-w>k
map <M-,> :split<CR><C-w>j " Horizontal split
map <M-.> :vsplit<CR><C-w>l " Vertical split
map <M-/> :close<CR>
map <M-<> <C-w>K " Convert vertical to horizontal split
map <M->> <C-w>L " Convert horizontal to vertical splitHTH
Although I use M-- and M-| for vertical and horizontal splits.
* Configuring emacs still requires learning a lot about emacs (which takes a lot of time).
* These vi/vim emulation modes doen't touch SLIME's keybindings, afaik. So, to make them less finger-twisting will require manual rebinding (which takes yet more time).
* Most emacs tutorials assume you're using the standard key bindings. So you still have to learn them.
All of the above make the various vi/vim emulation modes fine for people who already know emacs, or who are willing to sink a ton of time in learning it and reconfiguring it. But they are far less attractive to vim users who already have a nice environment set up in vim and feel comfortable in it.
I guess they're still better than nothing. If I had to use emacs, I'd certainly use something like evil mode. But evil mode alone is not enough to make a vim veteran feel comfortable in emacs.
The relevant parts are:
" shortcuts
map <Tab> <C-W><C-W>
" Tabs
map <C-t> <Esc>:tabnew<CR>
map <C-l> :tabnext<CR>
map <C-h> :tabprevious<CR> nnoremap <c-j> <c-w>j<c-w>_
nnoremap <c-k> <c-w>k<c-w>_
Which does both split navigation and split maximizing. I could probably switch to tabs but I'm happy with how things work and I don't really see any advantage over how I'm doing things now.https://github.com/skeept/dotvim/blob/master/plugin/ZoomWinP...
Basically, if you have multiple split windows, it allows you to do a cmd+O to zoom the current split view (i.e. making it the only view visible). That's neat if there's something tricky going on (say a weird bug) and you want to focus just on this piece of code, without seeing anything else. Once you're done, you can hit cmd+O again, and your old split setup comes back. I love this plugin.
nmap <F4> :tabedit %<CR>
nmap <F5> :tabclose<CR>Edit re below: OK, good point. But I would still prefer the plugin (and plan to install it) because I just don't use tabs, preferring to stick with splits.
:vsplit .
I use this all the time when I need to find a file or I'm not sure where something is. It just opens the file browser in a new window split. It's extremely handy. Once you've got it open, it's important to note that you can use your regular commands in the file browser as you would in Vim. /beginning of file name
This allows for a really nice and fast file browsing experience like when you're searching through code. I prefer it much over cd'ing around on the command line. I can see the directory or file I need to go to, type /, the first few letters, and hit enter. vim .
From the command line, you can simply open Vim as a file browser and use it to browse around your project. I do this to get projects in my head sometimes when I know I'm going to be dealing with multiple parts of the system at once. I can browse around a bit and get things open in tabs or splits and go to town. set autochdir
This is a handy configurable I wish I would've picked up a long time ago that, in my opinion, perfectly accents heavily using filesystem browsing in Vim. If you're someone that splits or tabs around a lot in Vim, this is a really handy change. Instead of your directory always staying relative to the first file you opened, the directory changes depending on what file you're working with.This means you can do something like:
:vsplit ../../models/foo.php
And when you're working in foo.php, you realize you need to make a change to the bar model, bar.php, you can simply do: :vsplit bar.php
Instead of having to do: :vsplit ../../models/bar.php
Going beyond filesystem awesomeness with Vim and window management, you can also use it to easily create new files as you're going along. This is particularly useful for new projects where you're flowing along generating new models. Working on a model and suddenly realize you need to create another one? :vsplit newfilename.php
This will create the new file in your buffer and you can start typing. If you realize you made a mistake, simply close the pane without writing at the file will have never been written. This can also be handy when you need to type something out or keep quick notes. Have a little pane off to the side with notes about what you're working on. Maybe it's some numbers you need to keep in your head or maybe someone interrupted you with a request while you were knee-deep in terminal land. :vsplit notes
Let Vim be your flow and your editor.Also, depending on how you like to work, keeping a stable working directory can be very useful:
:vs **/bar<Tab>
is somehow less mentally taxing than: :vs ../../models/bar.php :vsplit .
On this point, it's worth noting that users of the NERDTree plugin[1] can set it to work with the above style of use as well: " Replace netrw with secondary NERDTree
let NERDTreeHijackNetrw=1
[1] https://github.com/scrooloose/nerdtree/ :vs.
I use this all the time. nnoremap - :Sexplore<CR>
Which opens netrw when you hit the - key. I now have it mapped to ctrlp instead (ctrl+enter in ctrlp to split open).`set autochdir` is very nice. Thanks for sharing!
cabbr <expr> %% expand('%:p:h')
You could also use :. instead of :p to get the relative path, see :help c_% and :help filename_modifiers map <leader>e :e <C-r>=expand("%:p:h") . "/" <cr>
you can make one that splits: map <leader>v :vs <C-r>=expand("%:p:h") . "/" <cr>" uses expression to extract path from current file's path
map <leader>e :e <C-R>=expand("%:p:h") . '/'<CR><C-M>
map <leader>s :split <C-R>=expand("%:p:h") . '/'<CR><C-M>
map <leader>v :vnew <C-R>=expand("%:p:h") . '/'<CR><C-M>
"quick window movements
map <a-w> <c-w>
map <a-l> <c-w>l
map <a-k> <c-w>k
map <a-j> <c-w>j
map <a-h> <c-w>h
imap <a-l> <esc><c-w>li
imap <a-k> <esc><c-w>ki
imap <a-j> <esc><c-w>ji
imap <a-h> <esc><c-w>hiI'd also suggest using <C-o> instead of the <Esc>...i dance.
Edit: "The way [Vim] stores alt+letter in its input queue collides with UTF-8/Unicode handling" -- LeoNerd in freenode/#vim at 2013-04-15 15:22:29
set encoding=utf-8
" TODO check if printing of utf-8 chars works with 'set fileencoding=utf-8'
set fileencoding=utf-8
" {{{ Diacritic characters: <Leader>char (keyboard switching doesn't work in cygwin)
" Use the same keys as on a keyboard
inoremap <Leader>; ö
inoremap <Leader>: ö
inoremap <Leader>' ä
inoremap <Leader>" Ä
inoremap <Leader>[ ü
inoremap <Leader>{ Ü
inoremap <Leader>- ß
" Comment/Uncoment following as you need:
"inoremap <Leader>`A Á
"inoremap <Leader>`Ae Ä
"inoremap <Leader>`C Č
"inoremap <Leader>`D Ď
"inoremap <Leader>`E É
"inoremap <Leader>`I Í
"inoremap <Leader>`Ll Ĺ
"inoremap <Leader>`L Ľ
"inoremap <Leader>`N Ň
"inoremap <Leader>`O Ó
"inoremap <Leader>`Ou Ô
"inoremap <Leader>`R Ŕ
"inoremap <Leader>`S Š
"inoremap <Leader>`T Ť
"inoremap <Leader>`U Ú
"inoremap <Leader>`Y Ý
"inoremap <Leader>`Z Ž
"inoremap <Leader>`a á
""inoremap <Leader>` ä " defined already
"inoremap <Leader>`c č
"inoremap <Leader>`z ž
"inoremap <Leader>`e é
"inoremap <Leader>`i í
"inoremap <Leader>`l ľ
"inoremap <Leader>`n ň
"inoremap <Leader>`o ó
"inoremap <Leader>`ou ô
"inoremap <Leader>`r ŕ
"inoremap <Leader>`s š
"inoremap <Leader>`t ť
"inoremap <Leader>`u ú
"inoremap <Leader>`y ý
"inoremap <Leader>`z ž
" }}}It might not work the way you prefer using your favorite input method, but vim allows you to enter any utf-8 character, and even has mnemonic digraphs for many you are most likely to want. To get è, for example, in input mode just type <ctl>-k`e.
Obviously not very helpful to people not on a Mac, but I don't have to go through Alt mappings at all.
Sometimes you don't want it, so you can toggle it off.
" Split window vertically
nnoremap <Bar> <C-W>v<C-W><Right>
" Split window horizontally
nnoremap _ <C-W>s<C-W><Down>
" Use tab to toggle between windows
nnoremap <Tab> <C-W>wC-w C-w
This moves to the last used split, i.e. it's a quick way to jump between two.
So I have tabs and those are then split. Each subject of work or exploration has a tab with a few splits. I end up with much less clutter than sublime text. Easy to close out a tab.
Also ctrl-w v is my favorite way to split.
au VimResized * wincmd =