try adding either
syntax on
or (near the top)
runtime vimrc_example.vim
(it's not necessary to use both) to your vimrc (or make one if you don't
yet have one, using
:e ~/_vimrc
inside Vim).
Best regards,
Tony.
--
Dimensions will always be expressed in the least usable term.
Velocity, for example, will be expressed in furlongs per fortnight.
Whell, how exactly do you restore your sessions? When I used "gvim -S"
with :mksession it did read my vimrc. (Now I use a handtyped Session.vim
which does exactly what I want and not all the :mksession hocus-pocus.)
Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
58. You turn on your computer and turn off your wife.
If you're using gvim, try making a desktop icon which would call it as
gvim -S d:\Session.vim
If you're using Console Vim, try making... well, I was about to say a
shell alias, but maybe these don't exist on Windows. You can make a bat
script, however, named maybe svim.bat, which would call Vim as
vim -S d:\Session.vim
In all cases, you may need to call vim, svim or gvim with a full path if
its executable's directory is not in your PATH environment variable.
see :help -S
Best regards,
Tony.
--
"When are you BUTTHEADS gonna learn that you can't oppose Gestapo
tactics *with* Gestapo tactics?"
-- Reuben Flagg
> When I start VIM it shows my tabs and reloads my buffers from the last
> time.
>
> I use a session to do this.
>
> au VimEnter * exe "so d:\\Session.vim"
> au VimLeave * exe "'mksession! d:\\Session.vim'"
You have made just the same mistake as me some time ago: all filetype-related
files are loaded using an autocommand, but by default no autocommands are
allowed when you are executing an autocommand, so you should add `nested' just
after the pattern. By the way, why do you use `exe'? The following works as
well:
augroup SaveRestoreSessions
autocmd!
autocmd VimEnter * nested source D:\session.vim
autocmd VimLeave * nested mksession! D:\session.vim
augroup END
See `:h autocmd-nested' for more details.
Original message:
> Please let me ask you one more question...
> How do you close this session and reopens a custom one (happens once
> in a while)?
I don't use one continious vim session and don't load any sessions at
vim startup (the `just the same error' meant that I used an autocommand
in a similar way and got the same error, not that I used the same code).
Instead I create a new session file almost each time when vim exits
and load one of created sessions at vim startup:
1. due to virtual desktops I almost never close any of my projects' windows,
2. I use vim to quickly edit something from command-line, loading any sessions
will discard the most significant part of vim invocation arguments
for this use-case.
Saving session at vim exit is for the case when I have to reload vim
(mostly plugin or kernel updates).
Here is my code:
"▶2 mksession
if has('mksession')
function s:InitSes()
let sesdir=expand('~/.vimsessions')
if !isdirectory(sesdir)
call mkdir(expand(sesdir), "", 0700)
endif
let sesfile=os#JoinPath(sesdir, '.sessions.lst')
let sessions=[]
if filereadable(sesfile)
let sessions+=readfile(sesfile, 'b')
while !empty(sessions) && empty(sessions[-1])
call remove(sessions, -1)
endwhile
endif
let sessplitted=map(copy(sessions),
\'split(v:val, ''\v%(\\@<!%(\\\\)*)@<=,'')')
let sesdirs=map(copy(sessplitted), '((empty(v:val))?(""):(v:val[0]))')
let sesfiles=map(copy(sessplitted), '((empty(v:val))?([]):(v:val[1:]))')
execute "cd ".fnameescape(resolve(fnamemodify('.', ':p')))
let curdir=escape(fnamemodify('.', ':p'), ',\')
return [sesdir, sesfile, sessions, sesdirs, sesfiles, curdir]
endfunction
let s:_functions['s:InitSes']=function('s:InitSes')
function s:MakeSession()
let [sesdir, sesfile, sessions, sesdirs, sesfiles, curdir]=s:InitSes()
let files=sort(map(filter(map(filter(range(1, bufnr('$')),
\ 'getbufvar(v:val, "&bt")!=#"help"'),
\ 'bufname(v:val)'),
\ 'filereadable(v:val)'),
\ 'escape(fnamemodify(resolve(fnamemodify(v:val, ":p")),
":~:."), ",\\")'))
if empty(files)
return
endif
let sesstr=join([curdir]+files, ',')
let sindex=index(sessions, sesstr)
if sindex==-1
let sindex=index(sessions, '')
endif
if sindex==-1
let sesname=os#JoinPath(sesdir, len(sesdirs).'.vim')
call add(sessions, sesstr)
else
let sesname=os#JoinPath(sesdir, sindex.'.vim')
let sessions[sindex]=sesstr
endif
execute 'mksession! '.fnameescape(sesname)
call writefile(sessions, sesfile, 'b')
endfunction
let s:_functions['s:MakeSession']=function('s:MakeSession')
function s:LoadSession(bang, ...)
let [sesdir, sesfile, sessions, sesdirs, sesfiles, curdir]=s:InitSes()
if a:0 && string(+a:1)==#a:1 && a:1<len(sessions) &&
\!empty(sessions[a:1])
let dirsessions=[[+a:1, sesdirs[a:1], sessions[a:1]]]
else
let dirsessions=filter(map(copy(sesdirs),
\ '[v:key, v:val, sessions[v:key]]'),
\ 'v:val[1]==#curdir'.
\ ((a:0)?(' && v:val[2]=~?a:1'):('')))
endif
if len(dirsessions)==1 || (!empty(dirsessions) && a:bang)
let sesid=dirsessions[0][0]
let sesname=os#JoinPath(sesdir, sesid.'.vim')
execute 'source '.fnameescape(sesname)
call delete(sesname)
if sesid==(len(sessions)-1)
call remove(sessions, -1)
else
let sessions[sesid]=""
endif
call writefile(sessions, sesfile, 'b')
endif
endfunction
let s:_functions['s:LoadSession']=function('s:LoadSession')
function s:PrintSessions()
let [sesdir, sesfile, sessions, sesdirs, sesfiles, curdir]=s:InitSes()
call map(sessions,
\'printf("%'.len(len(sessions)-1).'u %s", v:key, v:val)')
echo join(sessions, "\n")
endfunction
let s:_functions['s:PrintSessions']=function('s:PrintSessions')
autocmd VimLeavePre * call s:MakeSession()
command -nargs=? -bang LoadSession call s:LoadSession(<bang>0, <q-args>)
command -bar PrintSessions call s:PrintSessions()
let s:_commands+=['LoadSession', 'PrintSessions']
endif
"▲2
I am going to evolve this into plugin sometime.
Original message:
> Still have a little problem.
> I had also a VimLeave argdel command in my _vimrc.
>
> Is this correct?:
>
> augroup SaveRestoreSessions
> autocmd!
> autocmd VimEnter * nested source D:\session.vim
> autocmd VimLeave * nested mksession! D:\session.vim
> autocmd VimLeave * if argc() != 0 | exe 'argdel *'
> augroup END
>
> btw tnx. for your script.
1. Missing endif.
2. You don't need `exe' here.
3. I don't get why do you need this command at all.
> Tnx.. this is what I added:
> autocmd VimLeave * if argc() != 0 | 'argdel *' endif
Reread help. This is false: you should not use strikes around `argdel *' and you
should have bar before `endif' just like you have before `argdel'.
> I noted that (even after a buffer delete :bd) certain buffers do
> remain in "session.vim"
> I had no troubles anymore after removing "argdel *" and troubles again
> after having changed the script as above.
I know this issue. In this case you should have `argdel' before mksession,
I don't get why you have it *after*.
Why not try sending an email to:
<mailto:vim_use+u...@googlegroups.com>
> I found a new way to integrate argdel:
>
> augroup SaveRestoreSessions
> autocmd!
> autocmd VimEnter * nested source $VIM\vimfiles\sessions\Session.vim
> autocmd VimLeave * call MakeSession()
> autocmd VimLeave * nested mksession! $VIM\vimfiles\sessions
> \Session.vim
> augroup END
>
> function! MakeSession()
> if argc() != 0
> execute 'argdel *'
> endif
> endfunction
You are doing a strange things again:
1. You should either rename `MakeSession' to `ClearArgs' (because `MakeSession'
will confuse somebody (maybe even you) who will read you code as it does not
makes any sessions) or, better, move `mksession!' call inside a function.
2. Why are you again writing `execute'?
3. You don't need `nested' for mksession, you need it only for VimEnter.
4. Never write anything user-specific to application folder, it may be purged by
application update, removed by the package manager (if any) or uninstaller, or
you may have to create more then one user on the machine.
> Is this the correct one?
>
> augroup SaveRestoreSessions
> autocmd!
> autocmd VimEnter * nested source D:\Session.vim
> autocmd VimLeave * call ClearArgs()
> autocmd VimLeave * nested mksession! D:\Session.vim
> augroup END
>
> function! ClearArgs()
> if argc() != 0
> argdel *
> endif
> endfunction
Previous variant was also correct (working), but strange. It is better, but why
don't you use this instead:
let sesfile='D:\Session.vim'
augroup SaveRestoreSessions
autocmd!
autocmd VimEnter * nested :source `=sesfile`
autocmd VimLeave * :if argc() | argdel * | endif | mksession! `=sesfile`
augroup END
> Thank you..
> Nice to put the session file path in a variable.
> (The only drawback is that it seems not to be enable to expand
> variables as $HOME and $VIM)
Just use string concatenation (:h expr-.): `$HOME.'\vimsessions\main.vim''
instead of `'$HOME\vimsessions\main.vim''. And don't use $VIM, if your system is
configured properly then you do not have write access to it at all.
> > > > > > > > > > >
Eleven and 306 lines for three usefull :-(
Please cut unusefull citations in this thread.
--
Patrick Texier
> Eleven and 306 lines for three usefull :-(
Heh, with Thunderbird's Quote Colors add-on it looks like really good
art at least :)