mksession doesn't work as expected

1 view
Skip to first unread message

Nicolas Aggelidis

unread,
Dec 17, 2008, 5:44:42 AM12/17/08
to vim...@googlegroups.com
hi to all the list,

i have the following problem , and once again i need your help.

i have the following configuration for sessions:

set sessionoptions+=resize
set sessionoptions+=slash
set sessionoptions+=unix
set sessionoptions+=winpos

to save a session i do: mksession ~/sessions/session_name.vim
and to load a session i do: source ~/sessions/session_name.vim

The problem is observable with files on different folders, for example if i have

~/folder/file1
~/folder/file2
~/folder/folder2/file3

I open them {in this orded if it matters} on different tabs and then i issue a
mksession ~/sessions/sample.vim

then on a different gvim i do

source ~/sessions/sample.vim

the result is that gvim opens all files on different tabs, *but* the
file3 is blank! {file3 is the file on the different directory than the
other 2.


the sessions work great if i load gvim with -u NONE and then save the
session option...
and then open them from a gvim -u NONE.

sessions fail if i save from a gvim -u NONE but try to open them from
a "normal" gvim..


any idea why this happens? maybe some other setting is causing it?{but which?}

Cory Echols

unread,
Dec 17, 2008, 7:27:38 AM12/17/08
to vim...@googlegroups.com

Likely, you have 'autochdir' set somewhere in your startup files. You
can find out which file by executing ":verbose set autochdir". That
setting used to cause problems for me when reloading sessions. I used
to work around this problem with an autocommand similar to this:

autocmd BufWinEnter * exe 'lcd ' . expand('%:h')

I eventually quit using this for reasons I can't recall. It may have
problems as well.

fritzophrenic

unread,
Dec 17, 2008, 10:23:14 AM12/17/08
to vim_use


On Dec 17, 6:27 am, "Cory Echols" <c...@sixtimesnine.org> wrote:
>
> Likely, you have 'autochdir' set somewhere in your startup files.  You
> can find out which file by executing ":verbose set autochdir".  That
> setting used to cause problems for me when reloading sessions.

If 'autochdir' is your problem (I suspect it is) then it is simple to
fix.

Before making a session, turn off autochdir (otherwise the session
file will restore this option).

Before loading a session, turn off autochdir.

After loading the session, if desired, you can turn autochdir back on.

This is the procedure I use whenever I feel the need to make a session
file (which I avoided for a long time because I had similar problems
to yours).

Tony Mechelynck

unread,
Dec 18, 2008, 12:19:27 AM12/18/08
to vim...@googlegroups.com
On 17/12/08 13:27, Cory Echols wrote:
[...]

> Likely, you have 'autochdir' set somewhere in your startup files. You
> can find out which file by executing ":verbose set autochdir". That
> setting used to cause problems for me when reloading sessions. I used
> to work around this problem with an autocommand similar to this:
[...]

'autochdir' is a Boolean option. Don't use

:verbose set autochdir

because it would _set_ the option and say nothing. Instead, use

:verbose set autochdir?

_with_ a question mark, to see the current value and where it was set.


Best regards,
Tony.
--
GUARD #1: Where'd you get the coconut?
ARTHUR: We found them.
GUARD #1: Found them? In Mercea? The coconut's tropical!
ARTHUR: What do you mean?
GUARD #1: Well, this is a temperate zone.
The Quest for the Holy Grail (Monty
Python)

Nicolas Aggelidis

unread,
Dec 18, 2008, 7:03:37 AM12/18/08
to vim...@googlegroups.com
Thank you guys for your answers! i think the problem is solved!

amenu <silent>&simple.Enable\ autochdir :set autochdir <cr>
amenu <silent>&simple.Disable\ autochdir :set noautochdir <cr>
amenu <silent>&simple.autochdir\ Status :verbose set autochdir? <cr>


i have added a menu so that i can disable and enable autochdir with buttons.

i have 2 questions concerning the menu:

* is there any way to make an entry toggle-autochdir that will toggle
the the autochdir option?

*how can i present the state of autochdir in the status line?

currently i have the following:

set statusline=[FORMAT=%{&ff}]\ [TYPE=%Y]\
[Line,Column]=[%04l,%04v][%p%%]\ [%L\ Lines]\ [FILE=%F%m%r%h%w]

thanks in advance for your answers,

nicolas

Nicolas Aggelidis

unread,
Dec 18, 2008, 7:10:57 AM12/18/08
to vim...@googlegroups.com
one more thing conserning sessions, i want to keep all the session
files in a specific folder i.e. ~/sessions/session_name.vim

is there any way to make vim save by default all sessions in the
specific folder and load from this specific folder.
so that i can do the following:
mksession session_name.vim
source session_name.vim

if this is not possible, can i define a sort of variable so that i can
something like this:

mksession $SESSION_DIR/session_name.vim
source $SESSION_DIR/session_name.vim

-nicolas

Cory Echols

unread,
Dec 18, 2008, 7:29:51 AM12/18/08
to vim...@googlegroups.com

The simplest way to do this is probably to write your own commands to
load and save the sessions. As a bonus, these commands could do the
toggling of autochdir for you. My preference for any remotely complex
command is to write a function and bind the command to the function:

let g:my_session_dir = '~/.vim/sessions'
function! MakeSession(sessionName)
set noautochdir
" I'd love to know if there's a way to avoid :exe here.
exe ':mksession! ' . g:my_session_dir . '/' . a:sessionName
set autochdir
endfunction

command! -nargs=1 MKSession :call MakeSession(<f-args>)

The above is barely tested. I'll leave "loadession" as an exercise
for the reader. Relevant help sections in the manual are:

:he user-commands
:he 40.2
:he user-functions
:he 41.7

Tony Mechelynck

unread,
Dec 18, 2008, 6:42:14 PM12/18/08
to vim...@googlegroups.com
On 18/12/08 13:03, Nicolas Aggelidis wrote:
> Thank you guys for your answers! i think the problem is solved!
>
> amenu<silent>&simple.Enable\ autochdir :set autochdir<cr>
> amenu<silent>&simple.Disable\ autochdir :set noautochdir<cr>
> amenu<silent>&simple.autochdir\ Status :verbose set autochdir?<cr>
>
>
> i have added a menu so that i can disable and enable autochdir with buttons.
>
> i have 2 questions concerning the menu:
>
> * is there any way to make an entry toggle-autochdir that will toggle
> the the autochdir option?

amenu <silent> &simple.Toggle\ autochdir :set autochdir!<CR>

(":set invautochdir" would also work, and you can shorten 'autochdir' to
'acd'

>
> *how can i present the state of autochdir in the status line?
>
> currently i have the following:
>
> set statusline=[FORMAT=%{&ff}]\ [TYPE=%Y]\
> [Line,Column]=[%04l,%04v][%p%%]\ [%L\ Lines]\ [FILE=%F%m%r%h%w]

e.g. add somewhere in your custom status line

%{&acd?'[acd]':''}

BTW your statusline looks wasteful of screen space. I use

if has("statusline")
set statusline=%<%f\ %h%m%r%=%k[%{(&fenc\ ==\
\"\"?&enc:&fenc).(&bomb?\",BOM\":\"\")}][U+%04B]\ %-12.(%l,%c%V%)\ %P
endif


>
> thanks in advance for your answers,
>
> nicolas

Best regards,
Tony.
--
Death is only a state of mind.

Only it doesn't leave you much time to think about anything else.

Nicolas Aggelidis

unread,
Dec 19, 2008, 10:22:34 AM12/19/08
to vim...@googlegroups.com
Thanks for all your help guys,

Tony i think i have some questions regarding the use of the
statusline....i will search a bit a more and then i will come back and
ask!


thanks
-nicolas

Reply all
Reply to author
Forward
0 new messages