Day 19: Manipulating Windows in Vim

I was reading up some more on Vim windows, buffers, and tabs. To be able to have unique window layouts for each tab is really cool tbh.

TLDR;

Okay, so here are the highlights of what I did:

  • I learned how to open new windows within a current tab in Vim. Also wrote notes on how to manipulate how new windows open (vertically, or horizontally and with varying window sizes).
  • I watched some more videos on Vim plugins. I can’t wait until I get my Vim config at that level and I actually know how to use it lol.
  • I am working on understanding ‘Fuzzy find’ and the ctrlP / fzf plugins.

Vim Progress

I don’t have much to say today since I’m pretty tired but I will share some of the notes that I took on opening multiple files with Vim. I was mainly trying to understand how to open mulitple windows but vertically. Currently, I really dislike horizontally split windows. You knoww… the ones where the windows are stacked on top of each other. I’m all about vertically split windows. Now, let me save msyelf by saying that sometimes it is better to have the screen split horizontally. So don’t come for me like that.

The main take away that I am a big fan of is opening the help window with the screen being vertically split between the two windows. the command code I used was :vert :help [help_topic] . The :vert is short for vertical and opens any commands that opens a new window with a vertical split rather than the default horizontal split. I swear once I learn more about vimscript and how to customize my config I will change that default. Unless… of course there is a reason that makes sense of course… he..he..he.

Opening New Windows While in Vim

When we open a new window we can have it open with:

  • The current buffer (This is the default)
  • An empty buffer
  • A new buffer for a different existing file

Additionally we can also determine how the Windows are split on the screen depending on the commands that we use to split them. There are multiple ways to accomplish the same tasks in Vim. Below are a few example commands that are easy to remember and will open a new window. For more information type :help opening and it will pull up the section that highlights opening a window in Vim.

# Simple opening for new window horizontal split
:sp
# Simple opening for new window vertical split
:vs

# Add a new Window with a Horizontal Split
CTRL-W s						*CTRL-W_s*
:[N]sp[lit] [++opt] [+cmd] [file]			*:sp* *:split*

# Add a new Window with a Vertical Split
CTRL-W CTRL-V						*CTRL-W_CTRL-V*
CTRL-W v						*CTRL-W_v*
:[N]vs[plit] [++opt] [+cmd] [file]			*:vs* *:vsplit*

# Force any command that splits the screen by adding a window to be a vertical split (This only runs if the cmd splits the screen).
:vert cmd

Note: The [N] is an optional flag for specifying the width of the new window that will be opened.

Note: The [++opt] is an optional flag for specifying the format the [file] should be opened with.

Note: The [+cmd] is an optional flag for providing a Vim command to position the cursor immediately within the new [file].

We can switch between our visible windows by pressing CTRL-w w . There may be other ways to accomplish this that I have not learned yet.

Conclusion

That’s all for today. If you are interested in the MIT course you can check out the video lecture I’m currently going through. The lecture is helpful but isn’t sufficient by itself. Anyways, until next time PEACE!

YouTube player