2

I'm using Neovim 0.3.7. I have a default session file that loads up a number of files I'm working on at the moment. To save and load the sessions I have the following custom commands defined:

let sessionlocation = maindir.'/basetest.vim'
exe 'command Sdfs mks' sessionlocation
exe 'command Ldfs source' sessionlocation

This worked fine when I first saved the session. But now I have closed some tabs and opened some new ones and I want the current file layout to be the default session. When I try to run :Sdfs I get the error message:

E189 "..." exists (add ! to overwrite)

where ... is the session file directory. That makes sense. But when I run :Sdfs! I get another error message:

E447: No ! allowed

How can I allow ! in my custom command so that I can overwrite my default session file?

3
  • Note that I am running Windows 10. I have tested this behaviour with nvim opened as administrator and the behaviour persists.
    – Moustache
    Commented Jul 10, 2019 at 23:52
  • 1
    exe 'command! Sdfs mks' sessionlocation exe 'command! Ldfs source' sessionlocation
    – Alex Kroll
    Commented Jul 10, 2019 at 23:55
  • Thanks I tried the modification but unfortunately the problem persists.
    – Moustache
    Commented Jul 11, 2019 at 0:02

1 Answer 1

4

E189 "..." exists (add ! to overwrite) is reported by :h :mksession if session file exists , add ! after mks should fix that:

exe 'command Sdfs mks!' sessionlocation

If you want to pass ! from Sdfs to mks, use this:

exe 'command -bang Sdfs mks<bang>' sessionlocation

:h :command-bang
:h <bang>

1
  • Thanks, the first one I really should have thought of, the second one is completely new to me and very interesting. I confirmed both work on my system and went with the latter solution in the end as it seems like good practice to have to explicitly overwrite.
    – Moustache
    Commented Jul 11, 2019 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.