1

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

4 Answers 4

5

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

1

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.

1 Comment

Thanks, but are there any file browser plugins ? I installed NERDTree but :NERDTree command fails in vim
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.