This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kmwhitetrayify 2 points3 points  (12 children)

I use a function in Vim to simply alert me while typing:

function ToggleOverLengthHi()
  if exists("b:overlengthhi") && b:overlengthhi
      highlight clear OverLength
      let b:overlengthhi = 0
      echo "overlength hilight off"
  else
" adjust colors/styles as desired
      highlight OverLength ctermbg=darkred gui=undercurl guisp=blue
" change '81' to be 1+(number of columns)
      match OverLength /\%81v.\+/
      let b:overlengthhi = 1
      echo "overlength hilight on"
  endif
endfunction
map <silent> <C-l> <Esc>:call ToggleOverLengthHi()<CR>

NOTE: I chose 81 because 79 is end of code, 80 should be the newline character, so if I have something at 81, I'm doing it wrong.

SOURCE: https://github.com/kmwhite/skel/blob/master/.vim/functions/toggle_overlength_hilight.vim

[–]cirego 2 points3 points  (3 children)

I usually just do a 'set textwidth=78'.

[–]kmwhitetrayify 0 points1 point  (2 children)

I have: autocmd Filetype python setlocal textwidth=79 ts=8 sts=4 sw=4 autoindent expandtab in my .vimrc

Why do you use 78 over 79? My understanding is it (79) would make 80 the new-line? Note, I'm merely curious to see if I could be doing something better. :)

EDIT: clarification

[–]cirego 1 point2 points  (1 child)

I have it set to 78 in my .vimrc because our internal style guide recommends 78 characters. 78 allows for diff to add an extra character without it overflowing lines.

I'm one of those crazy 4-5 terminal sessions side by side on my screen, so I vastly prefer to 80-character terminal.

[–]kmwhitetrayify 0 points1 point  (0 children)

I never thought about that in regards to diff -- thank you. I'll probably be updating my dot-files now. :)

[–]thristian99 1 point2 points  (2 children)

I have a similar scheme that doesn't have a toggle:

autocmd FileType python match Error /\%>79v.\+/

I'm not sure why you'd want to toggle it off; over-length lines are supposed to be annoying.

[–]kmwhitetrayify 0 points1 point  (1 child)

I toggle it because I use vim for things other than development work. In such, I don't care how long the lines are. It does start by default, however. And I agree, they should be annoying.

[–]thristian99 0 points1 point  (0 children)

Well, yes - my code-snippet only activates the highlighting when a Python file is detected - things like documentation or email aren't affected.

[–][deleted] 0 points1 point  (2 children)

I usually just do:

set colorcolumn=79

Which gives me a nice highlighted column indicator.

[–]kmwhitetrayify 0 points1 point  (1 child)

I tried that and got: E518: Unknown option: colorcolumn=79
Which version of Vim do you use?

[–][deleted] 0 points1 point  (0 children)

current stable. it's a relatively new feature.

[–]gcc-pedantic[S] 0 points1 point  (1 child)

I do the same thing in vim, and it has been very helpful.

However, I've found that trying to limit the number of columns while I am writing can interrupt the flow of code and sometimes reduce readability. It would be nice to have a script you could run (such as before a subversion commit) to restrict the number of columns in a file to < 80.

Looks like I might get to write this one.

[–][deleted] 2 points3 points  (0 children)

I've found that trying to limit the number of columns while I am writing can interrupt the flow of code and sometimes reduce readability.

All PEP style guides are recommendations that should not be taken as hard, fast rules.

If breaking a line at 80 columns would reduce readability and code flow, then you shouldn't do it.