0

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>
Willis
  • 3
  • 2
  • 1
    You don't source ftplugins either manually or programatically: they are sourced by Vim when it detects the associated filetype. Also, you didn't show what's in that ftplugin or even say what filetype it is supposed to cover. Please replace the excuses in your question with more information. – romainl Feb 20 '14 at 22:14
  • romainl thanks for your response, what excuses should I replace? I could add the filetype is c code. using the standard c filetype that is included with vim... last changed 2007 Sep 25. does that help? – Willis Feb 21 '14 at 15:40
  • "I sincerely apologize in advance" and friends. – romainl Feb 21 '14 at 15:49
  • Sourcing your `~/.vimrc` shouldn't put you in that situation. What is the output of `:set syntax` after you have sourced your `~/.vimrc`? Just to be sure, is it really `~/.vimrc`? – romainl Feb 21 '14 at 16:07

2 Answers2

1

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.

benjifisher
  • 5,054
  • 16
  • 18
  • after removing this from my vimrc it works, sourcing my .vimrc now does not cause any side effects. I had modified the question to make it more readable at romainl's suggestion. I also modified the question to remove my "potential fix comment" – Willis Feb 21 '14 at 20:38
  • As Jimmy Buffet said, "it could be my fault." That is, I may have misread the question first time through. I thought you liked what was in your vimrc and that is why you were source'ing it over the ftplugin. – benjifisher Feb 21 '14 at 23:00
0

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.

Community
  • 1
  • 1
benjifisher
  • 5,054
  • 16
  • 18
  • I have looked at that ftplugin-overrule before and after looking at it again it seems that this would help me work around the issue instead of addressing it head on. I shouldn't have to source the ftplugin with the lines i commented out. But, looking at the help file in this did get me closer to a solution, I am editing my question now. – Willis Feb 21 '14 at 15:49