0

I like using Vim for presentations, and I use :bnext and :bprev to switch between buffers, where each buffer contains the data for a slide.

One annoyance however is that :bnext on the last buffer (containing the data for the last slide) cycles back to the first buffer (in my case the beginning of the presentation).

Is it possible not to have this behaviour ?

1
  • Alternatively you can use argument list and use :next and :prev as :next will not move beyond the end of the argument list – Peter Rincker Apr 26 at 13:53
4

One very basic solution would be create custom Bnext and Bprev commands like this

command! Bnext if bufnr() != bufnr('$') | bnext | endif
command! Bprev if bufnr() != 1 | bprev | endif

Now if you use :Bnext you check if the number of the current buffer (bufnr()) is different from the one of the last buffer (bufnr('$')) and trigger the built-in :bnext only if it's not the case.

Related help:

5
  • 1
    Hm, this answer looks a lot simpler than the one at the suggested duplicate! – D. Ben Knoble Apr 26 at 19:17
  • 1
    Ah I missed the duplicate question. The other answer is more complex because it handles unlisted buffers, I guess it depends on the use case but for this particular question where OP is giving a presentation unlisted buffers are probably not a big concern. – statox Apr 26 at 19:24
  • As the person who wrote the other answer, I do also like this answer. Is it possible to merge them for ease of future search? – Andrew Ho-Lee Apr 27 at 12:47
  • Probably worth noting that if the first buffer is not buffer number 1 (if you’d closed it before) this would cycle back to the end. Not an issue for the OP’s use case though. – Andrew Ho-Lee Apr 27 at 12:50
  • @AndrewHo-Lee Yes this is a very basic solution fitting only the particular OP problem. About merging the answers SE doesn't really have such a feature AFAIK but this question is already linked to the other and you can add a link to this one in the other one if you want to :) – statox Apr 27 at 12:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.