Skip to content

Instantly share code, notes, and snippets.

@g0xA52A2A
Last active April 28, 2020 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g0xA52A2A/14dfabefb0d9a581fdc917811872155f to your computer and use it in GitHub Desktop.
Save g0xA52A2A/14dfabefb0d9a581fdc917811872155f to your computer and use it in GitHub Desktop.

Preamble

In an effort to consolidate my focus in Vim I wondered what it would be like if I limited myself to a single window. This notion came about because I knew I wasn't utilizing things like tags, jumps, and the quickfix list as effectively could be done.

It's important to remember that no configuration is a substitute for discipline when learning to change. This is simply a journey I went on and sharing what I learnt about Vim along the way.

Windows

I would note I've never been keen on the idea of setting up lots of windows with different buffers in each. Having two windows vertically split would be about as far as I would go and perhaps rarely a third window split wherever.

Splits I don't like anyway

Vim splits some things by default which I'm not too keen on.

By default :help opens up another window that is split horizontally.

The quickfix window is another item Vim defaults to opening in a split. Whilst this was something I didn't love I didn't hate it either and just lived with it.

A simple config

Preventing Vim or ourselves creating split windows is pretty easy, when we enter a window ensure it is the only one displayed.

augroup OneWindow
  autocmd!
  autocmd WinEnter * only
augroup END

This method essentially takes a "corrective" approach allowing for split windows and then ensuring the window we are in is the only one displayed.

This is actually the only viable method because as mentioned in the beginning, Vim simply defaults to splitting windows for some things and can't be set to do otherwise.

Splits I do like

Now that being said I do value using Vim as a diff tool so let's make an exception.

augroup OneWindow
  autocmd!
  autocmd WinEnter * if &diff ==# 'nodiff' | only | endif
augroup END

The quickfix window is special

One thing I noticed is that with the above autocmd the quickfix window wasn't displaying correctly. It would become the only window but it would not take up all the available lines. So as always let's check the :help as our first step.

:cope[n] [height]       Open a window to show the current list of errors.

                        When [height] is given, the window becomes that high
                        (if there is room).  When [height] is omitted the
                        window is made ten lines high.

Sure enough I was getting a quickfix window only ten lines high. As we cannot define the default value for this via a setting again we need to consider a "corrective" approach.

augroup OneWindow
  autocmd!
  autocmd WinEnter * if &diff ==# 'nodiff' | only | endif
  autocmd BufReadPost quickfix resize
augroup END

Now whilst I was going over height related settings in the help I also came across winfixheight which is set for the quickfix window. Sadly I can't recall exactly how I came across this, likely :helpgrep.

So the complete snippet is.

augroup OneWindow
  autocmd!
  autocmd WinEnter * if &diff ==# 'nodiff' | only | endif
  autocmd BufReadPost quickfix setlocal nowinfixheight | resize
augroup END

Finding a bug

Surprisingly in this adventure I managed to make Vim crash when opening the location list. I reported this with a minimal reproducer and it was quickly fixed.

vim/vim#3906

Conclusion

Well this is how I run Vim now so I guess this experiment was a success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment