Skip to main content
deleted 20 characters in body
Source Link
Maxim Kim
  • 13.9k
  • 2
  • 20
  • 48

If you look into :h 'backupdir', you will find in the description:

    - For Unix and Win32, if a directory ends in two path separators "//",
      the backup file name will be built from the complete path to the
      file with all path separators changed to percent '%' signs. This
      will ensure file name uniqueness in the backup directory.
      On Win32, it is also possible to end with "\\".  However, When a
      separating comma is following, you must use "//", since "\\" will
      include the comma in the file name. Therefore it is recommended to
      use '//', instead of '\\'.

Thus, if you add // at the end of the path, it should usebehave the same thing that you have foras 'undodir' now.:

set backupdir=~/.cache/vim/backup// |call mkdir(&backupdir, 'p', 0o700)

One example of setting up directories:

vim9script

g:vimdata = $'{has("win32") ? expand("$APPDATA") : expand("~/.config")}/vim-data'
if !isdirectory(g:vimdata) | mkdir(g:vimdata, "p") | endif

&directory = expand($'{g:vimdata}/swap/')
&backupdir = expand($'{g:vimdata}/backup//')
&undodir = expand($'{g:vimdata}/undo//')
if !isdirectory(&undodir)   | mkdir(&undodir, "p")   | endif
if !isdirectory(&backupdir) | mkdir(&backupdir, "p") | endif
if !isdirectory(&directory) | mkdir(&directory, "p") | endif

set backup
set undofile

As an exampleHere, I have edited 2 files readme.md files, one in ~/temp/hello/ and another in ~/temp/world/ directories:

enter image description here

If you look into :h 'backupdir' you will find in the description:

    - For Unix and Win32, if a directory ends in two path separators "//",
      the backup file name will be built from the complete path to the
      file with all path separators changed to percent '%' signs. This
      will ensure file name uniqueness in the backup directory.
      On Win32, it is also possible to end with "\\".  However, When a
      separating comma is following, you must use "//", since "\\" will
      include the comma in the file name. Therefore it is recommended to
      use '//', instead of '\\'.

Thus if you add // at the end of the path, it should use the same thing that you have for 'undodir' now.

set backupdir=~/.cache/vim/backup// |call mkdir(&backupdir, 'p', 0o700)

One example of setting up directories:

vim9script

g:vimdata = $'{has("win32") ? expand("$APPDATA") : expand("~/.config")}/vim-data'
if !isdirectory(g:vimdata) | mkdir(g:vimdata, "p") | endif

&directory = expand($'{g:vimdata}/swap/')
&backupdir = expand($'{g:vimdata}/backup//')
&undodir = expand($'{g:vimdata}/undo//')
if !isdirectory(&undodir)   | mkdir(&undodir, "p")   | endif
if !isdirectory(&backupdir) | mkdir(&backupdir, "p") | endif
if !isdirectory(&directory) | mkdir(&directory, "p") | endif

set backup
set undofile

As an example, I have edited 2 files readme.md, one in ~/temp/hello/ another in ~/temp/world/ directories:

enter image description here

If you look into :h 'backupdir', you will find in the description:

    - For Unix and Win32, if a directory ends in two path separators "//",
      the backup file name will be built from the complete path to the
      file with all path separators changed to percent '%' signs. This
      will ensure file name uniqueness in the backup directory.
      On Win32, it is also possible to end with "\\".  However, When a
      separating comma is following, you must use "//", since "\\" will
      include the comma in the file name. Therefore it is recommended to
      use '//', instead of '\\'.

Thus, if you add // at the end of the path, it should behave the same as 'undodir':

set backupdir=~/.cache/vim/backup// |call mkdir(&backupdir, 'p', 0o700)

One example of setting up directories:

vim9script

g:vimdata = $'{has("win32") ? expand("$APPDATA") : expand("~/.config")}/vim-data'
if !isdirectory(g:vimdata) | mkdir(g:vimdata, "p") | endif

&directory = expand($'{g:vimdata}/swap/')
&backupdir = expand($'{g:vimdata}/backup//')
&undodir = expand($'{g:vimdata}/undo//')
if !isdirectory(&undodir)   | mkdir(&undodir, "p")   | endif
if !isdirectory(&backupdir) | mkdir(&backupdir, "p") | endif
if !isdirectory(&directory) | mkdir(&directory, "p") | endif

set backup
set undofile

Here, I have edited 2 readme.md files, one in ~/temp/hello/ and another in ~/temp/world/ directories:

enter image description here

added 207 characters in body
Source Link
Maxim Kim
  • 13.9k
  • 2
  • 20
  • 48

If you look into :h 'backupdir' you will find in the description:

    - For Unix and Win32, if a directory ends in two path separators "//",
      the backup file name will be built from the complete path to the
      file with all path separators changed to percent '%' signs. This
      will ensure file name uniqueness in the backup directory.
      On Win32, it is also possible to end with "\\".  However, When a
      separating comma is following, you must use "//", since "\\" will
      include the comma in the file name. Therefore it is recommended to
      use '//', instead of '\\'.

Thus if you add // at the end of the path, it should use the same thing that you have for 'undodir' now.

set backupdir=~/.cache/vim/backup// |call mkdir(&backupdir, 'p', 0o700)

One example of setting up directories:

vim9script

g:vimdata = $'{has("win32") ? expand("$APPDATA") : expand("~/.config")}/vim-data'
if !isdirectory(g:vimdata) | mkdir(g:vimdata, "p") | endif

&directory = expand($'{g:vimdata}/swap/')
&backupdir = expand($'{g:vimdata}/backup//')
&undodir = expand($'{g:vimdata}/undo//')
if !isdirectory(&undodir)   | mkdir(&undodir, "p")   | endif
if !isdirectory(&backupdir) | mkdir(&backupdir, "p") | endif
if !isdirectory(&directory) | mkdir(&directory, "p") | endif

set backup
set undofile

As an example, I have edited 2 files readme.md, one in ~/temp/hello/ another in ~/temp/world/ directories:

enter image description here

If you look into :h 'backupdir' you will find in the description:

    - For Unix and Win32, if a directory ends in two path separators "//",
      the backup file name will be built from the complete path to the
      file with all path separators changed to percent '%' signs. This
      will ensure file name uniqueness in the backup directory.
      On Win32, it is also possible to end with "\\".  However, When a
      separating comma is following, you must use "//", since "\\" will
      include the comma in the file name. Therefore it is recommended to
      use '//', instead of '\\'.

Thus if you add // at the end of the path, it should use the same thing that you have for 'undodir' now.

One example of setting up directories:

vim9script

g:vimdata = $'{has("win32") ? expand("$APPDATA") : expand("~/.config")}/vim-data'
if !isdirectory(g:vimdata) | mkdir(g:vimdata, "p") | endif

&directory = expand($'{g:vimdata}/swap/')
&backupdir = expand($'{g:vimdata}/backup//')
&undodir = expand($'{g:vimdata}/undo//')
if !isdirectory(&undodir)   | mkdir(&undodir, "p")   | endif
if !isdirectory(&backupdir) | mkdir(&backupdir, "p") | endif
if !isdirectory(&directory) | mkdir(&directory, "p") | endif

set backup
set undofile

If you look into :h 'backupdir' you will find in the description:

    - For Unix and Win32, if a directory ends in two path separators "//",
      the backup file name will be built from the complete path to the
      file with all path separators changed to percent '%' signs. This
      will ensure file name uniqueness in the backup directory.
      On Win32, it is also possible to end with "\\".  However, When a
      separating comma is following, you must use "//", since "\\" will
      include the comma in the file name. Therefore it is recommended to
      use '//', instead of '\\'.

Thus if you add // at the end of the path, it should use the same thing that you have for 'undodir' now.

set backupdir=~/.cache/vim/backup// |call mkdir(&backupdir, 'p', 0o700)

One example of setting up directories:

vim9script

g:vimdata = $'{has("win32") ? expand("$APPDATA") : expand("~/.config")}/vim-data'
if !isdirectory(g:vimdata) | mkdir(g:vimdata, "p") | endif

&directory = expand($'{g:vimdata}/swap/')
&backupdir = expand($'{g:vimdata}/backup//')
&undodir = expand($'{g:vimdata}/undo//')
if !isdirectory(&undodir)   | mkdir(&undodir, "p")   | endif
if !isdirectory(&backupdir) | mkdir(&backupdir, "p") | endif
if !isdirectory(&directory) | mkdir(&directory, "p") | endif

set backup
set undofile

As an example, I have edited 2 files readme.md, one in ~/temp/hello/ another in ~/temp/world/ directories:

enter image description here

Source Link
Maxim Kim
  • 13.9k
  • 2
  • 20
  • 48

If you look into :h 'backupdir' you will find in the description:

    - For Unix and Win32, if a directory ends in two path separators "//",
      the backup file name will be built from the complete path to the
      file with all path separators changed to percent '%' signs. This
      will ensure file name uniqueness in the backup directory.
      On Win32, it is also possible to end with "\\".  However, When a
      separating comma is following, you must use "//", since "\\" will
      include the comma in the file name. Therefore it is recommended to
      use '//', instead of '\\'.

Thus if you add // at the end of the path, it should use the same thing that you have for 'undodir' now.

One example of setting up directories:

vim9script

g:vimdata = $'{has("win32") ? expand("$APPDATA") : expand("~/.config")}/vim-data'
if !isdirectory(g:vimdata) | mkdir(g:vimdata, "p") | endif

&directory = expand($'{g:vimdata}/swap/')
&backupdir = expand($'{g:vimdata}/backup//')
&undodir = expand($'{g:vimdata}/undo//')
if !isdirectory(&undodir)   | mkdir(&undodir, "p")   | endif
if !isdirectory(&backupdir) | mkdir(&backupdir, "p") | endif
if !isdirectory(&directory) | mkdir(&directory, "p") | endif

set backup
set undofile