Why Vim Experts Do THIS Instead of Using Tabs...

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Most editors use tabs and windows system, VIM has buffers, Windows and tabs. Some of these obstructions VIM use are different. In short, buffers are memory slots where VIM holds open files, while Windows and tabs are only representational. Any buffer can show up in any window or tab, while not straightforward, knowing now how buffers and windows and tabs relate in VIM. This is one of the many reasons I believe VIM is a superior working environment, and now I've got my coffee, so let's go. What I see when I open VIM is a simple window. I can separate that window, open more of them, so let's open a file and see how that works. I open the main.go, and you can see down below that this is running a buffer. That's called main.go. A buffer is loading a file into the memory. I just separated a split, which is basically another window, and both of them show the same file. I'll remove the background, so it's easier to read. But you can see that main.go is the only buffer that's currently loaded. So even though I have two different windows, it's still using the same buffer. I didn't use any additional memory. Let's see what happens when I add a file to the system. So I open ConfigML, and now you can see below that I have two different buffers. And regardless, whether I move to the window on the right or on the left, main.go and config.file are just two buffers open. I can close one window, and when the split disappears, two buffers are still loaded. In terms of memory, I'm still using two different files loaded. I can use the same window and switch between buffers. But regardless, VIM has them open. I can create this split, a vertical one. I can create horizontal splits. It doesn't matter. The buffers stay the same. Viewing the buffers is easy with telescope, or running the buffers command on VIM. Let's put the background back, and let's load even another file. I'll load the rhythm, and you can see I have main.go, config.yaml, the unnamed buffer, which was an empty file, and read me. So now I have two buffers that I can toggle through with be pre-have, or be next shortcuts for a buffer next and buffer previous. And in my case, they are mapped. You can see that I'm using T and all kinds of shortcuts below. This is because of all the habits I had with tabs. You can just map it however you want. Another cool feature of Lua line, which will go through, is telling you whether there was a change in a buffer. So readme.md now shows a black dot. And if I save the file, the black dot disappears. If I make another change, it reappears. This way I can track which buffers were changed and require saving, which are not. Before I go any further, I know I'm going to be asked a lot. What's the cool new terminal? So that's Western. Western is kind of a niche terminal, but it's absolutely amazing. I've started using it. It's very fast. It's written in Rust, which makes it very performant. And it uses a.config file that's something I used to have with the liquidity. And I'm happy I can still have with Western, but with all the other features. So Western has tons of stuff. It can integrate a shell. It can run an SSH. It even has a multiplexer built into it. I'm not using it because I'm running Tmox as you probably know, but having all of these features is kind of an amazing selling point for the terminal. So I urge you to go look at it and now back to the video. Let's talk about window management. So we spoke about how loading a file loads both into a buffer like we have here, but also opens up in a window. So I have two buffers and one window at the moment. I can open even another file just to show that we can have two or three buffers, but one window. Let's split that window with some file, which is a new name. And we have an empty buffer that's named some file. This split shows two windows in one screen. So I'll add yet another split, the vertical one. And now I have three windows that I can toggle through. By using control w, I can move between them up and down or to the sides. I can kind of zoom into them if that's a vertical. I'll use a pipe and if it's a horizontal one, I'll use the underscore to do that. And I can also do it incrementally with hyphen. So I can move between them or close them and play with that. It's really comfortable to view everything in one place if that's your use case and zoom in and out between different files. Now if I were to call them with two files, I can load both of them into two buffers. As you can see down below, go mod and go somewhere both loaded. I can see the buffers in telescope and see that I have two of them. You can call the buffers command in them that we've mentioned before and see them below without any plug-in. So we touched on buffers, we touched on windows. Let's speak about tabs. If you see up in the window on the top level, I have two different tabs. And tabs is just another way of separating windows. So I have two windows that I can toggle through, but they're not split it under the same screen. They're on different, which you call tabs. I can toggle through with the command tabs next and tab previous much like I do with buffers. But then again, it doesn't have to do with the buffers themselves. I can present any buffer that I have open in any of the tabs or any of the windows. It's just another way to split. This differs than most IDEs where you use tabs to open different files. And that's the big difference between VIM and any other standard IDEs that you're used to presenting files with. If tabs make sense to you, you can run VIM minus P and any number of files following that. And that'll open all the three buffers, split it into different tabs, as you can see below and upstairs in the window. I have all three files listed. I can toggle between them. I can, by the way, close the windows or close the tabs and nothing will happen to the buffers. As long as the buffer is still in the system, I did not run T-Delete, which deletes the tab. I'm still there. So, pretty useful if that's your use case. I have to say that I rarely ever use tabs these days. I load all my new VIM files into buffers and maybe split them in the window that I'm using. Let's jump quickly to the new VIM configuration on my machine. I want to quickly show you what's the Lua line config looks like, so you can enjoy the same experience of buffers and tabs presentation. I use a plugin that's called Lua line that I've mentioned before. And you can see that the Lua line is configured with showing both buffers and tabs. There are different themes, separators. You can change how the changes look like, what's the representation of a file that wasn't saved or was saved. It looked like I didn't go too far with it, but you have a full-blown documentation of Lua line.txt that you can view and change. This also appears on the readme that I'll show in a bit, and very easy to configure and very useful to have as part of your workflow. If you're constantly using buffers and tabs like I do. So here's the Lua line project on GitHub. I strongly recommend that you view it and you check out all the additional features. It's beyond just tabs and buffers. Of course, you can see the status of the mode you're currently using. The Git status changes status of the file, how long you've gone through the file, scrolling features, finding features. It's a full-blown status line for VIM, which I highly recommend, especially if you're a new user like me. If you're still not quite confident with the basics of VIM, I invite you to check the secrets to learning new VIM, which is a video where I show you every possible keystroke in new VIM connected to character on the keyboard it represents. And that'll help you ramp up to a level that you can start getting into the flow of work with new VIM and having, of course, files loaded buffers, etc. Thank you for watching and I'll see you on the next one.
Info
Channel: DevOps Toolbox
Views: 108,376
Rating: undefined out of 5
Keywords:
Id: ST_DZ6yIiXY
Channel Id: undefined
Length: 7min 54sec (474 seconds)
Published: Fri Mar 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.