Showing posts with label window. Show all posts
Showing posts with label window. Show all posts

Saturday, April 22, 2023

Multiple monitors with i3 wm

 This took a very long time to happen. Ultimately it is a downgrade which has made me to take up multiple monitor setup. A Dell laptop, around 5 years old, was discarded by my son certifying it to be very slow. However, the laptop was upto the task considering the mac mini which I had. So, upgraded the hdd to ssd. I started from a clean slate. Installed a clean copy of windog 10(well, paid for the license when the laptop was brought). After a flurry of updates and reboots... phew.. it was complete.

Now to the favorite part. Getting Arch Gnu/Lnux onto the laptop. Tried installing arch based derivatives with i3 as the wm. However, was not happy with the plethora of packages which got installed. I have nothing against the distros. However, I have been destroyed by the plain/vanilla install of arch Gnu/Linux on all my computers. So wiped again, and did a vanilla arch gnu/linux install. Installing packages as and when I was hitting a wall for a particular task. Just goes a long way to tell how much effort you have put to make your arch gnu/linux install "your own". That is not time wasted. But, time well spent.

As I again, brought the install to my liking, it is bewildering to see the control one has on his computer. Compare it with the windows install. Cannot compare. Yes, cannot compare the ease with which GBs of software lands on your computer in the name of "ease of use". Well, Freedom is never easy and never will be. 

 However, the point of the post is multiple monitor setup with i3. Let me start by telling that it was not easy. Lot of web searching and personal shares of various users have made me to nearly approach the setup which I liked. Again, which I liked... so... The basic premise is I wanted 05 workspaces on the QHD monitor and another 05 workspaces on the laptop display(FHD). This was my requirement. However, wherever, I was searching, the majority of the results concentrated on moving workspaces or containers or windows or another atomic elements in i3. I did not want to move applications between the monitors. Some apps are better on QHD and some on FHD. So the applications will go respectively to those workspaces as decided by the user(me). Tie the workspaces to the monitors


Howver, the point of the post is multiple monitor setup with i3. Let me start by telling that it was not easy. Lot of web searching and personal shares of various users have made me to nearly approach the setup which I liked. Again, which I liked... so...

The basic premise is I wanted 05 workspaces on the QHD monitor and another 05 workspaces on the laptop display(FHD). This was my requirement. However, wherever, I was searching, the onus was on moving workspaces or containers or windows or another atomic element in i3. I did not want to move applications between the monitors. Some apps are better on QHD and some on FHD. So the applications will go respectively to those workspaces as decided by the user(me).

Tie the workspaces to the monitors

workspace $ws1 output $qhd
workspace $ws2 output $qhd
workspace $ws3 output $qhd
workspace $ws4 output $qhd
workspace $ws5 output $qhd
workspace $ws6 output $fhd
workspace $ws7 output $fhd
workspace $ws8 output $fhd
workspace $ws9 output $fhd
workspace $ws10 output $fhd


Added the following to meet the requirement which I set out to achieve. When you now hit the hot key for navigating to a particular workspace, irrespective of the monitor, the focus is on that particular workspace.

bindsym $mod+1 focus output $qhd;workspace $ws1
bindsym $mod+2 focus output $qhd;workspace $ws2
bindsym $mod+3 focus output $qhd;workspace $ws3
bindsym $mod+4 focus output $qhd;workspace $ws4
bindsym $mod+5 focus output $qhd;workspace $ws5
bindsym $mod+6 focus output $fhd;workspace $ws8
bindsym $mod+7 focus output $fhd;workspace $ws7
bindsym $mod+8 focus output $fhd;workspace $ws8
bindsym $mod+9 focus output $fhd;workspace $ws9
bindsym $mod+0 focus output $fhd;workspace $ws10


As a bonus, now, let us say you have the workspace you want to work on in clear view on the other monitor. You just want focus on that monitor. Add the following to your config

bindsym $mod+period focus output left

Kindly bear in mind, the keybindings which are already utilized in your config file before changing anything.

Thats it.

A big Shout-out and Thanks to all the devs and users making the "free as in freedom" world possible.

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"