Search code examples
vimword-wrap

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


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.


Solution

  • 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.