osa1 github gitlab twitter cv rss

Quick Vim Tip: Add Left Margin To Buffers

January 16, 2013 - Tagged as: vim, en.

I almost always work in fullscreen, and when I do that, text in vim starts just where my laptop monitor’s frame ends and it’s really annoying. And even if I don’t use vim in fullscreen, generally I want some margin(empty space) on the left side of vim window.

One way to achieve this is enabling line numbers. But I don’t like this solution because line numbers cause unnecessary noise in the screen.

As a solution, I was using foldcolumn, which, like line numbers, puts some space on the left side to show some folding information. It’s a nice solution if you never use folding in your code, and I wasn’t using folding in my code, but now I’m using folding and foldcolumn looks horrible:

A nasty trick to make this folding guides hidden is making folding guides’ foreground and background color the same, and same as you colorscheme’s background color:

autocmd Colorscheme * highlight FoldColumn guifg=bg guibg=bg

Put this in your .vimrc, somewhere before setting your colorscheme(ie. before colorscheme ... line) and whenever you change color colorscheme, foldcolumn’s colors will be set and folding guides will be hidden.

How does it work: bg and fg are two special variables that will be set by vim automagically whenever you set Normal colors by calling :highlight Normal [options] and all colorschemes do that because that’s the way to set vim’s background color and default text color.

autocmd Colorscheme * makes this command run whenever you set your colorscheme by calling :colorscheme ... command. And now you have clear left margin. Enjoy.