An attempt to fix my broken coding flow in Neovim due to a newly purchased 24" 4k monitor

An attempt to fix my broken coding flow in Neovim due to a newly purchased 24" 4k monitor

Backstory

It was a beautiful Saturday morning when I received my newly purchased 24" 4K monitor (Dell P2415Q). I was super excited for this upgrade from my old 22" 1080p monitor, and immediately got it setup after my breakfast. When it lights up, I know that it's money well spent because everything looks so much sharper compared to the old monitor. As a programmer myself, I couldn't wait to try coding in a 4K monitor and immediately fired up my editor of choice - Neovim. And it was at this moment, I knew that I messed it up. The code definitely looks sharper, but this monitor is also wider making them showing up at far left. Which means that, now I have to turn my head slightly to the left to read my code, and I hated it.

2021-11-20_21-20-29.png

Journey to make it "works" again

Everybody has their own workflows, and here's mine. I usually work with two vertical split windows in a tab. Before, I can easily read the code from left and right on my 22" monitor which I can no longer do now. So, what I really wanted to make my Neovim works again is that I have a main window holding a file I am working on in my effective vision and another file opened slightly to the left, so I can turn my head slightly to the left only when I needed to look at some code for reference. The main window should have a fixed width so that when I toggle my file-explorer it wouldn't get resize. I should also be able to easily swap the file from the left to my effective vision when I needed. Lastly, opening files in new tab should work the same.

2021-11-20_21-45-33.png

1. Seeking help from reddit

I can't be the only one having this problem, my monitor is just a 24", what about those who have 27", 32" or even ultra-wide monitor? I am curious about their workflows so I posted a thread in the Neovim sub-reddit seeking for suggestions. I have received a few suggestions like using window manager to control the position of Neovim, setting the fold and sign columns to add a little bit of left padding, and etc. However, those suggestions did not fix my personal workflow so I did not stop here.

Googling for ready-to-use plugins

Again, I can't be the only one, there must be some plugins that fixed just this problem. The first two related plugins I found are focus.nvim and zen-mode.nvim. They are both amazing plugins but just not what I am looking for. The search goes on and I found 3 of them (centerpad.nvim, swap-buffers.nvim, and stay-centered.nvim) that I think with some minor tweaks will work very well together and bring my Neovim back to life!

Getting my hands dirty

1. centerpad.nvim

I didn't end up using this plugin but was inspired by it to use a window as left padding. So I have added some auto commands to both the VimEnter and TabNewEntered events. Whenever I start a new Neovim session or opening a file in a new tab, the auto command gets run and create a layout I wanted as above by splitting them into a main window and side window with empty buffers.

2021-11-20_22-36-03.png

  • Do a vertical split with a specific width and make it fixed. For new tab I am using the swap-buffers plugin because when I open a file in a new tab it will get opened in the support window.

image.png

  • Registering the autocommands image.png

2. stay-centered.nvim

This is super awesome, what it fixes for me is that it makes everything vertically centered. Now, when I go to the last line of a file, this little plugin will make it center by adding some padding to the bottom. This way, I don't have to move my head down to read the last line. What's even best is that I don't need to tweak anything, install and it works!

2021-11-20_22-47-06.png

3. swap-buffers.nvim

This plugins allow me to easily swap the file from the support window to the main window. The only tweak I needed to make is for the cursor to stay at where the swap is called. For example, I am now at my main window and invoke the swap command to the left. The file on the left will now be shown in my main window having the cursor on it.

The end result

sample gif