I would like to have a marker at column 80 in VIM, but only in file like *.cpp, *.h. but not in *.txt
For now I have this in my .vimrc
set cc=120
Cheers
Solution:
autocmd FileType cpp,c,cxx,h,hpp,python,sh setlocal cc=120
Vim doesn't directly use the file extension, it has an indirection called filetype
, which is then used for syntax highlighting and specific settings.
Put your :set
command (as :setlocal
, so that it only affects the current buffer [1]) in a new file ~/.vim/after/ftplugin/cpp.vim
. (You could also use :autocmd FileType cpp setlocal cc=120
directly in your .vimrc
, but the separation is cleaner once you do a lot of that customization.)
[1] Note that 'colorcolumn'
is window-local, not buffer-local, so the approach isn't perfect, but usually good enough. It can be perfected with additional BufWinEnter/Leave
autocmds.
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