40

How can I open in a split window multiple files. One split for each file if I'm not being clear.

I want to do something like. :sp app/views/*.erb and have the ~7 files all open in their own split windows.

Brian Carper
  • 71,150
  • 28
  • 166
  • 168
lagsalot
  • 513
  • 1
  • 4
  • 7

5 Answers5

62

Not actually from within vim, but perhaps you can run vim like this:

vim -o app/views/*.erb
32

Just learned from tonymec@#vim that you can do

:args app/views/*.erb | all

for horizontal splits or

:args app/views/*.erb | vertical all

for vertical.

Henrik N
  • 15,786
  • 5
  • 82
  • 131
  • Works. Would you please explain how this works? Got no clue why I need to use "args. Expansion to use a new tab for this would be appreciated to (idk how to "pass" the `:tab` modifier to all) – Florian Jul 15 '18 at 22:46
  • I got the code from someone back then and I've never delved deep into how it works. If you figure it out (maybe using `:help args` and so on), please share in a comment! :) – Henrik N Jul 16 '18 at 06:45
  • Explanation: vim remembers all files opened at start-up. This is called the argslist. Even if you open other files from within vim, the argslist remains the same. Here, the argslist is set from withing vim, with `args` (see args_f). Next (it is the next command since we use a bar to separate it (see :bar)) we use `all` to see all files in the argslist at once. Vim used to only have a horizontal split (just easier to implement), so splits are by default a horizontal split. That's why `vertical` exists, which just executes a command but replaces horizontal splitting with vertical splitting. – Hielke Walinga May 24 '19 at 13:25
23
vim -O app/views/*.erb

This is also from the shell. It will open as vertical splits.

Eric Renouf
  • 13,950
  • 3
  • 45
  • 67
James F
  • 1,066
  • 9
  • 5
3

What happens when you do a

:sf app/views/*.erb

from within vim?

Rob Wells
  • 36,220
  • 13
  • 81
  • 146
  • 1
    works for me on Mac. But I was trying to do vertically. from http://stackoverflow.com/questions/32399791/sf-in-vim-but-split-vertically I fount it would be :vert sf – fangmobile Sep 24 '15 at 17:58
1

Had to whip up a function.

  fun! OpenSplits(dir)
    for f in split(glob(a:dir), '\n')
      execute "sp " f
    endfor
  endfun
lagsalot
  • 513
  • 1
  • 4
  • 7