2

Say I am writing a plugin and constantly editing scripts in ftplugin. How do I efficiently test the changes? I can't simply source the editted file because they are filetype-specific. For example, if there is a line

set buftype=nofile

in the script, and I source it, then whatever buffer I'm in will no longer be writable into a file...

I can open another vim instance to test the change, but that is not very efficient because I have to reopen one whenever I make changes to the ftplugin scripts.

1 Answer 1

1

Add this to your script:

let b:undo_ftplugin='setlocal buftype='

When the FileType autocmd is fired, that variable will execute. To trigger the autocmd, you could run :set ft=whatever to reload the ftplugin and syntax scripts.

While I'm tweaking an ftplugin, I usually don't want to save the changes made in a buffer during testing. So, I just use :e! to reload the buffer since :edit effectively sets the detected filetype.

You can read more about this in :h undo_ftplugin. To see exactly how this works, you can look at the script that loads your ftplugin script:

:e $VIMRUNTIME/ftplugin.vim

Your Answer

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

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