I used exvim as session manager, it uses a project file with extension .exvim. The session is auto-loaded when double click the .exvim, and auto-saved on exit. But there're bugs and the dev is inactive for years, now I switch to use vim-session.
I like the '.exvim' idea, I'm trying to implement '.proj' with vim-session in my vimrc:
let g:session_autosave = 'yes' "auto saved
let g:session_autoload = 'no' "load by myself as below
function! s:open_proj_session()
" if the buffer is /a/b/mars.proj, just get the 'mars'
let session_name = fnamemodify(fnamemodify(bufname('%'), ":t"), ':r')
" try to open it first
call xolox#session#open_cmd(session_name, '', 'OpenSession')
" if it's not opened then it's not created, let's create it
let cur_sess = xolox#session#find_current_session()
if cur_sess != session_name
call xolox#session#save_cmd(session_name, '', 'SaveSession')
endif
endfunction
augroup MyProj
autocmd!
autocmd! BufRead,BufNewFile *.proj set filetype=proj "register .proj filetype
autocmd FileType proj nested call s:open_proj_session()
augroup END
Once I open a .proj file, session loaded successfully, but buffers has no filetype
, try to print filetype in some .cpp buffer with :set filetype
, results in: filetype=conf
or filetype=
. And the syntax highlight is not working.
I see the official dev is also inactive for years so I decide to post it here, how to fix this?
Problem Update:
Code updated, add a nested
keyword works. Now only the active buffer not syntax highlighted. Its ``filetype=cpp` is already set, but has no syntax('No Syntax items defined for this buffer'), all other buffer are syntax highlighted, why?
"register .proj filetype
on another line to be sure that it doesn't mess with the autocommand? (Also I thinkfnamemodify(fnamemodify(bufname('%'), ":t"), ':r')
could beexpand('%:t:r')
)expand('%:t:r')
is helpful, and it has the same result if I delete the comments