From 4aad9e5e6a86d54d2bdfcccc8ce77ce069f14f53 Mon Sep 17 00:00:00 2001 From: Anthony Rose Date: Mon, 27 Jan 2025 15:02:20 +0000 Subject: [PATCH] Simplify colorcolumn handling --- vimrc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vimrc b/vimrc index 3f8e6ae..6ac3862 100644 --- a/vimrc +++ b/vimrc @@ -77,8 +77,8 @@ map 3 " larger than the textwidth. E.g. to include a 'margin-bell' line also: " set tw=80 cc=73,81 " Clear the colorcolumn highlighting with cc=0. -set colorcolumn=0 -set textwidth=0 " Suggestions: 72, 80, 100 +set textwidth=80 " Suggestions: 72, 80, 100 +execute "set colorcolumn=" . (&textwidth + 1) " All other settings. set autoindent @@ -148,8 +148,8 @@ if has('eval') let loaded_netrwPlugin=1 function! ACPToggleMargins() - execute "set colorcolumn=" . (&colorcolumn == "0" ? "73,81" : (&colorcolumn == "73,81" ? "101" : "0")) - execute "set textwidth=" . (&colorcolumn == "73,81" ? "80" : (&colorcolumn == "101" ? "100" : "0")) + execute "set textwidth=" . (&textwidth == "80" ? "72" : (&textwidth == "72" ? "100" : "80")) + execute "set colorcolumn=" . (&textwidth + 1) echo "tw=" . &textwidth . " & cc=" . &colorcolumn endfunction @@ -242,6 +242,9 @@ if has('autocmd') autocmd BufRead,BufNewFile *.xml set et sw=2 autocmd BufRead,BufNewFile *.yaml set et sw=2 autocmd BufRead,BufNewFile *.yml set et sw=2 + + " Set colorcolumn after the file has been loaded. + autocmd VimEnter * execute "set colorcolumn=" . (&textwidth + 1) endif if has('clipboard')