As of vim 7.3, you can use set colorcolumn=80 ( set cc=80 for short).
Use ctrl+v to select a column of text consisting of the first character of the place you want your new column to go in front of. Use I to go into insert mode, and type one space. Press Esc, and you'll see you have inserted a column of single spaces. Now use ctrl+v again to highlight the column of spaces.
Now if you want to add line break after a specific pattern, you can easily add line break '\r' after the cur pattern above. For example, if you want to add line break after '}' character in file data. css, you need to go to open the file in vi editor. Go to command mode, by hitting Esc key.
To change your split orientation use the command that prepends all split commands: ctrl-w followed by either K or H: ctrl-w H – Change horizontal splits to vertical. ctrl-w K – Change vertical splits to horizontal.
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
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.
There is another way to notify about the long line.
highlight OverLength ctermbg=red ctermfg=white guibg=#592929 <br>
match OverLength /\%81v.*/
Vim 80 column layout concerns
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/.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With