patch 9.2.0019: Hard to configure Vim according to full XDG spec
Commit:
https://github.com/vim/vim/commit/4f04efb760af4f51975091ace7605c3dbd01d0c9
Author: Andrey Butirsky <[email protected]>
Date: Wed Feb 18 21:14:24 2026 +0000
patch 9.2.0019: Hard to configure Vim according to full XDG spec
Problem: Hard to configure Vim according to full XDG spec
Solution: Include the $VIMRUNTIME/xdg.vim script as an example.
(Andrey Butirsky).
closes: #19421
Co-authored-by: Christian Brabandt <[email protected]>
Signed-off-by: Andrey Butirsky <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt
index 2c3968853..4d828a1c3 100644
--- a/runtime/doc/starting.txt
+++ b/runtime/doc/starting.txt
@@ -1,4 +1,4 @@
-*starting.txt* For Vim version 9.2. Last change: 2026 Feb 16
+*starting.txt* For Vim version 9.2. Last change: 2026 Feb 18
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1125,8 +1125,13 @@ This is not an exhaustive list of those directories:
`$XDG_DATA_HOME` $HOME/.local/share Persistent data files
`$XDG_STATE_HOME` $HOME/.local/state State data files
-Vim will only use the `$XDG_CONFIG_HOME` directory, the others are not
-(yet) used for its various configuration and state files.
+ *xdg.vim*
+Vim itself will only use the $XDG_CONFIG_HOME directory. Support for the
+other XDG directories is provided by the "$VIMRUNTIME/xdg.vim" script.
+Note: xdg.vim is only effective if the $XDG_CONFIG_HOME/vim directory (or
+its default fallback) exists. By default, it only sets the 'viminfofile'
+option. Other option settings are commented out, see the script for
+details on how to enable them.
*xdg-vimrc*
Vim, on Unix systems, will look at `$XDG_CONFIG_HOME/vim/vimrc` for its
diff --git a/runtime/doc/tags b/runtime/doc/tags
index 2c7d10766..2d3858b4d 100644
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -11899,6 +11899,7 @@ xattr editing.txt /*xattr*
xdg-base-dir starting.txt /*xdg-base-dir*
xdg-runtime starting.txt /*xdg-runtime*
xdg-vimrc starting.txt /*xdg-vimrc*
+xdg.vim starting.txt /*xdg.vim*
xf86conf.vim syntax.txt /*xf86conf.vim*
xfontset mbyte.txt /*xfontset*
xfree-xterm syntax.txt /*xfree-xterm*
diff --git a/runtime/xdg.vim b/runtime/xdg.vim
new file mode 100644
index 000000000..254cb1248
--- /dev/null
+++ b/runtime/xdg.vim
@@ -0,0 +1,46 @@
+" XDG Base Directory support
+" This script sets up paths for XDG compliance.
+" Maintainer: The Vim Project <https://github.com/vim/vim>
+" Last Change: 2026 Feb 18
+
+let s:config = empty($XDG_CONFIG_HOME) ? expand("~/.config") :
expand("$XDG_CONFIG_HOME")
+let s:data = empty($XDG_DATA_HOME) ? expand("~/.local/share") :
expand("$XDG_DATA_HOME")
+let s:state = empty($XDG_STATE_HOME) ? expand("~/.local/state") :
expand("$XDG_STATE_HOME")
+
+if isdirectory(s:config .. '/vim')
+ func s:mkvimdir(dir)
+ if !isdirectory(a:dir)
+ call mkdir(a:dir, 'p', 0700)
+ endif
+ return a:dir
+ endfunc
+
+ " Use Data for packages, prevent duplicates
+ if index(split(&packpath, ','), s:data .. '/vim') == -1
+ exe $"set packpath^={s:data}/vim"
+ exe $"set packpath+={s:data}/vim/after"
+ endif
+
+ " Use Data for the viminfo file
+ let &viminfofile = s:mkvimdir(s:data .. '/vim') .. '/viminfo'
+
+ " These options are not set by default because they change the behavior of
+ " where files are saved. Uncomment them if you want to fully move all
+ " transient/persistent files to XDG directories.
+ " Note: Undo/Views/Spell are placed in DATA_HOME as they are persistent,
+ " while Swap/Backups use STATE_HOME as transient session state.
+
+ " Persistent Data:
+ " let &undodir = s:mkvimdir(s:data .. '/vim/undo') .. '//'
+ " let &viewdir = s:mkvimdir(s:data .. '/vim/view') .. '//'
+ " let g:netrw_home = s:mkvimdir(s:data .. '/vim')
+ " call s:mkvimdir(s:data .. '/vim/spell')
+
+ " Transient State:
+ " let &directory = s:mkvimdir(s:state .. '/vim/swap') .. '//'
+ " let &backupdir = s:mkvimdir(s:state .. '/vim/backup') .. '//'
+
+ delfunction s:mkvimdir
+endif
+
+unlet s:config s:data s:state
diff --git a/src/Makefile b/src/Makefile
index c0b7db75f..99c77cb34 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2400,6 +2400,9 @@ installrtbase: $(HELPSOURCE)/vim.1 $(DEST_VIM)
$(VIMTARGET) $(DEST_RT) \
chmod $(VIMSCRIPTMOD) $(DEST_SCRIPT)/vimrc_example.vim
$(INSTALL_DATA) $(SCRIPTSOURCE)/gvimrc_example.vim $(DEST_SCRIPT)
chmod $(VIMSCRIPTMOD) $(DEST_SCRIPT)/gvimrc_example.vim
+# install the xdg file
+ $(INSTALL_DATA) $(SCRIPTSOURCE)/xdg.vim $(DEST_SCRIPT)
+ chmod $(VIMSCRIPTMOD) $(DEST_SCRIPT)/xdg.vim
# install the file type detection files
$(INSTALL_DATA) $(SCRIPTSOURCE)/filetype.vim $(SYS_FILETYPE_FILE)
chmod $(VIMSCRIPTMOD) $(SYS_FILETYPE_FILE)
diff --git a/src/version.c b/src/version.c
index 4f4155200..8fabd64ed 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 19,
/**/
18,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1vsp7U-001Uk8-LF%40256bit.org.