How to show vertical line to wrap the line in Vim?

VimWord Wrap

Vim Problem Overview


I'm interested in finding a way to show a vertical line at column 80 in Vim (not GVim).

I've used set wrap, but I just want to show a vertical line so I can wrap the long line myself.

Vim Solutions


Solution 1 - Vim

New in Vim 7.3:

> 'colorcolumn' is a comma separated list of screen columns that are > highlighted with ColorColumn. Useful to align text. Will > make screen redrawing slower. The screen column can be an absolute number, or > a number preceded with '+' or '-', which is added to or subtracted from > 'textwidth'.

Example from the docs:

:set colorcolumn=+1        " highlight column after 'textwidth'
:set colorcolumn=+1,+2,+3  " highlight three columns after 'textwidth'
:highlight ColorColumn ctermbg=lightgrey guibg=lightgrey

You can use absolute numbers as well:

:set colorcolumn=80

Solution 2 - Vim

Edit: For Vim >=7.3 see answer below.

Unfortunately vim has no mechanism to display a vertical line after a column like you want (unlike, say, TextMate). However, there are alternative visual indicators that you can use to show that a line is too long.

Here's what I use (you can put this in your .vimrc):

nnoremap <Leader>H :call<SID>LongLineHLToggle()<cr>
hi OverLength ctermbg=none cterm=none
match OverLength /\%>80v/
fun! s:LongLineHLToggle()
 if !exists('w:longlinehl')
  let w:longlinehl = matchadd('ErrorMsg', '.\%>80v', 0)
  echo "Long lines highlighted"
 else
  call matchdelete(w:longlinehl)
  unl w:longlinehl
  echo "Long lines unhighlighted"
 endif
endfunction

So then you can use <Leader>H to toggle columns over 80 being highlighted.

Solution 3 - Vim

There is another way to notify about the long line.

highlight OverLength ctermbg=red ctermfg=white guibg=#592929 <br>
match OverLength /\%81v.*/

https://stackoverflow.com/questions/235439/vim-80-column-layout-concerns

Solution 4 - Vim

I use match ErrorMsg '\%>80v.\+' which will highlight anything over 80 chars with red.

I put that command in my python.vim and ruby.vim under ~/.vim/after/ftplugin/.

Solution 5 - Vim

Several answers here http://vim.wikia.com/wiki/Highlight_long_lines simple autocommand

:au BufWinEnter * let w:m1=matchadd('Search', '\%<81v.\%>77v', -1)
:au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjenniferView Question on Stackoverflow
Solution 1 - VimUncleZeivView Answer on Stackoverflow
Solution 2 - VimSamView Answer on Stackoverflow
Solution 3 - VimBrianView Answer on Stackoverflow
Solution 4 - VimPierre-Antoine LaFayetteView Answer on Stackoverflow
Solution 5 - VimmichaelView Answer on Stackoverflow