Closed user202729 closed 4 years ago
@chrisbra I've just tested it and it's even worse -- <c-o>%
in insert mode now always insert visual mode, and in visual mode it still insert "m'gv``"
However, it's possible to do this instead
--- a/plugin/matchit.vim
+++ b/plugin/matchit.vim
@@ -48,8 +48,8 @@ set cpo&vim
nnoremap <silent> <Plug>(MatchitNormalForward) :<C-U>call matchit#Match_wrapper('',1,'n')<CR>
nnoremap <silent> <Plug>(MatchitNormalBackward) :<C-U>call matchit#Match_wrapper('',0,'n')<CR>
-xnoremap <silent> <Plug>(MatchitVisualForward) :<C-U>call matchit#Match_wrapper('',1,'v')<CR>m'gv``
-xnoremap <silent> <Plug>(MatchitVisualBackward) :<C-U>call matchit#Match_wrapper('',0,'v')<CR>m'gv``
+xnoremap <silent> <Plug>(MatchitVisualForward) :<C-U>call matchit#Match_wrapper('',1,'v') <bar> normal! m'gv``<CR>
+xnoremap <silent> <Plug>(MatchitVisualBackward) :<C-U>call matchit#Match_wrapper('',0,'v') <bar> normal! m'gv``<CR>
onoremap <silent> <Plug>(MatchitOperationForward) :<C-U>call matchit#Match_wrapper('',1,'o')<CR>
onoremap <silent> <Plug>(MatchitOperationBackward) :<C-U>call matchit#Match_wrapper('',0,'o')<CR>
(it may be better to include the normal!
command into the Match_wrapper
function)
I do not see this. For me this works. What vim version is this?
Am 03.03.2020 um 01:56 schrieb user202729 notifications@github.com:
I've just tested it and it's even worse --
v in insert mode now always insert visual mode, and in visual mode it still insert "m'gv``". — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or unsubscribe.
Vim 8.2.0148-1, Arch Linux.
(I copy the repository into ~/.vim/pack. If I understood correctly, the plugin check for a global variable so that it only loads once, so it's not necessary to remove the global version)
But how can it be correct to run normal! v
when the old mode is "n"?
(the old message has a typo. <c-o>%
in insert mode always enter visual mode.)
@chrisbra I upgraded to a newer version and the issue still persists (for matchit version 1.17)
Full version info:
So does this patch fix it?
diff --git a/autoload/matchit.vim b/autoload/matchit.vim
index 4f3dd8f..264df29 100644
--- a/autoload/matchit.vim
+++ b/autoload/matchit.vim
@@ -44,12 +44,12 @@ function matchit#Match_wrapper(word, forward, mode) range
let restore_options = s:RestoreOptions()
" If this function was called from Visual mode, make sure that the cursor
" is at the correct end of the Visual range:
- if a:mode == "v"
- execute "normal! gv\<Esc>"
- elseif a:mode == "o" && mode(1) !~# '[^VvV]'
+ if a:mode =~# "[nvV]" && mode(1) =~# 'ni'
exe "norm! v"
- elseif a:mode == "n" && mode(1) =~# 'ni'
+ elseif a:mode == "o" && mode(1) !~# '[^VvV]'
exe "norm! v"
+ elseif a:mode == "v"
+ execute "normal! gv\<Esc>"
endif
" In s:CleanUp(), we may need to check whether the cursor moved forward.
let startpos = [line("."), col(".")]
@chrisbra Now %
works in insert visual mode, but <c-o>%
in insert mode still enters visual mode.
(the literal ^V
character in the diff file is not preserved when copied to GitHub, so the diff file doesn't apply directly. I don't know if I made any mistake while applying the patch.)
Now % works in insert visual mode, but
% in insert mode still enters visual mode.
ah <c-o>%
is a different problem.
I think this patch fixes both problems:
diff --git a/autoload/matchit.vim b/autoload/matchit.vim
index 4f3dd8f..49841b1 100644
--- a/autoload/matchit.vim
+++ b/autoload/matchit.vim
@@ -42,14 +42,14 @@ endfunction
function matchit#Match_wrapper(word, forward, mode) range
let restore_options = s:RestoreOptions()
+ if a:mode =~# "v" && mode(1) =~# 'ni'
+ exe "norm! v"
+ elseif a:mode == "o" && mode(1) !~# '[^VvV]'
+ exe "norm! v"
" If this function was called from Visual mode, make sure that the cursor
" is at the correct end of the Visual range:
- if a:mode == "v"
+ elseif a:mode == "v"
execute "normal! gv\<Esc>"
- elseif a:mode == "o" && mode(1) !~# '[^VvV]'
- exe "norm! v"
- elseif a:mode == "n" && mode(1) =~# 'ni'
- exe "norm! v"
endif
" In s:CleanUp(), we may need to check whether the cursor moved forward.
let startpos = [line("."), col(".")]
can you please test?
Yes, now it works, but there is another problem.
Given a file (a.cpp) with content
{
a
}
Putting the cursor in first line, then pressing i<c-o>v
, press %
once will move the cursor to the last line, but press %
again will not move it to the first line.
That problem does not happen in normal visual mode.
I think you shouldn't really use <c-o>
from insert mode for anything fancy. It was supposed to be used for a single (builtin) normal mode command. Now with custom maps and plugins, this will break sooner or later. Having said that, I believe this would fix it:
diff --git a/autoload/matchit.vim b/autoload/matchit.vim
index 4f3dd8f..10a3738 100644
--- a/autoload/matchit.vim
+++ b/autoload/matchit.vim
@@ -42,14 +42,14 @@ endfunction
function matchit#Match_wrapper(word, forward, mode) range
let restore_options = s:RestoreOptions()
+ if a:mode =~# "v" && mode(1) =~# 'ni'
+ exe "norm! gv"
+ elseif a:mode == "o" && mode(1) !~# '[^VvV]'
+ exe "norm! v"
" If this function was called from Visual mode, make sure that the cursor
" is at the correct end of the Visual range:
- if a:mode == "v"
+ elseif a:mode == "v"
execute "normal! gv\<Esc>"
- elseif a:mode == "o" && mode(1) !~# '[^VvV]'
- exe "norm! v"
- elseif a:mode == "n" && mode(1) =~# 'ni'
- exe "norm! v"
endif
" In s:CleanUp(), we may need to check whether the cursor moved forward.
let startpos = [line("."), col(".")]
let me know, what you think.
Reproduction steps:
i
(enter insert mode)<c-o>v
. Now the status bar should show "(insert) VISUAL"%
.m'gv``
is displayed on the screen.