How can I open several files at once in Vim?

后端 未结 6 1076
渐次进展
渐次进展 2021-01-30 07:55

Is there a way to open all the files in a directory from within Vim? So a :command that would say in effect \"Open all the files under /some/path into

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 08:45

    A method that doesn't require messing with args is to put the list of files in a text file, and then use the :so command to run the commands in that file.

    For example, if you want to open all the files that end in .php in a given directory, first create files.txt containing the list of files, prepended with whatever command you want to use to open them.

    sp alpha.php
    sp bravo.php
    sp charlie.php
    

    Then, within vim:

    :so files.txt
    

    If the list of files is large, it's relatively trivial to generate the files.txt file quickly, by redirecting the output of ls to a file, and then using a vim macro to prepend sp before each filename.

    This obviously isn't as elegant as using the args and argdo commands, but those commands are also a lot more complicated.

    There also might be a way to do this with a single command on the command line, but even after 16 years I still find vim programming to be strange and arcane.

提交回复
热议问题