r/vim • • Aug 26 '19

Vim Windows - Open multiple files on Vim

Post image
630 Upvotes

49 comments sorted by

30

u/[deleted] Aug 26 '19

10

u/ivster666 Aug 26 '19

I prefer this Color scheme :)

2

u/HoldMyWater Aug 27 '19

I prefer the other one. The white is too bright for my sissy, dark-theme acclimated eyes.

To each their own. :)

48

u/Primital Aug 26 '19

<c-w> v splits the window vertically.

<c-w> s splits the window horizontally.

5

u/[deleted] Aug 26 '19

Thanks, I didn’t know that

6

u/Primital Aug 26 '19

Another useful function is the <c-w> </> which changes the width of the active pane.

Can also be used with a number as many things in vim, like

<c-w> 20 >

11

u/Tanath Aug 26 '19

Written like that it looks like you're referring to /. Wasn't until the end I realized you meant >/<.

→ More replies (1)

4

u/Baspar Aug 26 '19

Nice, but I always find it difficult to find the correct number to put. I'm an advocate of <c-w>| and <c-w>_, combined with c-w>= to balance everything again

13

u/christian-mann nnoremap ; : Aug 26 '19

:new and :vnew open new windows with blank buffers

8

u/SrineshNisala Aug 26 '19

Do you have all these images in one place?

17

u/[deleted] Aug 26 '19

I have plans to make other topics and after that will make on PDF file including everything.

4

u/code1302 Aug 26 '19

Can't wait, this is great

2

u/bcozimme Aug 27 '19

please do 😭

1

u/noelevans Aug 27 '19

Some tmux ones would be great too if you're looking for business ideas

3

u/bravekarma Aug 26 '19

Also <C-w>p alternates between two windows, in contrast to <C-w>w which cycles between all present windows. Kind of like :buffer # / <C-^> vs. :bnext for buffers.

1

u/[deleted] Aug 26 '19

This is so cool.

12

u/[deleted] Aug 26 '19 edited Aug 26 '19

I really like <c-w>o (makes the current window the only window) for reading help files.

Edit: You can also do :vsplit . To open netrw and search for the file you want

6

u/Cyph0n Aug 26 '19

Any way to go back?

Tmux has Ctrl-B Z which basically “maximizes” the current pane. If you hit it again, it returns you to the original layout.

4

u/y-c-c Aug 26 '19

Not unless you use a plugin. A close alternative to tmux maximizing is :tab sp which opens a new split of the window in a new tab. Close the tab/window to go back.

2

u/wolloda Aug 27 '19

Closest way of doing that with no vimscript that I can think of is using <c-w>| <c-w>_ to maximize current window both horizontally and vertically and then using <c-w>= to go back. This will, however, mess up your layout if your windows weren't the same size.

9

u/dys_bigwig Aug 26 '19 edited Aug 26 '19

You can shorten :vsp to just :vs

vs. is one I use a bit, which opens a new vertical split in the current folder so you can browse. Great if you need to quickly browse for another file in the same folder in another split. Doesn't have to be the same folder of course, you can use vs. and then navigate upward using -. If you already know the name though, just use vs filename.

I'm sure almost everyone on here has already read the "to grok vim you must grok vi" post, which goes into great detail about the vim "language", with operators and operands. Window commands are no different. You have sp for h-split and vs for v-split, adding a . operand for the current folder, or a filename operand to open that file in said form of split. There's a huge assortment of other commands, but I get by quite well with just those few, and it's not much to remember at all if you think in those terms (as you can/should for most vim commands).

I really feel like people using nerdtree haven't bothered to learn window commands like the ones above, and would genuinely be better off just using their old IDE with some kind of vim keymap plugin. Having a file-tree split open constantly isn't really what vim is designed for, nor is the "tabbed" way of arranging your workspace. Master the few essential window and buffer commands and I guarantee you'll find yourself working much more efficiently, and using less precious screen real-estate too.

2

u/[deleted] Aug 27 '19

[removed] — view removed comment

2

u/dys_bigwig Aug 27 '19

I spent a minute or so trying to come up with a witty response, but I genuinely couldn't think of one I'm afraid. The best I can offer is: "when you google that phrase, it's the first fucking result" not up to my usual standard of biting sarcasm, but oh well.

→ More replies (2)

5

u/Yungclowns Aug 26 '19

Why would someone use <C-W>q instead of :q ? Are they different ways of doing the same thing or is there a use of one over the other?

4

u/Primital Aug 26 '19 edited Aug 27 '19

<c-w> q is equivalent to :q!

3

u/Tanath Aug 26 '19

I recommend you use `backtick quotes` to make input clear: :q!

→ More replies (2)

0

u/[deleted] Aug 26 '19

[deleted]

2

u/0bel1sk Aug 26 '19

i'm not sure how it is one less fewer keystroke. 2==2

3

u/starship-unicorn Aug 27 '19

Are we not counting control and shift as keystrokes now? I always have... Am I the one that's doing it weird?

→ More replies (1)
→ More replies (2)

3

u/shivam_c137 Aug 26 '19

Thanks for your posts! Are really alot helpful!

3

u/[deleted] Aug 26 '19

<c-w> R rotates opened windows :D

2

u/christian-mann nnoremap ; : Aug 26 '19

I use this feature all the time, and have mapped ^J to ^W j etc, so that I can move back and forth.

^W H moves a window all the way to the left, and similarly for J, K, and L.

^W + makes a window one line or column bigger; this can be repeated by typing a number beforehand, same as any other vim command. Of course, ^W - makes it smaller.

Oh, and if you have :set mouse=a then you can use your mouse to resize windows, and move your cursor between them.

2

u/talos_security Aug 26 '19

I've been using Windows for over a year and never knew <c-w> w or <c-w> = existed - always learning!

2

u/wakela Aug 26 '19

I'm on a mac and I unfortunately often mix up CTRL-W with COMMAND-W (which closes the window).

2

u/ebetemelege Aug 27 '19

i discovered this by accident, when tmux stopped splitting an R plugin horizontally, then by some miracle, I forgot to invoke tmux, which happens regularly, called R, and wallachia, it split across the screen, I quickly saved all the config files that may have helped

2

u/unstableunicorn Aug 27 '19

These are awesome, any chance you could do them all as wallpapers?

2

u/Platvoetenn Aug 27 '19

Didn't knew the resize command, thanks for posting this ;)

1

u/[deleted] Sep 14 '19

You can use C-w x to reverse the vertically split layout.

1

u/Cmshnrblu Aug 26 '19

Why do this instead of opening more terminal windows?

8

u/[deleted] Aug 27 '19

Because you can

  • highlight the same search on both windows

  • make a diff comparison

  • lock both windows on scroll

  • use a window as a quickfix or location window.

  • etc

3

u/DriftingThroughSpace Aug 27 '19

You also benefit from ins-completion (completing from open buffers)