Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gVim: How to load multiple files in buffer?

Tags:

vim

nerdtree

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.

like image 787
ginotria Avatar asked Aug 18 '11 06:08

ginotria


People also ask

How do I open multiple files in Gvim?

Show activity on this post. in most GUI text editor I can use ctrl click to open multiple files at once.

Can I open multiple files in vim?

By default, the Vim opens only a single window, even if you have opened multiple files. However, you can view multiple windows open at once in Vim. This can be achieved by splitting the windows horizontally to create two windows of the same width, or vertically to create two windows of the same height.

How do I open files side by side in Vim?

Splitting Vim Screen Horizontally To split the vim screen horizontally, or open a new workspace at the bottom of the active selection, press Ctrl + w , followed by the letter 's' .


2 Answers

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.

like image 126
sehe Avatar answered Sep 21 '22 15:09

sehe


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

like image 25
numbers1311407 Avatar answered Sep 19 '22 15:09

numbers1311407