I want to run a command when I change the textwidth. I have tried autocmd CmdlineLeave * call Myfunction()

When I do :set tw=40, the function is called before tw is changed.

What is the best way to do this ?

1 Answer 1


There's OptionSet autocommand. For example,

augroup test | au!
    autocmd OptionSet textwidth call NewTextWidth(v:option_type, v:option_new)
augroup end

function! NewTextWidth(type, value)
    echom 'set' a:type 'textwidth' a:value
  • Thanks, this is exactly what I need
    – Ôrel
    Apr 14, 2020 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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