Muffinresearch Labs by Stuart Colville

vim: automatically highlight long lines | Comments (0)

Posted in Code, Linux/Unix on 22nd June 2009, 9:50 pm by Stuart

This .vimrc snippet highlights lines when you exceed 77 columns – this is especially useful if you are trying to adhere to PEP8 with Python development.

The if statement makes this work for older vims as well as more recent versions which is handy if you put your .vimrc on remote boxes as vim below v7.1.40 doesn’t have the matchadd function.

" Highlight lines over 77 columns
if has('matchadd')
    :au BufWinEnter * let w:m1=matchadd('Search', '\%<81v.\%>77v', -1)
    :au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
else
    :au BufRead,BufNewFile * syntax match Search /\%<81v.\%>77v/
    :au BufRead,BufNewFile * syntax match ErrorMsg /\%>80v.\+/
endif

To configure highlighting to work manually see the vim wiki for more details http://vim.wikia.com/wiki/Highlight_long_lines

Whilst I’ve often heard people snub the PEP8 recommendation for keeping line length to under 79 chars, I’ve personally found it leads to more readable code whether you live in a terminal or use gui editors. YMMV

Post Tools

Comments: Add yours







XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



GNU screen: open tab in current working directory|(1)

A nice trick for having screen open a new tab in the same directory as the one you’re currently in. To use it add it to your .screenrc

# Open new window in current dir.
bind c stuff "screen -X chdir \$PWD;screen^M"
bind ^c stuff "screen -X chdir \$PWD;screen^M"

Hat tip: mteckert on SuperUser.com

Ubuntu: add-apt-repository: command not found|(2)

When you’re using a minimal Ubuntu install if you find the ‘add-apt-repository’ command is missing (it’s useful for adding PPAs and other repositories), then simply run:

sudo apt-get install python-software-properties

Photos on Flickr

© Copyright 2004-12 Stuart Colville, all rights reserved. May contain traces of Muffin. Powered by WordPress. Hosting by Slicehost.com This page was baked in 0.458s.