开发者

GVim - How to handle multiple files

Sorry to ask such a novice question but I am looking for a way to handle multiple files. I dont want to type huge开发者_高级运维 file paths to open every file using :tabnew and :e commands


Fuzzy Finder is a handy plugin to quickly find and open files.

Basically you have to only type a few letters like test and you'll get a pop-up menu to open in your current path :

footest.c
bartest.h
footest.h
...

It is a bit slow when used on NFS but it is useful if you don't want to type long path and file names.

Alternatively if you don't want to use any plugin, by default gvim/vim includes a file browser called netrw.
To start it, just type :e . you'll get the content of your current directory, you can then navigate through the directory structure quite easily. (There is even commands to delete, rename, etc like a standard file explorer)

:help netrwfor more information.


A couple of tips that you might be interested in:

  • You can configure Vim so that the current directory "follows" the directory of the file you are currently editing. That way you can edit another file from the same directory without having to type the full path. This can be achieved by putting either set autochdir or autocmd BufEnter * lcd %:p:h in your .vimrc

  • You can use wildcards with tab completion. e.g. to edit a_file_with_a_long_name.txt you could do :e a*long and then press Tab followed by Return.


Usually, vim supports buffers for that. Use :badd to add buffer, :bdelete to remove it and :ls (or :buffers) to list all opened buffers. I believe, GVim supports these features too.

For example, if you wanna edit all .rb files in your app/controllers/pages dir (in the case of Rails project), you type vim app/controllers/pages/*.rb in your terminal and then edit the first file (buffer) in the vim window. When you've done with all changes, save changes as usual with :w (note: do not use q! option - this will close all your buffers you've opened) and then use :bn<tab> (or fully, :bnext) or :bprevious to switch to the next file (buffer). When you run :bnext on the last buffer, you'll be dropped to the first one.


You can open a directory in Vim, search for the file o directory you are looking for with '/' and type [enter] to open it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜