You can use line continuations (lines after the first starting with a backslash) and using |
s to separate commands.
Something like this might work for you (but I haven't tested it, so it might be missing some escaping):
autocmd BufRead,BufNewFile /tmp/wiki-tag-reports/*
\ nnoremap <Enter> :DiaryTagBrowser <Enter>
\ | nnoremap <Backspace> :bd! <Enter>
\ | nnoremap q :q!<CR>
\ | set ft=vimwiki
But this approach can be pretty fragile, particularly due to the rules around escaping |
s (see :help :bar
and :help :execute
, which is often used to work around it.)
A much saner approach is to just define a function with all commands you want to execute and call that function from your autocmd
, there are no pitfalls with escaping in that case and it's much easier to include complex logic (including conditional statements.)
For example:
function! SetupWikiTagReports()
nnoremap <buffer> <Enter> :DiaryTagBrowser <Enter>
nnoremap <buffer> <Backspace> :bd! <Enter>
nnoremap <buffer> q :q!<CR>
set ft=vimwiki
endfunction
autocmd BufRead,BufNewFile /tmp/wiki-tag-reports/* call SetupWikiTagReports()
Note that I also added <buffer>
tags to your mappings here, since you only want those mappings on the buffers which are editing files of these types. You don't want those mappings to be global. If you edit multiple files that match that pattern, the autocmd
will execute for each of them and create the mappings on all buffers.
I see you're also setting a filetype in your autocmd
. Do you intend these mappings to be set only for files in /to/wiki-tag-reports
? Or for every file of type vimwiki
? If the latter, then consider simply setting a filetype based on the autocmd
with the filename pattern (you could do so in a ~/.vim/ftdetect/*.vim
file, which gets loaded automatically from Vim's filetype detection code), and then creating a ~/.vim/after/ftplugin/vimwiki.vim
with the mappings (still using <buffer>
mappings there.) That file is sourced every time a file gets filetype vimwiki
, so that would be an easy approach to create the mappings consistently.