Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add XDG_BASE_DIR support #14182

Closed
wants to merge 5 commits into from
Closed

Add XDG_BASE_DIR support #14182

wants to merge 5 commits into from

Conversation

saccarosium
Copy link
Contributor

continues: #14167
fixes: #2034

I've added the check for $XDG_CONFIG_HOME.

@chrisbra
Copy link
Member

Thanks. I think we should add something to the documentation, about what $XDG_CONFIG_HOME is and where to find it.

Then we should probably add something to :version, mentioning $XDG_CONFIG_HOME as fourth vimrc File.

And finally, I suppose this does not make $XDG_CONFIG_HOME/vim part of the default runtime directory? That leaves the question, where do I put my other runtime files?

@saccarosium
Copy link
Contributor Author

I was thinking to introduce full XDG_BASE_DIR in another PR but make sense to do it all here

I think we should add something to the documentation, about what $XDG_CONFIG_HOME is and where to find it.

Yes it is probably a good a idea. Where exacly do you think we should put it this explenation (I'm not super versed on where is the appropriate spot for this information).

And finally, I suppose this does not make $XDG_CONFIG_HOME/vim part of the default runtime directory? That leaves the question, where do I put my other runtime files?

We could make a file to put under $VIMRUNTIME/xdg.vim that uses the appropriate XDG_BASE_DIR, that will be sourced when we detect that the user is using $XDG_CONFIG_HOME/vim/vimrc. This can also be beneficial for the users that wants to use XDG_BASE_DIR but still wants their vimrc in the home directory because they would just need to source $VIMRUNTIME/xdg.vim in their vimrc.

@saccarosium saccarosium changed the title Add XDG_CONFIG_HOME/vim/vimrc support Add XDG_BASE_DIR support Mar 12, 2024
@habamax
Copy link
Contributor

habamax commented Mar 12, 2024

This can also be beneficial for the users that wants to use XDG_BASE_DIR but still wants their vimrc in the home directory because they would just need to source $VIMRUNTIME/xdg.vim in their vimrc.

Let's not introduce yet another defaults.vim.

Can we add $XDG_CONFIG_HOME/vim/{plugin,after,ftplugin,...etc} to runtime path if $XDG_CONFIG_HOME/vim/vimrc was used?

PS, do we target Windows ~/AppData/vim/ here?

@saccarosium
Copy link
Contributor Author

PS, do we target Windows ~/AppData/vim/ here?

Ideally yes, but probably is better to address it in another PR since I don't really know the windows convention.

Let's not introduce yet another defaults.vim.

Why not exactly? What is the disadvantage of doing this in your opinion?

Can we add $XDG_CONFIG_HOME/vim/{plugin,after,ftplugin,...etc} to runtime path if $XDG_CONFIG_HOME/vim/vimrc was used?

I'm not against this just wanna know why the $VIMRUNTIME/xdg.vim is a bad idea.

@habamax
Copy link
Contributor

habamax commented Mar 12, 2024

Let's not introduce yet another defaults.vim.

Why not exactly? What is the disadvantage of doing this in your opinion?

There might be vim without eval. Or distro maintainer that will not package this .vim file for good(or whatever) reason.

defaults.vim caused probably the most user questions in freenode and then libera #vim channel, so whatever new default with regards to runtimepath to be introduced, it is better be in vim source code.

@habamax
Copy link
Contributor

habamax commented Mar 12, 2024

I take it, eval shouldn't matter as then your configuration doesn't make sense anywhere in filesystem.

@saccarosium
Copy link
Contributor Author

And finally, I suppose this does not make $XDG_CONFIG_HOME/vim part of the default runtime directory? That leaves the question, where do I put my other runtime files?

I want to layout what I was thinking for the runtime files layout.

First I give a brief explenation of the XDG varibles with their realative fallbacks:

  • XDG_CONFIG_HOME or $HOME/.config: user configuration
  • XDG_DATA_HOME or $HOME/.local/share: persistent user data
  • XDG_CACHE_HOME or $HOME/.cache: ephemiral user data

Having that in mind I was thinking the following layout:

XDG_CONFIG_HOME
| after/
| autoload/
| ...
| vimrc
XDG_DATA_HOME
| netrwhist
| viminfo
| ...
XDG_CACHE_HOME
| undo/
| backup/

For something like the pack dir, I don't really know where would be the appropriate spot. Someone could argue it belongs in XDG_CONFIG_HOME since some people like to have plugin as submodules, neovim user XDG_DATA_HOME.

@saccarosium
Copy link
Contributor Author

[...] add $XDG_CONFIG_HOME/vim/{plugin,after,ftplugin,...etc} to runtime path if $XDG_CONFIG_HOME/vim/vimrc was used [...]

@habamax makes sense. It make sense to do it this way.

@habamax
Copy link
Contributor

habamax commented Mar 12, 2024

For something like the pack dir, I don't really know where would be the appropriate spot. Someone could argue it belongs in XDG_CONFIG_HOME since some people like to have plugin as submodules, neovim user XDG_DATA_HOME.

I consider them the same as ~/.vim/ directory -- config, and put there my own configuration (filetypes, colorschemes, syntax files) I do for myself and would like them to be separated from ~/.vim/{ftplugin, plugin, colors, syntax, indent} to avoid clutter. And it is still in the same .vim repo I can clone on another machine.

@chrisbra
Copy link
Member

Puh, I am not sure I like this. First of all:

XDG_CONFIG_HOME
| after/
| autoload/
| ...
| vimrc
XDG_DATA_HOME
| netrwhist
| viminfo
| ...
XDG_CACHE_HOME
| undo/
| backup/

Shouldn't there be a vim directory under which undo/backup/viminfo/netrwhist/autoload etc are stored? Else we will be cluttering various $XDG_ directories with Vim related files and it's hard to find out what belongs to Vim (which matters if you want to make a backup, or move it to a new pc, etc).

Second, personally, I hate ripping apart the existing .vim directory for a similar reason. Nowadays, I can simply go to ~/.vim and archive it and move it to a new host. In the future I have to remember where all potential data for Vim will be stored. That makes my life as a user harder.

In short, I am not yet convinced we should spread out the data among several directories, even if this is what the freedesktop specification is about.

Same for Windows, I wholeheartly hate that I have to find anything below AppData, because it has become like a trash bin and it's hard to find the correct place (do I need to go to Local or Roaming? But fine, if this is just an alternative directory and I can still use my precious vimfiles directory. Oh well...

@habamax
Copy link
Contributor

habamax commented Mar 13, 2024

Shouldn't there be a vim directory under which undo/backup/viminfo/netrwhist/autoload etc are stored? Else we will be cluttering various $XDG_ directories with Vim related files and it's hard to find out what belongs to Vim (which matters if you want to make a backup, or move it to a new pc, etc).

I think this is a typo and it should have been XDG_CONFIG_HOME/vim/, XDG_DATA_HOME/vim/, etc.

Second, personally, I hate ripping apart the existing .vim directory for a similar reason. Nowadays, I can simply go to ~/.vim and archive it and move it to a new host. In the future I have to remember where all potential data for Vim will be stored. That makes my life as a user harder.

Same, I would like to have a vim config directory that is easily manageable. Not sure about .viminfo -- it is by default saved as ~/.viminfo even if you have ~/.vim/ directory.

@saccarosium
Copy link
Contributor Author

Shouldn't there be a vim directory under which undo/backup/viminfo/netrwhist/autoload etc are stored? Else we will be cluttering various $XDG_ directories with Vim related files and it's hard to find out what belongs to Vim (which matters if you want to make a backup, or move it to a new pc, etc).

It is a typo everything is under a vim directory in the respective XDG folders.

Second, personally, I hate ripping apart the existing .vim directory for a similar reason. Nowadays, I can simply go to ~/.vim and archive it and move it to a new host. In the future I have to remember where all potential data for Vim will be stored. That makes my life as a user harder.

This comes down to personal preference of the user. This days a lot of people dislike having a lot of file in their home. Also this will be only an option if the user activly opt in. A lot of programs do it this way while preserving their home location by default (tmux, emacs, etc).I think we should have a least the option.

Also:

XDG_CONFIG_HOME
| after/
| autoload/
| ...
| vimrc
XDG_DATA_HOME
| netrwhist
| viminfo
| ...
XDG_CACHE_HOME
| undo/
| backup/

this was an idea, is up for debate an modification.

@diegoviola
Copy link
Contributor

@saccarosium Thanks for reviving #14167! Happy to see progress on this. Cheers.

@saccarosium
Copy link
Contributor Author

@chrisbra we could just use XDG_CONFIG_HOME/vim as we use $HOME/.vim only if we find a XDG_CONFIG_HOME/vim/vimrc. But I would also put the viminfo in XDG_CONFIG_HOME/vim since if the user is using XDG_DIRS they don't want clutter in their HOME.

@diegoviola
Copy link
Contributor

@saccarosium @chrisbra What about XDG_STATE_HOME for viminfo and other history related files?

@chrisbra
Copy link
Member

we could just use XDG_CONFIG_HOME/vim as we use $HOME/.vim only if we find a XDG_CONFIG_HOME/vim/vimrc. But I would also put the viminfo in XDG_CONFIG_HOME/vim since if the user is using XDG_DIRS they don't want clutter in their HOME.

That sounds fine.

@chrisbra
Copy link
Member

@saccarosium @chrisbra What about XDG_STATE_HOME for viminfo and other history related files?

As mentioned before, I don't like scattering around vim folder across various $XDG related folders.

@vim-ml
Copy link

vim-ml commented Mar 15, 2024 via email

@chrisbra
Copy link
Member

Well true, except when you want your register-contents or search-/ex- history shared accross several systems 🤷 .

So let's leave the viminfo alone for now. People can already set :set viminfofile= to point it some other location.

src/os_unix.h Outdated Show resolved Hide resolved
@saccarosium
Copy link
Contributor Author

This is ready for review. The only thing is missing is some documentation on what is XDG_CONFIG_HOME or what is XDG.

src/option.c Outdated Show resolved Hide resolved
@ghgary
Copy link

ghgary commented Mar 19, 2024

":help 'runtimepath'" also needs to be updated.

@@ -236,7 +236,7 @@ typedef struct dsc$descriptor DESC;
# ifdef VMS
# define USR_VIMRC_FILE "sys$login:.vimrc"
# else
# define USR_VIMRC_FILE "$HOME/.vimrc"
# define USR_VIMRC_FILE "~/.vimrc"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change? That seems unrelated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a strange bug where it did expanded correctly (I was probably doing something wrong). Also is more consistent between other prepocessor variables. I can adress it in another PR if you want to.

@@ -809,7 +809,8 @@ accordingly. Vim proceeds in this order:
name. Also see |vimrc-intro|.

Places for your personal initializations:
Unix $HOME/.vimrc or $HOME/.vim/vimrc
Unix $HOME/.vimrc, $HOME/.vim/vimrc
or $XDG_CONFIG_HOME/vim/vimrc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are changing also changing 'runtimepath' and 'packpath'. That should also be documented.

@chrisbra
Copy link
Member

Can we please also have some tests? Have a look at github.com/vim/vim/blob/master/src/testdir/test_startup.vim

if ((opt_idx = findoption((char_u *)"packpath")) < 0)
goto theend;

options[opt_idx].def_val[VI_DEFAULT] = xdg_rtp;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options[opt_idx].def_val[VI_DEFAULT] = xdg_rtp;

This just overrides the default, right? I guess, this is not needed or is it?

Copy link
Contributor Author

@saccarosium saccarosium Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'packpath' defaults to DFLT_RUNTIMEPATH witch is:

// src/os_unix.h

#  ifdef RUNTIME_GLOBAL
#   ifdef RUNTIME_GLOBAL_AFTER
#    define DFLT_RUNTIMEPATH	"~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL_AFTER ",~/.vim/after"
#    define XDG_RUNTIMEPATH	"$XDG_CONFIG_HOME/vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL_AFTER "/after,$XDG_CONFIG_HOME/vim/after"
#    define XDG_RUNTIMEPATH_FB	"~/.config/vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL_AFTER "/after,~/.config/vim/after"
#    define CLEAN_RUNTIMEPATH	RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL_AFTER
#   else
#    define DFLT_RUNTIMEPATH	"~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.vim/after"
#    define XDG_RUNTIMEPATH	"$XDG_CONFIG_HOME/vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,$XDG_CONFIG_HOME/vim/after"
#    define XDG_RUNTIMEPATH_FB	"~/.config/vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.config/vim/after"
#    define CLEAN_RUNTIMEPATH	RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after"
#   endif
#  else
#   define DFLT_RUNTIMEPATH	"~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
#   define XDG_RUNTIMEPATH	"$XDG_CONFIG_HOME/vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$XDG_CONFIG_HOME/vim/after"
#   define XDG_RUNTIMEPATH_FB	"~/.config/vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.config/vim/after"
#   define CLEAN_RUNTIMEPATH	"$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after"
#  endif
// src/optiondefs.h

    {"packpath",    "pp",   P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
								    |P_SECURE,
			    (char_u *)&p_pp, PV_NONE, NULL, NULL,
			    {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
			    SCTX_INIT},

It should be need it unless I do the checks when initializing the options. But I don't know if there is a benefit or not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I know. I was just wondering if we need to override the default or if simply setting the option pointer is enough.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you want :set packpath& to do? Doesn't the default have to be overwritten with the XDG path for that command to restore the initial state?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yes makes sense. Thanks

@saccarosium
Copy link
Contributor Author

I've added some documentation on freedesktop and xdg. But I don't know how to connect it to 'runtimepath'. I think I need an help on that front.

I'll work on the test.

@chrisbra
Copy link
Member

oh great thanks. There are a few typos in the document and we probably don't need it in a separate doc file, but I can fix this when merging. Just a note to myself :)

@saccarosium
Copy link
Contributor Author

Hi @chrisbra
I've made a very simple test case and corrected some typos in the documentation. I'm not super good yet at writing test so I think I can't add anything more useful.

I think this can be merged.

Also there are some other things we may need to consider:

  • A function that returns the current vim dir location (e.g. $XDG_CONFIG_HOME/vim if they are using the xdg_vimrc or ~/.vim if their using ~/.vimrc/~/.vim/vimrc).
  • A way in the C code to check what rc is been used.

@ghgary
Copy link

ghgary commented Apr 11, 2024

Rather than a function, how about an environment variable? It's much easier to use an environment variable on the command line. $MYVIMRC is used now for the configuration file; you could use something like $MYVIM or $MYVIMDIR.
$MYVIMRC should already be visible in the C code.

@chrisbra
Copy link
Member

Is there a reason you cannot use echo fnamemodify(expand("$MYVIMRC"), ':p:h')?

@saccarosium
Copy link
Contributor Author

Is there a reason you cannot use echo fnamemodify(expand("$MYVIMRC"), ':p:h')?

Nope, I didn't know I could do that.

@ghgary
Copy link

ghgary commented Apr 11, 2024

That won't work if $MYVIMRC is ~/.vimrc.

@chrisbra chrisbra closed this in c9df1fb Apr 14, 2024
@Kreijstal
Copy link

so this patch will live on?

@chrisbra
Copy link
Member

sorry, what is your question?

XDG Base Directory Specification *xdg-base-dir* *$XDG_CONFIG_HOME*

The XDG Base Directory Specification aim to define standard locations for the
multilple data e configuration files used by applications. In order to divide
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed those when merging. You should probably compare against what was committed instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chrisbra pushed a commit to chrisbra/vim that referenced this pull request Apr 16, 2024
Problem:  Missing entry for XDG vimrc file in :version
Solution: Add 4th user vimrc entry to :version output
          (Diego Viola)

related: vim#14182
closes: vim#14569

Signed-off-by: Diego Viola <diego.viola@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
chrisbra pushed a commit to chrisbra/vim that referenced this pull request Apr 16, 2024
Problem:  Missing entry for XDG vimrc file in :version
Solution: Add 4th user vimrc entry to :version output
          (Diego Viola)

related: vim#14182
closes: vim#14569

Signed-off-by: Diego Viola <diego.viola@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
chrisbra pushed a commit to chrisbra/vim that referenced this pull request Apr 16, 2024
Problem:  Missing entry for XDG vimrc file in :version
Solution: Add 4th user vimrc entry to :version output
          (Diego Viola)

related: vim#14182
closes: vim#14569

Signed-off-by: Diego Viola <diego.viola@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
chrisbra pushed a commit that referenced this pull request Apr 16, 2024
Problem:  Missing entry for XDG vimrc file in :version
Solution: Add 4th user vimrc entry to :version output
          (Diego Viola)

related: #14182
closes: #14569

Signed-off-by: Diego Viola <diego.viola@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
@Surgo Surgo mentioned this pull request Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] .config/vim(UNIX), AppData/Roaming/vim(Windows) directory structure
8 participants