3

I use :sf <filename> with Vim a lot, to split horizontally and edit the said file in the new window.

I wonder what's the equivalent command to do the same but split vertically rather than horizontally.

:vne seems the closest I can find to this, but the help says it doesn't search for the file like :sf does.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
bjfletcher
  • 11,168
  • 4
  • 52
  • 67

2 Answers2

7
:vert sf <filename>

From :h :vert:

                        *:vert* *:vertical*
:vert[ical] {cmd}
        Execute {cmd}.  If it contains a command that splits a window,
        it will be split vertically.
        Doesn't work for |:execute| and |:normal|.

Note: The usual way of describing the 'direction' of a split (vertical/horiontal) is by the axis of the split, not the layout of the windows, so you're actually looking for a vertical split here.

Marth
  • 23,920
  • 3
  • 60
  • 72
  • Thanks, it makes better sense now. `:vert sf` is a bit long and I was hoping for something like `:vsf` but anyway thanks for the answer. – bjfletcher Sep 04 '15 at 14:07
  • 1
    Thanks for that note, I've just updated my question to use v instead of h. Thanks again. – bjfletcher Sep 04 '15 at 14:13
  • 2
    @bjfletcher: You could use `:cabbrev vsf vertical splitfind`, altough then any time you type `vsf` in command mode it'll be expanded to `vertical splitfind` (though you're probably not typing `vsf` in another context all that often). – Marth Sep 04 '15 at 14:17
  • 1
    cool, 4 or 5 extra characters really isn't that big a deal when I'll be doing it only once every now and then. Thanks for your answer & helpful comments. – bjfletcher Sep 04 '15 at 14:20
  • @Marth be careful with simple `cabbrev`'s as they expand in unexpected places. e.g. `/`, `=`, and `input()`'s. See `getcmdtype()` for a list. You can roll your own via an [expression mapping](http://stackoverflow.com/a/7515418/438329) or use [cmdalias.vim](http://www.vim.org/scripts/script.php?script_id=746). Example of expression mapping: `cnoreabbrev vsf getcmdtype() == ":" && getcmdline() == 'vsf' ? 'vert sf' : 'vsf'` – Peter Rincker Sep 04 '15 at 15:16
2
:sp filename

Splits the screen horizontally

:vsp filename

Splits the screen vertically

Sagar Jain
  • 7,475
  • 12
  • 47
  • 83
  • When I said horizontally, I meant windows on the left and right, rather than on the top and bottom. Was I meant to say vertically? `:sp` I see is top and bottom. – bjfletcher Sep 04 '15 at 14:01
  • 1
    That's great, very close now :) you have `sp` and `vsp` there, great, and if you can put in `sf` and `???` too then this would be the answer I wanted. I'll upvote and accept. :) – bjfletcher Sep 04 '15 at 14:04
  • I answered this question on mobile platform. I don't know how to format it. I can't even test the commands :( Thanks for sf and ???. I didn't know these commands :D – Sagar Jain Sep 04 '15 at 14:05
  • I usually type the answers in Vim and then post here. But, now I don't have access to vim and I've to type the answer slowly on this lousy mobile platform. – Sagar Jain Sep 04 '15 at 14:16