How to setup a line length marker in vim/gvim?
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Mysterious Puzzle
--
Chapters
00:00 Question
00:43 Accepted answer (Score 187)
01:10 Answer 2 (Score 31)
01:52 Answer 3 (Score 2)
02:17 Answer 4 (Score 0)
02:45 Thank you
--
Full question
https://superuser.com/questions/249779/h...
Question links:
https://stackoverflow.com/questions/2354...
Accepted answer links:
[textwidth]: https://vimhelp.org/options.txt.html#%27...
[colorcolumn]: https://vimhelp.org/options.txt.html#%27...
Answer 2 links:
["More Instantly Better Vim" talk]: http://youtu.be/aHm36-na4-4
[move those 2 lines to the last part]: https://superuser.com/a/771578/2132
Answer 4 links:
[Hacking Vim: A Cookbook to get the Most out of the Latest Vim Editor]: http://www.packtpub.com/hacking-vim-cook...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#vim #gvim
#avk47
ACCEPTED ANSWER
Score 205
Just execute this
:set colorcolumn=72
You can also prefix the argument with -
or +
to put the marker that many columns to the left or right of textwidth
, and it accepts a comma-separated list of columns. I think the colorcolumn
option is only in Vim 7.3. See
:help colorcolumn
ANSWER 2
Score 32
From Damian Conway's "More Instantly Better Vim" talk at OSCON 2013:
highlight ColorColumn ctermbg=magenta
call matchadd('ColorColumn', '\%81v', 100)
This results in the character being highlighted in magenta (the screenshot is in DarkCyan
) when the line goes over the 80-character maximum.
For gVim: it's best to move those 2 lines to the last part of your .vimrc
file to ensure it works.
ANSWER 3
Score 2
You could try this:
grep '.\{81\}' file
or
set colorcolumn=80
(or the shorthand equivalent)
set cc=80
or as aforementioned:
match ErrorMsg '\%>80v.\+'
ANSWER 4
Score 0
Below is a clumsy trick from Hacking Vim: A Cookbook to get the Most out of the Latest Vim Editor by Kim Schultz.
It highlights with ErrorMsg
(usually bright red) any lines that go over 80 characters. Works well for me.
function! RemoveWidthLimitWarnigns()
silent! call matchdelete(4)
endfunction
function! InsertWidthLimitWarnings()
call RemoveWidthLimitWarnigns()
call matchadd("ErrorMsg", "\\%>79v.\\+", 10, 4)
endfunction