0

I want to mark the textwidthth column using colorcolumn and have used the following (since I have slightly different textwidths for different files)

au FileType py set textwidth=80 (say line 98)
au FileType c set textwidth=79 (say line 99)
let &colorcolumn=&textwidth (say line 100)

As you can see I have made sure that textwidth has been defined before colorcolumn is being set. I have also checked the output of the following commands (inside a .c file)

:verbose set textwidth?
textwidth=79
    Last set from my_vimrc line 99
:verbose set colorcolumn?
colorcolumn=0
    Last set from my_vimrc line 100

As you can see the value is 0 even though no other file is changing the value. Any reason why this might be happening ?

On a related note, vim is not breaking lines at 79 characters within .c file even though textwidth is set to 79. Could this also be a part of the problem ??

5
  • formatoptions=ql
    – First User
    Mar 17 at 15:24
  • 1
    Without t (or c for comments only) the auto-wrapping is disabled. (Just to address your "on a related note" part.) Most people want this for coding, I think.
    – B Layer
    Mar 17 at 15:25
  • should I add a fo+=t then on its own ? or should I write it as an autocommand for C files only ?
    – First User
    Mar 17 at 15:28
  • 1
    Well, like I just added in my edit to my comment, it's off deliberately since auto-wrapping is kinda bad for coding. But if you want it on then it depends on if you want it just for C in which case autocommand (or, maybe better, adding an "after" file) is fine. You'll have to see if it's on/off for other file types to your liking.
    – B Layer
    Mar 17 at 15:29
  • 1
    Sure. Regarding colorcoumn...surely due to timings of autocommands (they are fired after initial vimrc processing). Easy verification/workaround: set colorcolumn in the autocommands
    – B Layer
    Mar 17 at 15:35
1

What you are expected to do: set cc=+0

Why your stuff doesn't work: because ordinary :set is executed once, while :autocmd FileType is executed upon each FileType event.

Note: your autocmd has all possible "novice bugs" in it. Before doing any stuff with auto-commands you're strongly advised to learn the docs. In particular, always use augroup; prefer after-directory over manual autocmd etc.

1
  • thanks. I had removed the augroups for the sake of brevity.
    – First User
    Mar 17 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.