vim filetype plugin conflict with session

做~自己de王妃 提交于 2020-01-16 01:02:47

问题


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.

  • :mksession!
  • :wviminfo viminfo
  • :qa

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.


回答1:


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'




回答2:


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



来源:https://stackoverflow.com/questions/34115908/vim-filetype-plugin-conflict-with-session

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!