Day 18: Plugins, Buffers, Tabs, & Vimscript

I went cold turkey and only used Vim today for my work. That was only possible once I learned more about opening windows, navigating through tabs, and a whole lot more in Vim.

TLDR;

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

  • I learned how to open multiple files and windows in Vim. I am still a noob but I can operate at a semi-functional level at least.
  • I watched a ton of videos on Vim plugins. I must say that with plugins Vim looks really cool and super fast.
  • I started reading up on Vimscript so that I can better understand how to improve my Vim configuration files. I have a long way to go but step by step I can make progress. Here is the great online book I found

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 started off covering some key definitions for a window, buffer, and tab in Vim.

Window

A window is a viewport on a buffer. So with a window being a viewport into a buffer, We can use multiple windows on one buffer. We can also use multiple windows on different buffers (I don’t fully understand this yet).

Buffer

A buffer is the in-memory text of a file. When we are editing a file, we are editing the buffer of the file. The file itself remais unchanged until we save the buffer changes to the actual file.

A buffer can be in one of three states:

  • active: The buffer is displayed in a window. That buffer can be a new, unsaved file. That buffer can also be an unsaved buffer for an existing file. The unsaved buffer for an existing file will likely appear different from the original because of the edits made to the buffer that have not been saved yet. (active-buffer)
  • hidden: The buffer is not displayed. It holds the same associations to existing files as an active buffer but is not currently visible through any windows. Remember, a window is a viewport on/into a buffer. (hidden-buffer)
  • inactive: The buffer is not displayed and does not contain anything. Options for the buffer are remembered if the file was once loaded. It can contain marks from the viminfo file. But the buffer doesn’t contain text. –I don’t fully understand this yet. (inactive-buffer)

Tab

A tab page is a collection of windows.

Opening Multiple Files from the Terminal

By default, and with no arguments passed, vim opens one window with an empty buffer. However, vim accepts one or more files as arguments. Each of those files will be opened as a buffer but only one window will be opened since we have not instructed vim to do anything different from the default behavior. We open multiple files by passing each file path as space separated arguments to the vim program.

vim /path/to/file1 /path/to/file2 /path/to/file3

We can also determine how many windows are open by using the flags -o[N] or -O[N] before providing the arguments list.

  • -o[N] will open N number of windows with the windows being split along the horizontal axis i.e. each window will be stacked wide one on top of the other.
  • -O[N] will open N number of windows with the windows being split along the vertical axis i.e. each window will be stacked side by side.

Do not forget that we can pass multiple files as arguments to vim. All the windows will be used to view as many buffers loaded from files as is available. If no windows are available, the buffers will still exist for each file but they will not be vissible. If N is greater than the number of files passed as arguments, vim will still load up N number of windows and have them viewing empty buffers.

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!