2

I have recently switched to VIM using NERDTree and python-mode. As NERDTree seems to have a conflict with python-mode and breaks my layout if I close one out of multiple buffers, I decided to switch to netrw since it is shipped with VIM anyway.

But having a file opened, if I open netrw by typing :E and open another file by hitting <enter> VIM closes the old one and opens the new one in the same window. And if I hit <o> in the same situation VIM adds another buffer but adds a new window in a horizontal split.

How can I add multiple files/buffers to the buffer list and only show the last added buffer in the active window (without new splits) using netrw? #edited#

Thanks in advance! I hope I haven't missed something trivial from the manual.. ;-)

Cord Kaldemeyer
  • 6,405
  • 8
  • 51
  • 81
  • This doesn't seem to really be a programming question, perhaps it would be better at http://vi.stackexchange.com – Eric Renouf May 29 '15 at 15:31

3 Answers3

3

But having a file opened, if I open netrw by typing :E and open another file by hitting <enter> VIM closes the old one and opens the new one in the same window.

[...]

How can I open multiple files/buffers in the same window using netrw?

Buffers are added to a list, the buffer list, and facultatively displayed in one or more window in one or more tab pages.

Since a window can only display one buffer, the only way to see two separate buffers at the same time is to display them in two separate windows. That's what netrw's o and v allow you to do.

When you use <CR>to edit a file, the previous buffer doesn't go away: it is still in the buffer list and can be accessed with :bp[revious].

Community
  • 1
  • 1
romainl
  • 186,200
  • 21
  • 280
  • 313
  • Thanks for your quick reply! I have maybe not expressed myself clearly (see my edit). I know about the buffer list and want to open multiple buffers using `E:`. But only the last opened buffer should be displayed. If I then want to switch I can do that usign `:bn`, `:bp` or `:b#`. – Cord Kaldemeyer May 29 '15 at 16:37
  • Basically, that would the same behaviour as with NERDTree. – Cord Kaldemeyer May 29 '15 at 16:55
  • "When you use to edit a file, the previous buffer doesn't go away: it is still in the buffer list and can be accessed with :bp[revious]." If you mean the enter-key with the key this does not apply in my vim installation. If I open several files this way and then use `:buffers` it only lists the last file I have opened! – Cord Kaldemeyer May 29 '15 at 19:50
  • Do you have `set hidden` in your `~/.vimrc`? – romainl May 29 '15 at 20:08
  • It works if I delete my .vimrc, so the error must be somewhere in my configuration. I'll do some troubleshooting tomorrow. Thanks already for your help! – Cord Kaldemeyer May 29 '15 at 21:41
  • It was the setting `set autochdir` in my .vimrc that prevented to load multiple buffers. I guess it is sometimes better to start an own config than just copying it from other users/manuals.. I'll mark your answer as accepted because now I have exactly the behaviour I want. Thank you! – Cord Kaldemeyer May 31 '15 at 20:59
2

(for netrw) If you set g:netrw_chgwin to a window number, then pressing [cr] atop a file in the netrw window will open that file up in the specified window. The "C" map can be used to specify the current window for that purpose if its currently showing a netrw listing.

There's also the :Lexplore command, which opens a netrw window on the left-hand side of the vim display; editing will occur to netrw's right.

If your netrw doesn't support :Lexplore, you can get the latest netrw which does support it from: http://www.drchip.org/astronaut/vim/index.html#NETRW

user21497
  • 1,061
  • 8
  • 9
1

Project Drawer

I believe what you want is a "project drawer" (aka like TextMate or Sublime Text) with the current projects file structure showing. If behavior is what you are after then you are out of luck. Vim has not notion of "project drawer", only tabs, windows (splits), and buffers.

For more information see this nice article over at Vimcast: Oil and vinegar - split windows and the project drawer

NerdTree

It is common for some to use NerdTree like a project drawer but it ultimately fail as it hinders a good splitting workflow as you have found. Not to mention takes up screen space for a task that probably takes up less than 10% of your workflow.

Netrw

Netrw is a file explorer and should be treated differently. Since netrw maps <cr> to open the current file in the current window. This means you typically only see your file explorer when you are actually exploring files. If you are referencing your file structure then use a split to hold netrw while you work on your file.

Thoughts

Personally I find that I rarely use any file explorers. I get by with filename completion in insert mode via <c-x><c-f>, ctags/cscope, a fuzzy finder, project navigation via projectionist.vim, and just using :e & <c-d>. I have a related post: Files, Buffers, and Splits Oh My!.

Community
  • 1
  • 1
Peter Rincker
  • 43,539
  • 9
  • 74
  • 101