Because on Linux, there is possible that file exists but is not readable by the user (I rather don't think it is feasible on Windows, but...), I seek for VimL functions to differentiate between those two states, which I could put into my _vimrc of my gVim.
Asked
Active
Viewed 697 times
1
Vlastimil Burián
- 435
- 1
- 3
- 12
1 Answers
1
I tried to write these functions myself, but feel free to correct me in your own answer.
" This defines the name and path of my buffer list file
" For I am on Windows, I can use \\, i.e. escaping
" But it is not necessary and also non-portable
let BufferListFile = $HOME . "/.vim/buflist.txt"
"-----------------------------------------------------------------------------
" This function returns true if the defined file exists
" No matter if it is readable by the user
" Gotten from https://stackoverflow.com/a/23496813/1997354
function FileExists(FileName)
return !empty(glob(a:FileName))
endfunction
"-----------------------------------------------------------------------------
" This function returns true if the defined file
" is readable by the user
" There is no reason to define the function myself
" as there already is the following built-in function
" filereadable()
Vlastimil Burián
- 435
- 1
- 3
- 12
- take parameters instead of working with global variables
- be non global, but defined in autoload plugins -- unless you always need them in your vimrc and never anywhere else
- and BTW,
- Forget
– Luc Hermitte Jul 05 '18 at 09:36returnisn't a function, you don't need parentheses.'\\'.'/'always works with every OS.s:BufferListFileReadable. I only define functions that overlap with builtin functions when there is a chance the end user may have a version of vim that doesn't implement that function. Also I would give a more generic name like:s:fileexists()more in sync with what it really does. – Luc Hermitte Jul 05 '18 at 14:31