Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make session settings saving function play nice with ultisnips

Tags:

vim

macos

session

I'm using the following function from go away and come back script to save and load sessions when I quit and start vim. It basically saves all my settings, files in buffers etc in session.vim file in the directory where I opened vim.

function! MakeSession()
  let b:sessiondir = $HOME . "/.vim/sessions" . getcwd()
  if (filewritable(b:sessiondir) != 2)
    exe 'silent !mkdir -p ' b:sessiondir
    redraw!
  endif
  let b:filename = b:sessiondir . '/session.vim'
  exe "mksession! " . b:filename
endfunction

function! LoadSession()
  let b:sessiondir = $HOME . "/.vim/sessions" . getcwd()
  let b:sessionfile = b:sessiondir . "/session.vim"
  if (filereadable(b:sessionfile))
    exe 'source ' b:sessionfile
  else
    echo "No session loaded."
  endif
endfunction
au VimEnter * nested :call LoadSession()
au VimLeave * :call MakeSession()

Recently I added ultisnips plugin.

"Snippet engine
Plugin 'SirVer/ultisnips'
"Snippets are separated from the engine. Add this if you want them:
Plugin 'honza/vim-snippets'

Now when session.vim is created and I open vim after that, I get this error trace. This happens in insert mode when I try to edit also.

".vim/vimrc" 287L, 9566C Error detected while processing /Users/sudobangbang/.vim/bundle/ultisnips/autoload/UltiSnips.vim: line 15: Traceback (most recent call last):

Error detected while processing /Users/sudobangbang/.vim/bundle/ultisnips/autoload/UltiSnips.vim: line 15: File "", line 1, in Press ENTER or type command to continue Error detected while processing /Users/sudobangbang/.vim/bundle/ultisnips/autoload/UltiSnips.vim: line 15: ImportError: No module named UltiSnips

Error detected while processing function UltiSnips#FileTypeChanged: line 1: Traceback (most recent call last): Error detected while processing function UltiSnips#FileTypeChanged: line 1: NameError: name 'UltiSnips_Manager' is not defined

Error detected while processing function UltiSnips#TrackChange: line 1: Traceback (most recent call last):

If I remove functions for loading sessions, It works fine. Also here are all the lines in session.vim which has ultisnips in it.

inoremap <silent> <C-Tab> ^V^R=UltiSnips#ListSnippets()^V^M
xnoremap <silent> ^V   :call UltiSnips#SaveLastVisualSelection()^V^Mgvs
snoremap <silent> ^V   ^V^[:call UltiSnips#ExpandSnippet()^V^M
snoremap <silent> <C-Tab> ^V^[:call UltiSnips#ListSnippets()^V^M


set runtimepath=~/.vim,~/.vim/bundle/Vundle.vim,~/.vim/bundle/syntastic,~/.vim/bundle/nerdtree,~/.vim/bundle/vim-colorschemes,~/.vim/bundle/YouCompleteMe,~/.vim/bundle/supertab,~/.vim/bundle/ultisnips    ,~/.vim/bundle/vim-snippets,~/.vim/bundle/ctrlp.vim,~/.vim/bundle/vim-go,~/.vim/bundle/vim-commentary,~/.vim/bundle/vim-surround,~/.vim/bundle/vim-fugitive,~/.vim/bundle/vim-unimpaired,~/.vim/bundle/v    im-repeat,~/.vim/bundle/vim-airline,~/.vim/bundle/vim-airline-themes,~/.vim/bundle/gundo.vim,~/.vim/bundle/emmet-vim,~/.vim/bundle/html5.vim,~/.vim/bundle/vim-css-color,~/.vim/bundle/python-mode,~/.vi    m/bundle/vim-flake8,~/.vim/bundle/vim-ruby,~/.vim/bundle/vim-endwise,~/.vim/bundle/vim-rails,~/.vim/bundle/vim-bundler,~/.vim/bundle/vim-rake,~/.vim/bundle/vim-ruby-refactoring,~/.vim/bundle/apidock.v    im,~/.vim/bundle/blockle.vim,~/.vim/bundle/vim-rspec,~/.vim/bundle/javascript-libraries-syntax.vim,~/.vim/bundle/tern_for_vim,~/.vim/bundle/vim-javascript,/usr/local/share/vim/vimfiles,/usr/local/shar    e/vim/vim74,/usr/local/share/vim/vimfil

How can I change my session function so that vim loads ultisnips correctly?

vim --version

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 4 2016 11:48:12)
MacOS X (unix) version
Included patches: 1-1864
Compiled by Homebrew

like image 728
sudo bangbang Avatar asked Oct 19 '22 07:10

sudo bangbang


1 Answers

I made a fix but while sacrificing some functionality.

I removed this line from session loading

au VimEnter * nested :call LoadSession()

and made a key mapping to manually load the session

map <leader>l :call LoadSession()<CR>

Hypothesis in @Sato Katsura's comment seem to be valid.
Now I'm researching if I can go to automated part with this getting this function called when all plugins are loaded.

like image 175
sudo bangbang Avatar answered Nov 02 '22 10:11

sudo bangbang