Vim Tips Wiki

Tlgrok/Open files from list file

< User:Tlgrok

1,616pages on
this wiki

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:


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

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


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