Frage

If I open a c file and my buffer is using the "c.vim" ftplugin, then open/edit/source my .vimrc, I lose the functionality of the "c.vim" ftplugin.

what would be the best way to automatically reload the ftplugin?

Here is an example:

buffer state for c file before sourcing my .vimrc:

// This line has an existing comment.
// I used 'o' while on the above line to continue that comment.
// Awesome, after pressing return I am still commenting.

buffer state for c file after sourcing my .vimrc:

// This line has an existing comment.
I used 'o' while on the above line to try and continue that comment.
After pressing return it is obvious the ftplugin for this filetype is not active.

This is my .vimrc in case it is somehow causing the issue:

set nocompatible
set backspace=indent,eol,start
filetype plugin indent on
syntax on
set hls
nnoremap <leader>ev :split $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
War es hilfreich?

Lösung

Either I misread your question when I gave my first answer, or your editing changed the question drastically.

Short answer: remove the line

:set nocompatible

from your vimrc file.

Here are a few relevant lines from :help 'compatible':

This is a special kind of option, because when it's set or reset,
other options are also changed as a side effect.  ...
When a |vimrc| or |gvimrc| file is found while Vim is starting up,
this option is switched off, and all options that have not been
modified will be set to the Vim defaults.  ...

That means that :set nocompatible at the start of a vimrc file is redundant. Also, the bit about "all options that have not been set" only applies to the automatic effect of finding a vimrc file, not to when you set or reset the option.

As I said in my previous answer, the 'formatoptions' option is the one that is bothering you; this is one of the many options affected by the 'compatible' option.

Andere Tipps

You have to do two things:

  1. Find the option that matters.
  2. Override the ftplugin.

I recently gave advice on #1 on SuperUser: https://superuser.com/questions/719329/automatic-indentation-with-macvim/719411#719411 In your case, the option you want to change is 'formatoptions' (short form 'fo').

For #2, see :help ftplugin-overrule. I suggest using the third option described there.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top