- I'm Josh Branchaud
- I work at Hashrocket
- Twitter: @jbrancha
- Github: @jbranchaud
Using buffers as extensively as we do at Hashrocket is sorta new to me. I used to be more of a vim tab person. These are the buffer-related commands that mostly comprise my day to day workflow at Hashrocket.
Let's just start by editing a file
vim README.md
:ls
:buffers
:files
We'll be using :ls
a bunch
:e <filename>
:e %:h
- from netrw of directory of current file- With a plugin, e.g. rails-vim
vim .
i
to toggle display modes - credit to Brian Dunn
The key to working efficiently in Vim with buffers is being able to move between buffers quickly.
When you can move quickly between buffers you can work more quickly and (hopefully) better avoid getting distracted and losing your train of thought.
:help :b
:b [N]
:b <tab completion>
c-^
(<ctrl><shift>6
)
ctrl-o
- back a buffer (ish)ctrl-i
- forward a buffer (ish)
How does vim know where to go with ctrl-o
and ctrl-i
?
:help jump-motions
:jump
or:jumps
Sometimes I have a certain jump location in mind, but after moving around different files, it gets buried.
:help mark-motions
m[a-z]
- intra-file marksm[A-Z]
- inter-file marks
:help :bd
:bd
- to unload current buffer:bd [N]
:bd <filename>
:n,mbd
:%bd
- unload all the buffers?
:help :bw
:bw
- to wipeout the current buffer- etc.
So what's the difference between :bd
and :bw
?
The :bd
command really just removes the file from your buffer list
and not much else. The :bw
command on the other hand wipes out
everything about that buffer. It's entries in the jump list go away,
it's marks go away, etc.
- What sorts of cool stuff do you like to do with buffers that I didn't mention?
Thank you for this explanation. I am a newbie trying to learn vim. This helped to clear the confusion I had about buffers:
Could you please explain what is the difference when we open a file using :e filename and :tabe or :tabnew filename. I ask this because I find the navigating behavior different in both the case. When I use :e - I cannot use gt or gT to navigate whereas when I use :tabe I can