wnd's weblog

December 2013
Mo Tu We Th Fr Sa Su
25 26 27 28 29 30 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

Vim and long lines

4 December 2013 18:29:11 rant, software
highlight LongLines ctermbg=red ctermfg=white
match LongLines /.\\%>81v/"

Some months ago I switched to i3 window manager after discovering a Vim option to highlight column 81. As silly as it may sound, not easily spotting long lines was one of the biggest reason for not switching earlier. However, colorcolumn option wasn't perfect. It messed up using X11 to paste text from Vim.

When I first grew tired to colorcolumn and loads and loads of unwanted whitespaces in pasted text, I figured I'd use X resources to configure rxvt to draw column markers. These markers would obviously be completely separate from actual text buffer. After struggling to introduce X resources in rxvt, I realised my plan also was flawed; this wouldn't work properly with Vim's windows.

When the time to have a Christmas party at work arrived, I realised I'd have quality time to work on this again. I patched rxvt with a private set of VT escape sequences to manage a list of column markers. Adding this functionality was surprisingly simple and the unminimised patch (without partially implemented X resources) was just 145 lines. The next step would be to create a Vim script, or in worst case scenario, patch Vim to send required sequences to set the markers.

When I was testing my fancy little patch, I came across some settings in Vim configuration file I had added for highlighting redundant whitespaces a decade earlier. That's when I realised I could use exactly same thing for highlighting long lines. It wouldn't be exactly as pretty as my fancy little patch, but there would be no patching and no compiling.

The next time I think I need to patch some piece of software, I really need to sit on my hands and think if it's really the only way. That would have a lot of time.


Post comment


Add 9 and 7 (required!):