4

I'm trying to use :mkview with 'viewdir'.

I set 'viewdir' as the help page said:

set viewdir='C:/Users/MyPC/vimfiles/view'

and made sure that C:/Users/MyPc/vimfiles/view exists, but I still get error messages when I use :mkview:

E739: Cannot create directory: 'C:/Users/MyPc/vimfiles/view'
E190: Cannot open "'C:/Users/MyPc/vimfiles/view'\~=+vimfiles=+view=+vi=" for writing.

How can I use 'viewdir' with :mkview?

4
  • 3
    Don't use quotes around the file name. Commented Aug 27, 2021 at 9:24
  • 2
    Please do not post images of text. Instead, please edit and provide the actual content you want to be viewed.
    – D. Ben Knoble
    Commented Aug 27, 2021 at 11:46
  • 1
    Thanks @JürgenKrämer I removed the quotes and it worked
    – Pham Hung
    Commented Aug 28, 2021 at 0:44
  • @PhamHung you should post and accept an informative self-answer to help others who might benefit from your solution. Commented Sep 7, 2021 at 17:18

2 Answers 2

3

My problem here is caused by my single quote in viewdir

So I removed it and it's ok.

1

My problem was that set viewdir cannot be a list, like backupdir, directory, undodir all can.

" apply same list pattern as I use for other *dir options
set viewdir^=~/myViewDir/ " fails, because its a string. results in: 
                          " `~/myViewDir/home/user/.vim/view` ... that is,
                          " new path prefixing old path.

" override default with my choice, without fallback
set viewdir=~/myViewDir/ " works

The upside is that viewdir creates its own dir if missing, unlike some of the other options. So a fallback is less important there. (tested on vim9)

4
  • 2
    ^= concatenates strings in non-list values.
    – D. Ben Knoble
    Commented May 17 at 0:16
  • @D.BenKnoble correct. those vars are all "string", but for backupdir default is ".,~/tmp,~/" and the help text calls it a "List". for viewdir it calls it a "Name".
    – gcb
    Commented May 17 at 1:17
  • Let me be more explicit: :help :set^= says "Multiply the {value} to a number option, or prepend the {value} to a string option. When the option is a comma-separated list, a comma is added, unless the value was empty." So my point was that your inline comment "joins everything if you treat it as a list" is (pedantically) incorrect.
    – D. Ben Knoble
    Commented May 17 at 12:59
  • @D.BenKnoble thanks! A list in vim is an actual list... I try to avoid anything complex in vimscript. since I always saw the list represented as a string, I assumed vim treated strings with commas as list :)
    – gcb
    Commented May 17 at 17:13

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.