Wikia

Vim Tips Wiki

Changes: Save settings between Vim sessions

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 12: Line 12:
 
|category2=
 
|category2=
 
}}
 
}}
I often use vimsession-files to save set of options, buffers, etc, that are specific for each job (see {{help|:mksession}}). To save some additional settings, which are not saved in vimsession (like commands, autocommands, functions), I use vimsession-extra file. When I want to modify that extra-file, I had to type something like :new <c-r>=v:this_session<cr>, then edit commandline to get proper extra-file name and edit it. It was tiring. So I wrote this plugin:
+
I often use vimsession-files to save set of options, buffers, etc, that are specific for each job (see {{help|:mksession}}). To save some additional settings, which are not saved in vimsession (like commands, autocommands, functions), I use vimsession-extra file. When I want to modify that extra-file, I had to type something like :new <c-r>=v:this_session<CR>, then edit commandline to get proper extra-file name and edit it. It was tiring. So I wrote this plugin:
   
 
<pre>
 
<pre>
Line 18: Line 18:
 
function! SessSave()
 
function! SessSave()
 
if v:this_session==""
 
if v:this_session==""
call confirm("There is no loaded session","&amp;Ok",1)
+
call confirm("There is no loaded session","&Ok",1)
 
return
 
return
 
endif
 
endif
if 2==confirm('Save session '.v:this_session.'?',"&amp;No\n&amp;Yes",1)
+
if 2==confirm('Save session '.v:this_session.'?',"&No\n&Yes",1)
 
exe 'mksession! '.v:this_session
 
exe 'mksession! '.v:this_session
call confirm('Session '.v:this_session.' saved.','&amp;Ok',1)
+
call confirm('Session '.v:this_session.' saved.','&Ok',1)
 
endif
 
endif
 
endfunction
 
endfunction
Line 29: Line 29:
 
function! SessExtraFname()
 
function! SessExtraFname()
 
if v:this_session==""
 
if v:this_session==""
call confirm("There is no loaded session","&amp;Ok",1)
+
call confirm("There is no loaded session","&Ok",1)
 
return ''
 
return ''
 
endif
 
endif
Line 41: Line 41:
   
 
<pre>
 
<pre>
nmap &lt;c-z&gt;l :SessSave&lt;cr&gt;
+
nmap <c-z>l :SessSave<CR>
 
</pre>
 
</pre>
   

Latest revision as of 09:34, September 29, 2008

Tip 863 Printable Monobook Previous Next

created January 31, 2005 · complexity basic · author Ivan Tishchenko · version 6.0


I often use vimsession-files to save set of options, buffers, etc, that are specific for each job (see :help :mksession). To save some additional settings, which are not saved in vimsession (like commands, autocommands, functions), I use vimsession-extra file. When I want to modify that extra-file, I had to type something like :new <c-r>=v:this_session<CR>, then edit commandline to get proper extra-file name and edit it. It was tiring. So I wrote this plugin:

command! -bar SessSave call SessSave()
function! SessSave()
  if v:this_session==""
    call confirm("There is no loaded session","&Ok",1)
    return
  endif
  if 2==confirm('Save session '.v:this_session.'?',"&No\n&Yes",1)
    exe 'mksession! '.v:this_session
    call confirm('Session '.v:this_session.' saved.','&Ok',1)
  endif
endfunction

function! SessExtraFname()
  if v:this_session==""
    call confirm("There is no loaded session","&Ok",1)
    return ''
  endif
  return substitute(v:this_session,'\.[^.]*$','x.vim','')
endfunction
command! -bar SessExtraOpen exe 'new '.SessExtraFname()
command! -bar SessExtraReread exe 'source '.SessExtraFname()

I also put following mapping there:

nmap <c-z>l :SessSave<CR>

Of course, you can change lhs to whatever you want, or add some extra mappings, for example for SessExtraOpen or SessExtraReread.

CommentsEdit

See also VimTip238.


Taking in account that wonderful VimTip879 we may change definition of SessExtraOpen so that it sets up autocommand which will reload our extra-file each time we modify it:

command! -bar SessExtraOpen call SessExtraOpen()
function! SessExtraOpen()
  exe 'new '.SessExtraFname()
  augroup SessAuGroup
    autocmd!
    let fn=SessExtraFname()
    if has("win32")
      let fn=substitute(fn,'\\\ze\S','/','g')
    endif
    execute "autocmd BufLeave ".fn." source ".fn
  augroup END
endfunction

Around Wikia's network

Random Wiki