Wikia

Vim Tips Wiki

Tlgrok/Open files from list file

Talk0
1,612pages on
this wiki

< User:Tlgrok

This is a draft, quarantined as a subpage of my own userpage until (and if) it is ready to face the world. Feel free to edit it.


Say you've got a file containing a list of files which you would like to open.

Let's call this file list.txt. It's contents might be:

~/foo/bar.txt
~/foo/bar2.txt
~/something.pl

The following three commands will allow you to quickly open the files listed:

function s:ReadFileListAndDoSomething (command, file_list)
    for file_path in readfile(expand(a:file_list))
        exe a:command file_path
    endfor 
endfunction

command -nargs=1 -complete=file ReadBuffers call s:ReadFileListAndDoSomething('badd', <q-args>)
command -nargs=1 -complete=file ReadArguments call s:ReadFileListAndDoSomething('argadd', <q-args>)
command -nargs=1 -complete=file ReadTabs call s:ReadFileListAndDoSomething('tabedit', <q-args>)

Add the above code to your .vimrc, and you'll be able to load files as buffers using:

:ReadBuffers list.txt

Add files to your argument list using:

:ReadArguments list.txt

And to open the files in new tabs using:

:ReadTabs list.txt

NotesEdit

This technique can also be used for all sorts of other things - for instance, delete all files listed using the command '!rm'.

Around Wikia's network

Random Wiki