gVim: How to load multiple files in buffer?
Asked Answered
H

3

10

Im in windows and is new in using gvim. I am using the Nerdtree plugin for project navigations. Right now I open files from the nerd tree, vim will then load this opened files in the buffer. I find it easier to switch throug multiple files using the :b command, it gets more convenient after opening more files as more is loaded in the buffer.

But I think it will be more convenient if there is a way to load all files in a directory in the buffer at the same time instead of loading one by one when opening them.

Highfalutin answered 18/8, 2011 at 6:0 Comment(0)
R
18

You can specify multiple files on the command line (or right-click 'Open with Single Vim' in windows).

Equivalently, you can add or change the argument list after starting:

:args *.cs

Replaces the argument list, opening all files as buffers, showing just one

:argadd **/.java

Appends all java files in the tree below the current directory to the argument lst, opening them as buffers, keeping the active buffer in the current window unchanged

There are several other nice commands in relation to this:

:argdo %s/version_1-6-0/version_1-6-1/g
:bufdo g/SECRET/d

(apply commands to all files in argument list vs. all open buffers)

:sall
:tab sall

(open all loaded buffers in separate windows, optionally in tabs)


OT hint: to clear out the buffer list

:bufdo bclose
:bufdo bwipeout
:bufdo bwipeout!

Set the current directory:

:cd $HOME/myproject/subdir

Set it to the dir of the currently open file:

:cd %:h

This is very handy with tools like :argadd *.cpp or :!ctags -R . etc.

Reaves answered 18/8, 2011 at 7:21 Comment(2)
I've got an autocmd, autocmd BufEnter * silent! lcd %:p:h:gs/ /\\ /, which switches the current directory whenever I switch buffers. Very handy for the reasons listed here.Lyonnesse
In the :argadd example it should be :argadd **/*.java instead of :argadd **/.javaComfort
T
2
vim mydir/*

Should do the trick

Edit:

Oops, windows. I just found this similar thread quickly, which might be of some help.

Open files in existing Gvim in multiple (new) tabs

Tuddor answered 18/8, 2011 at 6:5 Comment(0)
E
2

If you use the project plugin for Vim, you could open all files under the currently selected entry.

Note that an entry is not only limited to be a folder, you could e.g. place all your needed includes in one entry and then open them in one go.

The plugin gives you also more project-relevant features like grepping through all files of the currently selected entry and many more.

Setting up your project is a little effort, but once you've done that, it's really comfortable.

Enceinte answered 18/8, 2011 at 8:3 Comment(1)
Thx. That sounds interesting (although I have a tendency to prefer vanilla Vim)Reaves

© 2022 - 2024 — McMap. All rights reserved.