Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM: How to open new file in current buffer?

Tags:

vim

By default, VIM :e command will create a new buffer with specified file, leaving current buffer to hand around. This leads to buffers count growing very large (and that is not handy if some buffer display plugin is used, for example popular minibufexplorer). Is it possible to modify VIM so :e command will re-use current buffer? If i need two buffers, i can always create second one via :enew command, after all.

like image 745
grigoryvp Avatar asked Jul 12 '13 09:07

grigoryvp


People also ask

How do I switch between buffers in Vim?

Pressing Alt-F12 opens a window listing the buffers, and you can press Enter on a buffer name to go to that buffer. Or, press F12 (next) or Shift-F12 (previous) to cycle through the buffers.

How do you start a new buffer?

To open the next buffer in the buffer list in a new window, use the ":sbnext" command. To edit the previous buffer in the buffer list, use the ":bprevious" or ":bNext" command. or the abbreviated ":bp" To open the previous buffer in the buffer list in a new window, use the ":sbprevious" or ":sbNext" command.


1 Answers

:e thefile | bd#

This solution has the advantage that it will preserve windows.

  1. Open "thefile" in a new buffer
  2. Delete the most recent buffer (# is the alternate buffer)
like image 157
wisbucky Avatar answered Oct 21 '22 06:10

wisbucky