I need to backup the registers and settings of a limited group of files. I'm more interested in what can be saved in a viminfo file, less interested in sessionss.

I'm having a problem reading viminfo file upon BufReadPre.

au BufReadPre,FileReadPre  *.md if expand('<amatch>') =~ '/path/to/file/\d\{3}-' | 
:verbose rv c:/Users/path/to/viminfo.vim

If I open a file that matches the above regex, everything's ok: the viminfo file is read.

However, if I open subsequent files (that also match the above regex) using eg. :e myfile.md, there is no indication that the viminfo file is read (using :mess).

This is driving me nuts!! Can you help please?

BTW: I'm logging events and can see quite clearly that BufReadPre is being triggered on the occasions mentioned above.

" ftplugin/markdown.vim

function! Dev_autocommands_enter()
            :let g:style="design"
            :set fenc=utf8
            :set lines=34
            :set cursorline
            :set wildmenu
            :set wildmode=full
            :verbose rv c:/Users/path/to/_dev/testing/vim/macros/viminfo-registers.vim
            :map <C-j> :bprev<CR>
            :map <C-k> :bnext<CR>
            :nmap <A-o> o<ESC>k
            :nmap <A-O> O<ESC>j

if !exists("mdCmds_loaded")
    augroup mdCmds
        au BufReadPre,FileReadPre  *.md if expand('<amatch>') =~ '/path/_dev/testing/\d\{3}-' | 
            :call Dev_autocommands_enter()
        au BufUnload *.md if expand('<amatch>') =~ '/path/_dev/testing/\d\{3}-' | 
            \ :verbose wv c:/Users/path/to/_dev/testing/vim/macros/viminfo-registers.vim
    augroup end
    let mdCmds_loaded = 1

  • If the code posted isn't the actual code, then perhaps you could share a closer example? The code talks about a viminfo file, but later you say function. Also, assuming ftplugins/the FileType event isn't good enough for this, you could try using BufRead and BufNewFile—those are what is typically used for filetype-detection.
    – D. Ben Knoble
    Jul 13, 2021 at 17:47
  • Also looks like you're missing endif and a continuation marker `\`
    – D. Ben Knoble
    Jul 13, 2021 at 17:47
  • Actually, I suspect that's the issue: the rv command could be run at vimrc time instead of installed as the autocommand. Can you check :autocmd {your-group}?
    – D. Ben Knoble
    Jul 13, 2021 at 17:48
  • No need to add "edit" markers. The goal is for the question to read fluidly and clearly. OTOH, I'm not sure the image adds anything. Have you considered using sessions?
    – D. Ben Knoble
    Jul 14, 2021 at 17:00
  • I would start with simplifying the whole thing. First thing fixing is adding the :endif commands. I actually wonder, why you did not get an error message Jul 15, 2021 at 7:10


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.