Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a file in a list of files in Vim?

Tags:

vim

People also ask

How do I open multiple files in Vim?

Ctrl-W w to switch between open windows, and Ctrl-W h (or j or k or l ) to navigate through open windows. Ctrl-W c to close the current window, and Ctrl-W o to close all windows except the current one. Starting vim with a -o or -O flag opens each file in its own split.

How do I list files in Vim?

In normal mode, type :e then press Space and Ctrl-D. That will list file names in the current directory.

How do I open a folder in Vim?

When you start vim, it gets the working directory of your shell. And then you can type commands like :e to open paths relative to your working directory. you can run :e bar. c to open a window containing the contents of the bar.

How do I view files in vi?

To use vi on a file, type in vi filename. If the file named filename exists, then the first page (or screen) of the file will be displayed; if the file does not exist, then an empty file and screen are created into which you may enter text.


I'd say with -p for tabs

vim -p `cat yourlistoffiles`

You can use quickfix mode, as following

:set errorformat=%f
:cf myfilelist

at this point you can use the normal quickfix shortcuts to go through your files, :cn for the next file, :cp for the previous one and :cr to go to the first again.

EDIT:

oh, if you want to read the list from the current buffer, use :cb instead of :cf in in the instructions above


You can do the following

cat file | xargs vim

Where "file" contains your list of files, this will open the files in the same vim session. As usual when opening multiple buffers, you can navigate forward with :bn and backward :bp.


I'm going to assume you have the file list open inside Vim, and want to simulate the "gf" command across the whole list...

Edit your .vimrc to include this function:

function Openall()
    edit <cfile>
    bfirst
endfunction

You can then highlight the entire file (or the set of paths you want to open) using visual mode (1G, Shift-V, G) and typing ":call Openall()". Afterwards the command row will show this:

:'<,'>call Openall()

This will run the new Openall() function across all highlighted lines.

Press Enter and all the files will be opened in background buffers. You can then access them using the usual buffer commands. :ls will display them as a list.


I suppose you want to select and list in vim. all the files of a certain extension. From your home directory or a particular source.

find . -name "*.sh" | vim -

Then within vim, you could search and view this potentially huge list. (Another topic)

You found your file, now you want to open it in a split?

CTRL-W F                        *CTRL-W_F*
    Split current window in two.  Edit file name under cursor and
    jump to the line number following the file name. See |gF| for
    details on how the line number is obtained.
    {not available when the |+file_in_path| feature was disabled
    at compile time}


CTRL-W gf                       *CTRL-W_gf*
    Open a new tab page and edit the file name under the cursor.
    Like "tab split" and "gf", but the new tab page isn't created
    if the file does not exist.
    {not available when the |+file_in_path| feature was disabled
    at compile time}