Highlighting the 70th character of the current line in Vim

I like to keep a strict 70 character mark when possible. To help with this, I want to configure vim so that the 70th character of the current line is highlighted. I understand that

set cursorline 

can be used to highlight the current line. However, I would just like the very end of the line (70th character) to highlight. How can i do this?

Edit: cursorcolumn is not what I'm looking for. I need only one character (70th in the current line).

Edit 2: maybe the image will help. enter image description here

+5
source share
4 answers

You can use colorcolumn to set the right margin strip.

This did not exist before Vim 7.3, so it would be wiser to enable it only if the function is available.

 if exists('&colorcolumn') set colorcolumn=70 endif 

I prefer this to only display in insert mode, so I use this:

 if exists('&colorcolumn') autocmd InsertEnter * set colorcolumn=80 autocmd InsertLeave * set colorcolumn="" endif 

This will set the parameter when switching to insert mode and turn it off when you leave insert mode.

+5
source
 :call matchadd('Todo', '\%70c') 

and if you do not want to consider one tab as one character, but you want to take into account all the spaces that it occupies:

 :call matchadd('Todo', '\%70v') 

You can use any other selection group (for example, to change the color) specified by :hi instead of Todo .

+1
source
 :autocmd CursorMoved * exe 'match IncSearch /\%70v\%' . line(".") . 'l./' 

The color of the backlight will be determined by your color scheme.

You can change IncSearch to any of the highlighted groups that can be found by typing:

 :hi 
+1
source

If you are using VIM 7.3, you can set the color of a specific column using

 set colorcolumn=70 
0
source

Source: https://habr.com/ru/post/1263554/


All Articles