]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0019: Hard to configure Vim according to full XDG spec v9.2.0019
authorAndrey Butirsky <butirsky@gmail.com>
Wed, 18 Feb 2026 21:14:24 +0000 (21:14 +0000)
committerChristian Brabandt <cb@256bit.org>
Wed, 18 Feb 2026 21:14:24 +0000 (21:14 +0000)
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 <cb@256bit.org>
Signed-off-by: Andrey Butirsky <butirsky@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/starting.txt
runtime/doc/tags
runtime/xdg.vim [new file with mode: 0644]
src/Makefile
src/version.c

index 2c39688532a43a61eb602e7a776a24937afbfb51..4d828a1c342f59960b3d4c89eebf2dd4e3986068 100644 (file)
@@ -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
index 2c7d10766e200f62e9e5d0f495b14d59141ab2de..2d3858b4d704898e5844ead3383e13aef61e2c39 100644 (file)
@@ -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 (file)
index 0000000..254cb12
--- /dev/null
@@ -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
index c0b7db75ff88ff749a22b6df6aaf641dbe89dc11..99c77cb34c082d3f05cbcb391a98698c2aca85a5 100644 (file)
@@ -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)
index 4f41552007709e053a2dc976cf246317f136c2c0..8fabd64ed3d354663adda26efe0467519f7758b2 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    19,
 /**/
     18,
 /**/