how to open a file in a list of files in vim?

后端 未结 10 1478
遇见更好的自我
遇见更好的自我 2020-12-05 02:22

I have a longish list of files opened in vim that looks like this:

/dir1/file1
/dir2/file2
/dir2/file3
.....

How can I open all of them one

相关标签:
10条回答
  • 2020-12-05 02:37

    My searchInRuntime plugin has a :Sp and a :Vsp commands that'll do the trick when called banged. However, the files have to exist.

    0 讨论(0)
  • 2020-12-05 02:38

    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.

    0 讨论(0)
  • 2020-12-05 02:45

    I often need to open a changing list of files that had been modified in my SVN checkout. This one liner works to open all modified files in vim tabs.

    svn st | grep ^M | awk "{print($2)}" | xargs vim -p
    
    0 讨论(0)
  • 2020-12-05 02:48

    I'd say with -p for tabs

    vim -p `cat yourlistoffiles`
    
    0 讨论(0)
  • 2020-12-05 02:51

    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}
    
    0 讨论(0)
  • 2020-12-05 02:54

    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.

    0 讨论(0)
提交回复
热议问题