2016-06-23 33 views
5

Sto usando la seguente funzione da go away and come back script per salvare e caricare sessioni quando esco e avvio vim. In pratica salva tutte le mie impostazioni, i file nei buffer ecc nel file session.vim nella directory in cui ho aperto vim.rendere le impostazioni di sessione salvare la funzione giocare con ultisnips

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() 

Recentemente ho aggiunto il plugin ultisnips.

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

Ora, quando session.vim è creato e apro vim dopo che, ottengo questo Traccia di errore. Questo succede nella modalità insert quando provo anche a modificare.

".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):

Se rimuovo le funzioni per il caricamento delle sessioni, funziona correttamente. Anche qui ci sono tutte le linee in session.vim che ha in sé ultrasta.

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 

Come posso cambiare la mia funzione sessione in modo che i carichi vim ultisnips correttamente?

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

+1

sicuro che questo sarebbe sufficiente, ma prova a caricare le sessioni dopo che i plugin sono stati inizializzati. A seconda del gestore di plugin, fare ciò può essere semplice (come in, basta chiamare la chiamata a 'LoadSession()' alla fine del tuo vimrc), difficile o impossibile. :) –

+0

Bel pensiero Ci provo io –

+0

Ho avuto errori simili in Windows GVim quando ho caricato la sessione tramite la riga di comando con 'gvim -S ' – icc97

risposta

3

Ho fatto una correzione, ma sacrificando alcune funzionalità.

ho rimosso questa linea da sessione di carico

au VimEnter * nested :call LoadSession() 

e ha fatto un mappatura dei tasti per caricare manualmente la sessione

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

Ipotesi a commento di @Sato Katsura sembrano essere valide.
Ora sto studiando se posso andare alla parte automatizzata con questa funzione chiamata quando vengono caricati tutti i plugin.

0

Non so quanta risposta sia, ma forse una spiegazione.

Dal vim-session plugin README

Vim's :mksession command isn't really compatible with plug-ins that create buffers with generated content and because of this the vim-session plug-in includes specific workarounds for a couple of popular plug-ins:

mi è stato fatto presso il plugin vim-sessione da questa più generale SO question on plugin issues with sessions.

ora sono in realtà abbastanza sicuro che ho una correzione, se si utilizza obsession.vim plug-in di Tim Pope, allora il file Session.vim che viene creato può essere caricato nel solito modo sia attraverso -S Session.vim o source Session.vim e UltiSnips funziona di nuovo.

Nel readme c'è questa una linea, il che potrebbe spiegare la differenza (ho aggiunto il bit tra parentesi quadre, come è un po 'fuori contesto qui):

  • [When saving the session] Don't capture options and maps. Options are sometimes mutilated and maps just interfere with updating plugins.
Non
Problemi correlati