lo__tp
lo__tp

Reputation: 365

vim filetype plugin conflict with session

Problem

When I restore from a session, It'll be impossible for to load my filetype plugin.

For example, I have an arduino filetype plugin of ~/.vim/ftplugin/arduino.vim, and the content is like this.

SyntasticToggleMode
call feedkeys("\<CR>")
nnoremap <leader>s :w<cr>:ArduinoVerify<cr>
nnoremap M :ArduinoUpload<cr>

I create an arduino file named test.ino to do some coding. Every thing seems pretty smooth. The filetype plugin is loaded properly.

Then I close vim with the following commands.

Now there is a session file named Session.vim. Then I open vim again, and it automatically load the session because I have something like this in my .vimrc.

filetype indent plugin on 
if filereadable("Session.vim")
    source Session.vim          
endif         
if filereadable("viminfo")
    rviminfo viminfo
endif      

Now something went wrong, the key mapping in my arduino filetype plugin is not working. Also it prints some error message like this. Error detected while processing /home/lotp/.vim/ftplugin/arduino.vim: line 1: E492: Not an editor command: SyntasticToggleMode"sketch_dec06a.ino" "sketch_dec06a.ino" 12L, 150C E492: Not an editor command: SyntasticToggleMode

IndeedSyntasticToggleMode is a valid vim command belonging to a vim plugin named syntastic.

Question

Is there a solution to solve this problem? By this I mean using the session and filetype plugin feather simultaneously.

Upvotes: 1

Views: 150

Answers (2)

lo__tp
lo__tp

Reputation: 365

Finally I work around this problem by using an vim plugin.

That's somekind of improved version of the built in vim session system

It's called vim-session

Upvotes: 1

yolenoyer
yolenoyer

Reputation: 9465

A partial answer:

The plugins are not loaded directly in .vimrc if you use a plugin manager. Their paths are just appended to 'runtimepath', and they are sourced later in the initialisation process.

You can try to add (i.e. in .vimrc) your own custom path to runtimepath, AFTER the end of the plugin initialisation. (i.e., for Vundle, after this line: call vundle#end()) Then add a vim file in your_custom_path/plugin where you put your code to source the session file.

I didn't check all the infos I gave, so sorry for mistakes, but hope it gives you some ideas.

See :h startup, :h 'runtimepath'

Upvotes: 1

Related Questions