16

Guys how do i open multiple files in vim with a single command?

These files i want to open has some kind of pattern, example:

myfile1dsa
myfile2dsdas
myfile3xzczxcz

and also do these opened files create their own tab in my vim window?

and out of topic question:

what does "--" means in a linux command? how does it differ from just "-"?

example:

grep --color 'data' fileName
ruggedbuteducated
  • 1,318
  • 7
  • 17
  • 22
  • 2
    GNU (and POSIX) defines option flags with one `-` as one-letter 'short options'. Double minuses indicate long options (that are longer than a single letter). This is not always the case (the X convention uses options such as `-display` often) – mike3996 May 16 '13 at 08:12

1 Answers1

30

You can open them from within vim using

:args myfile*

or if you want to open all files matching the pattern in subfolders

:args **/myfile*

This all assumes your current directory is the folder from wich you want to open files from. Prepend a directory to myfile if it's not.

:args /yourfolder/myfile*
:args /yourfolder/**/myfile*

Edit (cudo's to romainl)

To open all the files found in tabs, you can use

:argdo tabe

wich essentially goes like this:

  • argdo: for each file in the argument list
  • tabe : open a new tabpage and edit the file
Lieven Keersmaekers
  • 57,207
  • 13
  • 112
  • 146
  • care to explain what the ** means in your second args – ruggedbuteducated May 16 '13 at 06:31
  • 3
    @ruggedbuteducated, it's easy to explain but `:h **` is better. – romainl May 16 '13 at 06:35
  • it only opens the first occurence of myfile. I am expecting to open several tabs – ruggedbuteducated May 16 '13 at 06:35
  • @ruggedbuteducated - it's the convention used to traverse all subfolders to find the file matching the pattern. – Lieven Keersmaekers May 16 '13 at 06:37
  • 1
    @ruggedbuteducated, once the arglist is populated, do `:argdo tabe`. – romainl May 16 '13 at 06:38
  • @ruggedbuteducated - All your files are available in buffers, not in tabs. Using buffers is the defacto way of working with vim (at least, it is for me). Cudo's to romainl for adding the extra bit on opening them in tabs. – Lieven Keersmaekers May 16 '13 at 06:39
  • how to navigate through the buffer. and i entered :argdo tabe 2 times. now i have several duplicate files. help – ruggedbuteducated May 16 '13 at 06:40
  • @ruggedbuteducated: each file is represented by one buffer but that buffer may be displayed in 0 or more windows in 0 or more tabs. I totally backup Lieven's comment on using buffers instead of tabs. Take the time to read `:h windows`. – romainl May 16 '13 at 06:44
  • 1
    @ruggedbuteducated - You navigate through buffers using `:bn(ext)` or `:bp(revious)`. Personally, I have mapped `:bn` to `` for easy navigating and mapped `b` to `:ls:b` as it's the fastest way I've found to work with a buffer list. That part also came from romainl if I'm not mistaken. – Lieven Keersmaekers May 16 '13 at 06:46
  • ... and offcourse it did. You should definitely read [this](http://stackoverflow.com/questions/16082991/vim-switching-between-files-rapidly/16084326#comment22986046_16084326) – Lieven Keersmaekers May 16 '13 at 06:49
  • 3
    *"You can open them from within vim"* and likewise from the shell command line: `vim myFile*`, `vim **/myFile*`, etc. with exactly the same result (having buffers numbered from '1' and not '2' if one cares). – bloody Apr 07 '20 at 22:57