I am currently running the following configuration for latex: NVim 0.9, Vmitex and Evince.
I have been trying to map a key to open <current-file>.log
, while the current-file
is a name taken from a currently opened file without extension, e.g. from something.tex
.
Here is my first attempt:
autocmd FileType tex nmap <buffer> <F5> :view \| split %:p:r.log<CR>
while it works it also creates multiple issues. Essentially the *.log
can be recreated, deleted by external process latexmk
, not existing etc. For instance, if the file was opened by nvim, then closed but later the file was cleared by external process, nvim would warn about it but would also bring the old version of the file, probably from a swap.
Therefore, I'd rather check if the file exists before I open it and display a message if the file is not there.
The following is what I've tired to accomplish:
autocmd FileType tex nmap <buffer> <F5> if !empty(glob(expand("%:p:r.log"))) | view \| split %:p:r.log<CR> | else | echo expand("%:p:r").'.log does not exist!' | endif
Unfortunately I've got error parsing the init.vim
:
Error detected while processing BufReadPost Autocommands for "*":
Vim(else):E581: :else without :if: else