Showing posts with label neovim. Show all posts
Showing posts with label neovim. Show all posts

Sunday, October 18, 2020

Buffers, Windows and tabs in vim/neovim

There are three concepts when it comes to viewing/editing files in vim.

Buffer:

When you open a file in vim the contents are loaded to RAM. This portion of the ram which has the contents of the file is the buffer. Now, this loading happens behind the scenes. It is no good if the file contents are in the buffer. We have to view it. That is what visual editors like vim are for. There are ways and means of editing files without having the contents of the file displayed on the screen. For that you can combine the power of ed and then the later front ends like grep and sed. So, now we are still at a stage where vim has loaded the file into memory and named that block of memory with a name taken from the file name itself. This buffer name can be used in moving around buffers when we have multiple buffers.

When you create an empty buffer, vim allocates a certain amount of the RAM for the buffer. If you write this content to a file then the contents are saved. If you delete the buffer without saving it then all your content created in this buffer is out in the ether.

For playing with buffers vim provides commands starting with :buffer. It follows the object, action on the object philosophy of the other vim commands.

When you shift from one buffer to another using the buffer next command or similar, vim prompts you to save the present buffer to file. This can be overridden with settings in the vim config file.


Window:

This is the area where the contents of the buffer is displayed to the user. After loading the file into the buffer, vim then reads the contents of the buffer and displays it on the screen for the user's viewing pleasure. A full screen of content, which was a big deal in the good old days. To display the file vim creates a window. The file contents are displayed within this window. Okay, you have been editing a single file for many days. Now, you want to refer another file. So you now go ahead and open it up with :e file2

You are in for a shocker, the screen is now showing only the contents of file2. As we have already clarified, a window is the place where vim displays the contents of the file. In the present case we have only one window. So, when you requested vim to open a second file, vim agreed and showed the contents on the solitary windows. To show that vim had to clear the screen and load up the buffer which was the contents read in from file2.

The situation here is we are having one window and two buffers, as such vim can display only one buffer while the other is still loaded and available with vim read to be displayed when asked for. You can ask to bring the buffer contents of file1 to the fore by using appropriate :buffer command. But, instead a more elegant way of viewing both files side by side would be to create another window. This will reduce the screen estate available for each windows. if you open two windows then both share 50% of the screen and so forth.

Ctrl-W v    opens a new window and splits the screen into half vertically. Now you can open file1 in the left window and file2 in the right window. Now there are two buffers and two windows displaying the respective buffer. What if I open the same file in both the windows, well all your editing activities in one window will reflect in the second window also. try it. Because you are editing the same buffer.

To end the discussion about windows, when you close a window, the buffer is not offloaded from memory. It is still there within vim. You have to delete the buffer using the respective command to instruct vim to offload the buffer from memory.

Tab:

Tabs are the masters of vim windows. Every tab has access to the full screen. Withing tabs you create windows as explained above. In the above example there was only one tab which is started by default. Every tab can have multiple windows. When you close a tab you close all the windows in that tab. tabs are good when you want all your files to use the complete screen of your monitor. Whenever a new tab is created it is started with exactly one window. If you want to view file1 and file2 using the full screen estate of your monitor and move between them then, the :tab command is the way to go. The disadvantage is that you cant see the file side by side.

When you close a tab, all the windows within that tab are closed. But all the buffers you were viewing in that tab within their respective windows are still in memory. You have to delete the buffers to remove them from memory.


 Of course, when you quit vim, all the buffers are closed and any changes which you have done to the buffers, will be queried for saving.

In summary, we see that there is no one single strategy which works for and individual. And for every individual, the strategy depends on the task/s at hand. So, dont be very harsh on your preferences. You will be losing out on the most important aspect of vim, ie, "situational editing"

Friday, June 12, 2020

Well, What is on my raspberry pi 4

The first thing I install is my client for the cloud based notes application. I use simplenote. It has the advantage that it is available on all the major platforms. There is a terminal client called sncli. This is my go to client.
The next thing is to install terminology for the terminal. After trying out many, I observed that terminology is the fastest on the pi.
i3 window manager. I cannot live without it. None of my Gnu/Linux installations is complete without this. It is lightweight, easily configurable and simple.
For the browser, since I have started using computers I have sided with Firefox. I am at home with this browser. I install noscript, ublock, privacy badger and dark reader plugins. I like it. It has always met my expectations.
For the application launcher i go with rofi. The run menu is shown in a small window in the bottom left corner of my monitor.
For searching on the command line I use ddgr(DuckDuckgo client for the terminal) and surfraw. After installing surfraw I install a small script called menu-sufraw available on github. This integrates beautifully with rofi. Must try.
For the office suite, My choice was OpenOffice before it went to the butcher's table with the Apache foundation. Now it is libreoffice. I like it. It gets the job done.
For my text editor, wait, wait, I use both Neovim and Doom emacs as demanded by the situation. I use emacs with the client/server model. It is quick and very snappy to start and to work.
Feh for my wallpaper needs.
There is one more plugin which I install on firefox, it is called play-with. This I combine with mpv. We now have an awesome combination for playing streaming content on the pi. For this configuration to work there is one more piece of software required and that is youtube-dl. A beautiful example of the unix philosophy working for the modern age of the internet.
Not to forget that all the apps are in dark mode, if available. I like the dark mode. It has been excellent for my eyes. Even now when firefox flashes before loading a tab, I close my eyes for a while. Thank you, Apple, only for bringing the dark mode into vogue.
My hardware setup is already discussed in one of my previous posts.
font-awesome for that "graphics" in the terminal.
d2code for the font, wherever possible. I like its legibility.
I use i3status showing the date, time, empty space, processor speed and the temperature.

Thanks to all the devs/users of all the freedom software. My respect to one and all without which this post wouldn't exist.