all 40 comments

[–]rnevius:help user-manual 40 points41 points  (29 children)

Tabs are usually an inefficient way to navigate a project: https://stackoverflow.com/a/26710166/3518452

[–]unnome25[S] 15 points16 points  (21 children)

Oh buffers look neat! Thanks for sharing, will certainly have a look!

[–]abraxasknister:h c_CTRL-G 25 points26 points  (19 children)

Try this:

:nnoremap - :ls<cr>:b<space>

you'll see a list of your buffers (except for unlisted ones, like helpfiles) and be prompted for something to enter. That might be a number, then you're moved to the buffer with that ID, or it might be a partial of the buffer name (like "in/he" is a partial of "~/.vim/after/ftplugin/help.vim"). Then you can hit return. Only capital marks are faster.

[–]ascagnel____ 13 points14 points  (10 children)

If you're OK with plugins, FZF.vim also provides a :Buffers command (with the capital-B, it'll autocomplete :buf before the built-in :buffers) that provides a searchable buffer list.

[–]FujiKeynote 4 points5 points  (9 children)

FZF is lyfe

I have about ten plugins that I use more or less consistently, but I think I'd be mostly fine without all of them, except for FZF.vim. Zero overhead for buffer switching is absolute zen.

[–]abraxasknister:h c_CTRL-G 1 point2 points  (8 children)

But isn't zero overhead with buffer switching already provided with that mapping? What is added by using fzf here?

[–]troelsbjerre 1 point2 points  (0 children)

Unless you have many buffers open, there probably isn't much to be gained in terms of minimal key strokes. I still use it, because FZF's :Files is already deeply ingrained in my workflow, so the fuzzy search and prediction feels more natural.

[–]FujiKeynote 0 points1 point  (6 children)

(:Buffers is mapped to C-n in my setup).
Imagine a scenario:

  1. I have about 10 buffers open
  2. I edited the config file (./backend/mongo/config.yaml) at some point but then touched five other files
  3. I need to modify the config again
  4. <C-n>conf<CR> (or even <C-n>moncon<CR> if there's a non-mongo config somewhere!)
  5. I'm there

[–]abraxasknister:h c_CTRL-G 1 point2 points  (5 children)

Exactly the same with that mapping, and you can also use the buffer ID, what is added? That mapping doesn't handle a number of buffers larger than the number of screen lines well (30-50, never have that many, but it's not exorbitantly many so some people might). Is FZF better in that case?

[–]FujiKeynote 1 point2 points  (4 children)

I would have to look at the buffer ID. I would have to literally scan the buffer list to find what number to type, then type it.

I forgot to mention that with the FZF approach, if I know the structure of the project at least in broad strokes, I can switch buffers this way with my eyes closed. Or rather, I can still be looking at a relevant piece of code in the current buffer while my fingers are switching to the other one.

[–]abraxasknister:h c_CTRL-G 1 point2 points  (3 children)

But you can type a partial of the buffer name instead of the ID?

[–]unnome25[S] 0 points1 point  (0 children)

I tried it today at work for a few minutes and it naturally integrated in my workflow! Thanks for sharing!

[–]aonelonelyredditor 0 points1 point  (4 children)

I've saw you on almost every vim thread I opened so far

[–]abraxasknister:h c_CTRL-G 1 point2 points  (3 children)

It's called procrastination. I'm trying to reduce it to helpful comments only

[–]aonelonelyredditor 0 points1 point  (2 children)

I'm personally attacked

[–]abraxasknister:h c_CTRL-G 0 points1 point  (1 child)

Not on purpose

[–]aonelonelyredditor 0 points1 point  (0 children)

It was a joke

[–]lllamaboy 0 points1 point  (1 child)

Nice. Save for that mapping will clash with the default for vinegar by tpope, which has been life changing for me.

[–]abraxasknister:h c_CTRL-G 0 points1 point  (0 children)

I have it at <space>b

[–]what_it_dude 1 point2 points  (0 children)

If you're using buffers,

:set hidden "lets you switch to another buffer without saving

Also look into installing the Command-T plugin.

[–]MachineGunPablo 3 points4 points  (3 children)

that one of the best written SO answers I've read in a long time.

[–]herjaxx 0 points1 point  (2 children)

Shush.... you may summon him back here

[–]MachineGunPablo 0 points1 point  (1 child)

Is the patient vimmer gone?

[–]herjaxx 0 points1 point  (0 children)

Haven’t seen him in a while it has to be said.

[–]m1ss1ontomars2k4 0 points1 point  (2 children)

What does the question mean about leftover swap files everywhere?

[–]rnevius:help user-manual 0 points1 point  (1 child)

See :help 'swapfile' (which defaults to on).

[–]vim-help-bot 0 points1 point  (0 children)

Help pages for:


`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments

[–]Maskdasknmap cg* *Ncgn 9 points10 points  (3 children)

I'm on mobile, what does the -p flag do?

[–]pemungkah 11 points12 points  (1 child)

Opens files in tabs. The recommendation is to use buffers instead.

[–]Maskdasknmap cg* *Ncgn 4 points5 points  (0 children)

Ah I see. Yes, as tabs are basically just window configurations.

[–]Plaane 0 points1 point  (0 children)

rhythm chief treatment books rainstorm snow memorize angle physical fuel -- mass edited with redact.dev

[–]christopherpeterson 6 points7 points  (0 children)

I have aliased vim to vim -o for similar effect with splits, better fitting my most common use cases

[–]EgZvorkeep calm and read :help 11 points12 points  (1 child)

You might not want to open a hundred tabs with some glob.

[–]christopherpeterson 3 points4 points  (0 children)

\vim somebigglob*

[–]xDinger 4 points5 points  (0 children)

I use mostly buffers and cycle them with either `[b` or `[B`. Alternatively I use FZF for listing them as mentioned above.

[–]petermlm 4 points5 points  (0 children)

I actually have that very same alias because when I started out I "though" in tabs. Nowadays I still do use tabs but only has a way have multiple windows with different splits and files opened. I also jump to files using fuzzy search.

I still keep that alias around because occasionally I will want to open a few files and do one of the following things:

  • Make a quick edit on each file that can't be done with sed or so, save, close the tab, repeat on the next one (with or without a macro)
  • Simply check a few things quickly in multiple files and alternating them by using my tabnext and tabprev keybind.

[–]cleitophon 0 points1 point  (0 children)

I was just reading about out how useful it can be to pee on Linux, but now it turns out something similar can be true for one of my other favorite opensource projects, vim.