Skip to content

Commit 6233243

Browse files
authored
fix(mappings): prefer <cmd>, drop <silent> justinmk#235
Problem: Dirvish key mappings that are <silent> prevent Vim from asking the user to enter an encryption key when an encrypted file is opened from Dirvish (`:help encryption`). Solution: Remove <silent> from the key mappings that call 'dirvish#open()' and replace ':call' with '<cmd>call'.
1 parent 81b4087 commit 6233243

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

ftplugin/dirvish.vim

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,36 @@ if !hasmapto('<Plug>(dirvish_K)', 'n')
1818
execute 'xmap '.s:nowait.'<buffer> K <Plug>(dirvish_K)'
1919
endif
2020

21-
execute 'nnoremap '.s:nowait.'<buffer><silent> ~ :<C-U>Dirvish ~/<CR>'
22-
execute 'nnoremap '.s:nowait.'<buffer><silent> i :<C-U>.call dirvish#open("edit", 0)<CR>'
23-
execute 'nnoremap '.s:nowait.'<buffer><silent> <CR> :<C-U>.call dirvish#open("edit", 0)<CR>'
24-
execute 'nnoremap '.s:nowait.'<buffer><silent> a :<C-U>.call dirvish#open("vsplit", 1)<CR>'
25-
execute 'nnoremap '.s:nowait.'<buffer><silent> o :<C-U>.call dirvish#open("split", 1)<CR>'
26-
execute 'nnoremap '.s:nowait.'<buffer><silent> p :<C-U>.call dirvish#open("p", 1)<CR>'
27-
execute 'nnoremap '.s:nowait.'<buffer><silent> <2-LeftMouse> :<C-U>.call dirvish#open("edit", 0)<CR>'
21+
" The patch 8.2.1978 adds '<cmd>' to Vim.
22+
if has('patch-8.2.1978')
23+
let s:command_prefix = '<cmd>'
24+
let s:call_prefix = '<cmd>'
25+
let s:command_suffix = ''
26+
else
27+
let s:command_prefix = ':<C-U>'
28+
let s:call_prefix = ':<C-U>.'
29+
let s:command_suffix = ":echon ''<CR>"
30+
endif
31+
execute 'nnoremap '.s:nowait.'<buffer> ~ '.s:command_prefix.'Dirvish ~/<CR>'.s:command_suffix
32+
execute 'nnoremap '.s:nowait.'<buffer> i '.s:call_prefix.'call dirvish#open("edit", 0)<CR>'.s:command_suffix
33+
execute 'nnoremap '.s:nowait.'<buffer> <CR> '.s:call_prefix.'call dirvish#open("edit", 0)<CR>'.s:command_suffix
34+
execute 'nnoremap '.s:nowait.'<buffer> a '.s:call_prefix.'call dirvish#open("vsplit", 1)<CR>'.s:command_suffix
35+
execute 'nnoremap '.s:nowait.'<buffer> o '.s:call_prefix.'call dirvish#open("split", 1)<CR>'.s:command_suffix
36+
execute 'nnoremap '.s:nowait.'<buffer> p '.s:call_prefix.'call dirvish#open("p", 1)<CR>'.s:command_suffix
37+
execute 'nnoremap '.s:nowait.'<buffer> <2-LeftMouse> '.s:call_prefix.'call dirvish#open("edit", 0)<CR>'.s:command_suffix
2838
execute 'nnoremap '.s:nowait.'<buffer><silent> dax :<C-U>arglocal<Bar>silent! argdelete *<Bar>echo "arglist: cleared"<Bar>Dirvish<CR>'
2939
execute 'nnoremap '.s:nowait.'<buffer><silent> <C-n> <C-\><C-n>j:call feedkeys("p")<CR>'
3040
execute 'nnoremap '.s:nowait.'<buffer><silent> <C-p> <C-\><C-n>k:call feedkeys("p")<CR>'
3141

32-
execute 'xnoremap '.s:nowait.'<buffer><silent> I :call dirvish#open("edit", 0)<CR>'
33-
execute 'xnoremap '.s:nowait.'<buffer><silent> <CR> :call dirvish#open("edit", 0)<CR>'
34-
execute 'xnoremap '.s:nowait.'<buffer><silent> A :call dirvish#open("vsplit", 1)<CR>'
35-
execute 'xnoremap '.s:nowait.'<buffer><silent> O :call dirvish#open("split", 1)<CR>'
36-
execute 'xnoremap '.s:nowait.'<buffer><silent> P :call dirvish#open("p", 1)<CR>'
42+
" The patch 8.2.1978 adds '<cmd>' to Vim.
43+
if !has('patch-8.2.1978')
44+
let s:call_prefix = ':'
45+
endif
46+
execute 'xnoremap '.s:nowait.'<buffer> I '.s:call_prefix.'call dirvish#open("edit", 0)<CR>'.s:command_suffix
47+
execute 'xnoremap '.s:nowait.'<buffer> <CR> '.s:call_prefix.'call dirvish#open("edit", 0)<CR>'.s:command_suffix
48+
execute 'xnoremap '.s:nowait.'<buffer> A '.s:call_prefix.'call dirvish#open("vsplit", 1)<CR>'.s:command_suffix
49+
execute 'xnoremap '.s:nowait.'<buffer> O '.s:call_prefix.'call dirvish#open("split", 1)<CR>'.s:command_suffix
50+
execute 'xnoremap '.s:nowait.'<buffer> P '.s:call_prefix.'call dirvish#open("p", 1)<CR>'.s:command_suffix
3751

3852
nnoremap <buffer><silent> R :<C-U><C-R>=v:count ? ':let g:dirvish_mode='.v:count.'<Bar>' : ''<CR>Dirvish<CR>
3953
nnoremap <buffer><silent> g? :help dirvish-mappings<CR>

0 commit comments

Comments
 (0)