Closed nicodebo closed 7 years ago
What does the extra map hurt? My philosophy is to always map if it doesn't get in the way, because otherwise you're just being needlessly hostile to any coworker who sits down at your computer without having your custom maps memorized.
In fact, I'm using bépo keyboard layout (kind of the french version of dvorak). Thus, to have my {h,j,k,l} vim movements like on a classic azerty layout, I have mapped {h,j,k,l} to {c,t,s,r}. So basically I have these following lines in my vimrc:
" [HJKL] -> {CTSR}
" ————————————————
noremap c h
noremap r l
noremap t j
noremap s k
noremap C H
noremap R L
noremap T J
noremap S K
" {HJKL} <- [CTSR]
" ————————————————
noremap j t
noremap J T
noremap l c
noremap L C
noremap h r
noremap H R
noremap k s
noremap K S
Now, when using this particular layout (which I can agree that it is not very coworker friendly) with vim-commentary
, I have a delay when moving left with my c
key because of the cgc
plug map (nmap cgc <Plug>ChangeCommentary
).
I have also tried to unmap the vim-commentary
mappings directly in the vimrc but they were still loaded and that's why I'm using the abovementionned "fix".
I have also tried to unmap the vim-commentary mappings directly in the vimrc but they were still loaded and that's why I'm using the abovementionned "fix".
That is because the plugin file is sourced after the vimrc. I guess that if you do the unmapping in a function and call it at VimEnter
you should be fine; something like:
function UnmapCommentary()
" unmap here
endfunction
autocmd VimEnter * call UnmapCommentary()
This looks like a very specific issue which could be satisfied by a very specific solution like this 😃
Your solution works well and is better than modifiying the source code itself like I was doing until now.
For reference I have the following lines in vimrc to fix the mapping conflict:
function! UnmapCommentary()
unmap gc
nunmap gcc
nunmap cgc
nunmap gcu
endfunction
xmap <leader>c <Plug>Commentary
nmap <leader>c <Plug>Commentary
omap <leader>c <Plug>Commentary
nmap <leader>cc <Plug>CommentaryLine
nmap l<leader>c <Plug>ChangeCommentary
nmap <leader>cu <Plug>Commentary<Plug>Commentary
augroup bepo_clash
autocmd!
autocmd VimEnter * call UnmapCommentary()
augroup END
Thanks to both of you.
I also thinking wrapping the cgc
map in a nested check for maparg('c', 'n')
would be quite reasonable, if that would help. Certainly if c
is remapped, it makes no sense to map cgc
.
General informations
Minimal vimrc
Step to reproduce
:nmap g
and press enterExpected behavior
Well, I'm not totally sure about whether I did something wrong but I expect the default mapping not to load when I'm defining my own mappings.
Possible fix
Shouldn't the line 94 of the vim-commentary.vim source file be
instead of
?
At least, it seems to fix my issue but I would need some advice.