Conversation
If the system has XDG basedirs for Vim already, do support them.
$XDG_CONFIG_HOME is supported by Vim itself, other XDG dirs are handled by defaults.vim.
|
I am not sure. How about we either
let xdg_c = exists("$XDG_CONFIG_HOME") ? $XDG_CONFIG_HOME : "$HOME/.config"
let xdg_d = exists("$XDG_DATA_HOME") ? $XDG_DATA_HOME : "$HOME/.local/share/vim"
let xdg_s = exists("$XDG_STATE_HOME") ? $XDG_STATE_HOME : "$HOME/.local/state/vim"
if !isdirectory(xdg_d)
call mkdir(xdg_d, 'p', 0700)
endif
if !isdirectory(xdg_s)
call mkdir(xdg_s, 'p', 0700)
endif
let &packpath = printf("%s,%s,%s/after", xdg_d, &packpath, xdg_d)
let &viminfofile = xdg_s .. "/viminfo"
let &backupdir = xdg_s .. "/backup"
let &viewdir = xdg_s .. "/view"
let &undodir = xdg_s .. "/undo"
" the trailing slash is important
let &directory = xdg_s .. "/swap//" |
I actually targeted system vimrc file. In Fedora, it's
The intention here is to make Vim configure itself for XDG scheme automatically. |
|
As I said, I won't enable this by default (and for some of those configuration changes, like swapfile) this would be backwards incompatible change. If users want this, they have to configure it. It's not that hard. |
|
But the script I suggested checks the presence of |
|
But it doesn't belong into defaults.vim. That would be effective only for some niche use-cases. |
|
Do you know where the system vimrc usually comes from? |
Yes, apparently they maintain their own system vimrc and just pull things there from defaults.vim (I couldn't see the history): So for me, it would be good enough if we just include the code to defaults.vim, probably. |
We could separate the code to |
|
I had a look. Fedora's In any case, if people think such an It should remain an intentional choice by each user whether they want to split their configuration, state, and temporary files across different directory trees. |
|
As I said, the condition we have in the script would already mean we don't enable it by default. But, if you insist - better have something than nothing. |
move XDG code from defaults.vim
chrisbra
left a comment
There was a problem hiding this comment.
There should be at least a few comments, why some of those settings are commented out.
Also to be robust, I think we should make sure that the other XDG directories exist, so there should probably be a few mkdir() calls, if those do not exist. And then I think to always call mkdir() when setting those options does not make sense. It should only be done if the directory does not yet exist.
| endif | ||
|
|
||
| " XDG Base Directory support | ||
| source $VIMRUNTIME/xdg.vim |
There was a problem hiding this comment.
This can simply be :ru xdg.vim, but I don't want this to be part of defaults.vim
There was a problem hiding this comment.
$VIMRUNTIME is more precise, as we know where the file is.
runtime/xdg.vim
Outdated
|
|
||
| if isdirectory(expand($XDG_CONFIG_HOME."/vim")) | ||
| set viminfofile=$XDG_STATE_HOME/vim/viminfo | call mkdir($XDG_STATE_HOME."/vim", 'p', 0700) | ||
| " set backupdir=$XDG_STATE_HOME/vim/backup | call mkdir(&backupdir, 'p', 0700) |
There was a problem hiding this comment.
Are backups really state? I would think they are data. Besides, it should be:
set backupdir=$XDG_<whatever>_HOME/vim/backup//
There was a problem hiding this comment.
By default, backupdir=.,~/tmp,~/. It includes ~/tmp, and 'writebackup' option is the default (backup is written temporary), so it doesn't look like something to pretend to be DATA for me.
Anyway, I don't see a good candidate for backupdir to commonly override here:
. (directory of the file?) still makes sense to me, as it allows lightweight reflink copies of the file on filesystems supporting it (BTRFS, etc.).
Non-doubtfully, we could just override ~/ part here, but I don't know an elegant way to do it in VimL, and as it goes last - we could just don't bother and keep it commented, letting the user to set whatever he actually wants.
If someone has strong opinion it should be set here - well, we could reconsider then.
Just my 2 cents.
There was a problem hiding this comment.
it should be: set backupdir=$XDG__HOME/vim/backup//
done
| " set backupdir=$XDG_STATE_HOME/vim/backup | call mkdir(&backupdir, 'p', 0700) | ||
| " set directory=$XDG_STATE_HOME/vim/swap | call mkdir(&directory, 'p', 0700) | ||
| " set viewdir=$XDG_STATE_HOME/vim/view | call mkdir(&viewdir, 'p', 0700) | ||
| " set undodir=$XDG_STATE_HOME/vim/undo | call mkdir(&undodir, 'p', 0700) |
There was a problem hiding this comment.
viewdir and undo files I would also consider DATA files
There was a problem hiding this comment.
- By default,
directory=.,~/tmp,/var/tmp,/tmp- seems purely temporary. No need to override. - For XDG,
viewdiris set by Vim already:viewdir=~/.config/vim/view, which suggests it goes to backup anyway. So I don't see the necessity to override it here (even if I would consider it STATE personally). undodir=.is the default, and 'undofile' option is off. That doesn't contradicts with XDG scheme. At least - these files never stayed on my way. No reason to override IMO.
So among all of these write-sensitive options, only viminfofile is clearly out of place for me. That is why I changed it only.
Considering amount of uncertainty, I would prefer progress in small steps, and this is the first step. Will see how it goes.
|
@bam80 do you mind mentioning |
Those are typically distro-specific files that packagers control. Gentoo and other distros ship their own, IME. IIRC Vim itself does not ship a system vimrc, and modifying defaults.vim is not the right way to tweak such a file.
Either of these ought be simple and easy to maintain. The latter should come with a short help tag explaining how to use Vim with the XDG setup. |
@diegoviola this seems out of scope here, please do yourself if you wish. Thanks. |
I don't know the internals, but on the first glance, if the directory exists already, mkdir() just does nothing. At least I didn't notice even timestamp change. |
Done |
|
|
||
| " These options are not essential for XDG, but you might want to set them: | ||
| " set backupdir=$XDG_STATE_HOME/vim/backup// | call mkdir(&backupdir, 'p', 0700) | ||
| " set directory=$XDG_STATE_HOME/vim/swap | call mkdir(&directory, 'p', 0700) |
There was a problem hiding this comment.
Could someone outline format of the swap file? Does it always contain a full copy of the original?
|
@chrisbra I deem this PR ready. If something else needs to be adjusted, it seems can be done later. PS: |
| @@ -0,0 +1,21 @@ | |||
| " XDG Base Directory support | |||
|
|
|||
| if empty($XDG_CONFIG_HOME) | let $XDG_CONFIG_HOME = $HOME."/.config" | endif | |||
There was a problem hiding this comment.
Sorry for just chiming in, but I don't think Vim should define these variables as environment variables, as they bleed into processes Vim spawns. Other programs Vim might spawn are expected handle the absence of these environment variables themselves and set their configuration accordingly.
There was a problem hiding this comment.
Yes, I also noticed this. That's one of the reasons I completely re-wrote the script.
There was a problem hiding this comment.
Defining these standard $XDG_ variables here this way should be safe, as if they are not set, XDG mandates default values for them that any other program spawned from Vim should not change. Setting them to the default values is perfectly OK, though.
So defining them here also gives additional convenience for any other vim scripts that goes after.
Thus, I can just rely on $XDG_DATA_HOME in my minpac setup and do not bother to handle the fallback there (as we can handle it once and for all here).
There was a problem hiding this comment.
I think @janvhs 's point is that some programs behave differently if the environment variables are set at all (for example, a program that supports XDG but has it's own defaults that are not XDG might honor the environment but otherwise default to ~/.myprog or something). That makes it not-so-safe.
|
I have made quite a few more changes. The script now looks completely different, but I want to make sure:
Please check if this all works fine. Thanks |
In shell (ignoring error handling and proper quoting, etc.) I think the same is true for Vim: I found some time ago that checks like |
|
FWIW, splitting this to 3 separate issues seems likely to fragment the conversation and make more work for the community 😅 OTOH, they are better scoped. Hope you all can work out a reasonable path forward (but at least Vim is so configurable that you can have your wishes even if upstream does something different). |
This might be true but I consider this to be bad style. For your personal vimrc such hacks are fine, but I want to be explicit about it when we ship this with Vim. |
@benknoble How did you find that? Is it something noticeable enough to worry about? |
For example, benknoble/Dotfiles@5068531. You can measure startup times with I think if you're doing lots of conditional things that also reach out to the underlying system it has the potential to be slow, that's all. |
If the system has XDG basedirs for Vim already, do support them.
Fixes #19399