How to setup a line length marker in vim/gvim?
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Isolated
--
Chapters
00:00 How To Setup A Line Length Marker In Vim/Gvim?
00:31 Answer 1 Score 0
00:54 Accepted Answer Score 205
01:17 Answer 3 Score 32
01:41 Answer 4 Score 2
01:58 Thank you
--
Full question
https://superuser.com/questions/249779/h...
--
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