DEV Community

Discussion on: 1 Month Vim Only Challenge - Weeks 2 and 3

Collapse
 
vonheikemen profile image
Heiker

Working with multiple files "the vim way" is kind of tricky. I took me a long time finding how people did it... and then some more to get used to it.

Apparently the secret is the set hidden option and the buffer list. The :ls command will show you the list of open files. And you can navigate to any of those files with the :buffer command.

The cool thing about the :buffer command is that it can autocomplete using the paths of the opened files. So if you write something like :buffer main.js and then press Tab, vim will show you the completion list with the files that contain main.js. Accept the completion, press Enter and you're there.

The other piece of the puzzle will be the "alternate file", which is basically the most recently used file. If you use :buffer # you'll get there. Vim has a built-in shortcut for this: <C-^>, that is Ctrl + ^, which in QWERTY layouts is Ctrl + 6.

Additionally you could "chain" ls and buffer inside a keymap.

nnoremap <Leader>bb :ls<CR>:buffer<Space>
Enter fullscreen mode Exit fullscreen mode

If this is still not enough for your workflow you can check out fzf and the companion plugin fzf.vim. (I'm almost certain you knew about this one).

Collapse
 
mpodlasin profile image
mpodlasin

Thanks for the tips!