Skip to content

Instantly share code, notes, and snippets.

@jamescherti
Last active December 25, 2022 22:04
Show Gist options
  • Select an option

  • Save jamescherti/3651dfc40aac4181f01fffad4095094e to your computer and use it in GitHub Desktop.

Select an option

Save jamescherti/3651dfc40aac4181f01fffad4095094e to your computer and use it in GitHub Desktop.
Vim: Return the path to viminfo.
" Language: Vim script
" Description: Return the path to viminfo.
" Author: James Cherti
" URL: https://gist.github.com/jamescherti/3651dfc40aac4181f01fffad4095094e
" License: MIT
function! VimInfoPath() abort
if &viminfofile
return fnamemodify(&viminfofile, ':p')
endif
for l:item in split(&viminfo, ',')
if len(l:item) > 0 && l:item[0] ==# 'n'
return fnamemodify(l:item[1:], ':p')
endif
endfor
" :help viminfo-file-name
if has('win32') && !has('win32unix')
if exists('$HOME')
return fnamemodify($HOME . '\_viminfo', ':p')
elseif exists('$VIM')
return fnamemodify($VIM . '\_viminfo', ':p')
else
return 'c:\_viminfo'
endif
else
return fnamemodify('~/.viminfo', ':p')
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment