-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Port the support for <Cmd> key in map commands to execute commands without changing modes from Neovim #7282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Unfortunately appears to fail on Mac, check Travis. |
|
This text in map.txt isn't right "or an async event event was processed". "event" is doubled. And I suppose "async event" is a neovim thing. |
|
Also in map.txt: "they must be followed by in the +{lhs} of the mapping definition." should be {rhs}. In ex_getln.c a nested "if" is not needed, can use one "if" with "&&". |
|
Hi Bram,
On Wed, Nov 11, 2020 at 11:23 AM Bram Moolenaar ***@***.***> wrote:
Unfortunately appears to fail on Mac, check Travis.
Yes. I am looking into this test failure.
Regards,
Yegappan
|
|
Hi Bram,
On Wed, Nov 11, 2020 at 11:36 AM Bram Moolenaar ***@***.***> wrote:
Also in map.txt: "they must be followed by in the +{lhs} of the mapping
definition." should be {rhs}.
I have changed this.
It looks like this isn't checked at the time when the map is defined.
It also makes me wonder if must always come at the start of the {rhs}.
What could come before this that makes sense?
And if it must always end in we could just check for it. Or could there be
something following after the ?
You can use a map like the following:
noremap <F3> aHello<Cmd>let x = 10<CR>World
When the <F3> key is pressed, it will insert the text, execute the command
and
then continue inserting the rest of the text. So keys can be specified
before
the <Cmd> pseudo key and after the <CR> at the end of the command.
In ex_getln.c a nested "if" is not needed, can use one "if" with "&&".
I have changed this.
BTW, I didn't port the following changes in edit.c from Neovim (as the
insert-mode completion code has changed). These changes were made as part of
the "api: select items in popupmenu" commit to Neovim. But all the new
tests for
the <Cmd> key are passing without these changes. So I don't know the impact
of
these missing changes on insert mode completion.
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 90da6c8ab..5d918d8f6 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -4406,6 +4443,9 @@ void ins_compl_check_keys(int frequency, int
in_compl_func)
*/
static int ins_compl_key2dir(int c)
{
+ if (c == K_EVENT || c == K_COMMAND) {
+ return pum_want.item < pum_selected_item ? BACKWARD : FORWARD;
+ }
if (c == Ctrl_P || c == Ctrl_L
|| c == K_PAGEUP || c == K_KPAGEUP
|| c == K_S_UP || c == K_UP) {
@@ -4433,6 +4473,11 @@ static int ins_compl_key2count(int c)
{
int h;
+ if (c == K_EVENT || c == K_COMMAND) {
+ int offset = pum_want.item - pum_selected_item;
+ return abs(offset);
+ }
+
if (ins_compl_pum_key(c) && c != K_UP && c != K_DOWN) {
h = pum_get_height();
if (h > 3)
@@ -4459,6 +4504,9 @@ static bool ins_compl_use_match(int c)
case K_KPAGEUP:
case K_S_UP:
return false;
+ case K_EVENT:
+ case K_COMMAND:
+ return pum_want.active && pum_want.insert;
}
return true;
}
Regards,
Yegappan
|
Codecov Report
@@ Coverage Diff @@
## master #7282 +/- ##
==========================================
- Coverage 88.87% 88.85% -0.02%
==========================================
Files 148 148
Lines 162673 162731 +58
==========================================
+ Hits 144568 144602 +34
- Misses 18105 18129 +24
Continue to review full report at Codecov.
|
…thout changing modes from Neovim.
|
ah, that is nice for the various |
|
I see. If it's known Vim is insert mode, with the Normal mode mapping that starts with "a", then it would be possible to use CTRL-O for the Ex command. But I agree that using is more convenient, should have fewer side effects. |
|
@yegappan: It seems that using vim9script
var lines =<< trim END
---
aaa
---
bbb
bbb
---
ccc
ccc
ccc
---
END
setline(1, lines)
xno i- <esc><cmd>call <sid>Func()<cr>
ono i- <cmd>norm vi-<cr>
def Func()
search('^---\n\zs', 'bcW')
norm! V
search('\n\ze---$', 'W')
enddef
:2
norm di-
norm! j
norm .
norm! jj
norm .The final contents of the buffer is: vim9script
var lines =<< trim END
---
aaa
---
bbb
bbb
---
ccc
ccc
ccc
---
END
setline(1, lines)
xno i- <esc><cmd>call <sid>Func()<cr>
ono <silent> i- :<c-u>norm vi-<cr>
def Func()
search('^---\n\zs', 'bcW')
norm! V
search('\n\ze---$', 'W')
enddef
:2
norm di-
norm! j
norm .
norm! jj
norm .The final contents of the buffer is: The only difference between the two snippets is the In practice, I think I always want the second behavior, so I'll never use
Is it working as intended? If so, maybe it should be documented. I could try to write something if necessary. Also, while it's true that |
|
Also, it seems we don't need |
|
Hi,
On Thu, Nov 12, 2020 at 1:43 PM lacygoill ***@***.***> wrote:
Also, while it's true that <cmd> can replace :<C-U> in visual mode, in
practice, you'll probably want to press <esc> before, so that the visual
marks are set; at least, if your code refers to the visual marks. That was
done automatically with :<C-U>, but not with <cmd>. Again, it might be
useful to document this.
In the visual mode, you can use [line('v'), col('v')] and [line('.'),
col('.')] to get the starting
and ending cursor position of the visually selected text without leaving
visual mode.
For example, you can use the following map:
vnoremap <F3> <Cmd>echo [col('v'), col('.')]<CR>
You can visually select some text and press <F3> to echo the column numbers
without leaving visual mode.
- Yegappan
|
|
@lacygoill hmm, I assume this issue (operatior-pending dot repeat) is in neovim as well? I agree changing it to operator-repeat instead of geometry-repeat would be more useful. |
Sure, I just thought it was easier to simply press |
Yes, it also affects Neovim. I've just checked against master, with this code: let lines =<< trim END
---
aaa
---
bbb
bbb
---
ccc
ccc
ccc
---
END
call setline(1, lines)
xno i- <esc><cmd>call Func()<cr>
ono i- <cmd>norm vi-<cr>
fu Func()
call search('^---\n\zs', 'bcW')
norm! V
call search('\n\ze---$', 'W')
endfu
2
norm di-
norm! j
norm! .
norm! jj
norm! .Expected: Actual: |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Hi,
On Fri, Nov 13, 2020 at 7:44 AM Shane-XB-Qian ***@***.***> wrote:
and i was thinking it can reduce the mode switch which can reduce that
annoyed esc code output, but looks it's not helpful much..
e.g map l <cmd>call system('ls')<cr> and map h :call system('ls')<cr>
looks it still mode switched.. :)
and another amazing is when pressed l, this would print output into
buffer directly -vs- h print output into cmdline.
I am not able to reproduce this on MacOS or MS-Windows. With the above
map, when I press l or h, it doesn't output the directory listing and the
buffer contents
are not changed. BTW, in your example, the second map is not using the
<Cmd> key.
Regards,
Yegappan
|
This comment was marked as off-topic.
This comment was marked as off-topic.
|
I cannot reproduce |
Problem: Redoing a mapping with <Cmd> doesn't work properly.
Solution: Fill the redo buffer. Use "<SNR>" instead of a key code.
(closes #7282)
@lacygoill should be fixed with c77534c |
Problem: Redoing a mapping with <Cmd> doesn't work properly.
Solution: Fill the redo buffer. Use "<SNR>" instead of a key code.
(closes vim/vim#7282)
vim/vim@c77534c
Problem: Making a mapping work in all modes is complicated. Solution: Add the <Cmd> special key. (Yegappan Lakshmanan, closes vim/vim#7282, closes 4784, based on patch by Bjorn Linse) vim/vim@957cf67 Change docs to match Vim if it's wording better. Change error numbers to match Vim. Co-authored-by: Bram Moolenaar <[email protected]>
Problem: Making a mapping work in all modes is complicated. Solution: Add the <Cmd> special key. (Yegappan Lakshmanan, closes vim/vim#7282, closes 4784, based on patch by Bjorn Linse) vim/vim@957cf67 Change docs to match Vim if it's wording is better. Change error numbers to match Vim. Co-authored-by: Bram Moolenaar <[email protected]>
Problem: Making a mapping work in all modes is complicated. Solution: Add the <Cmd> special key. (Yegappan Lakshmanan, closes vim/vim#7282, closes 4784, based on patch by Bjorn Linse) vim/vim@957cf67 Change docs to match Vim if it's wording is better. Change error numbers to match Vim. Co-authored-by: Bram Moolenaar <[email protected]>
Problem: Making a mapping work in all modes is complicated. Solution: Add the <Cmd> special key. (Yegappan Lakshmanan, closes vim/vim#7282, closes 4784, based on patch by Bjorn Linse) vim/vim@957cf67 Change docs to match Vim if it's wording is better. Change error numbers to match Vim. Co-authored-by: Bram Moolenaar <[email protected]>
Problem: Making a mapping work in all modes is complicated. Solution: Add the <Cmd> special key. (Yegappan Lakshmanan, closes vim/vim#7282, closes 4784, based on patch by Bjorn Linse) vim/vim@957cf67 Change docs to match Vim if it's wording is better. Change error numbers to match Vim. Co-authored-by: Bram Moolenaar <[email protected]>
Problem: Making a mapping work in all modes is complicated. Solution: Add the <Cmd> special key. (Yegappan Lakshmanan, closes vim/vim#7282, closes 4784, based on patch by Bjorn Linse) vim/vim@957cf67 Change docs to match Vim if it's wording is better. Change error numbers to match Vim. Co-authored-by: Bram Moolenaar <[email protected]>
The Neovim commit that introduced the pseudo key support is:
neovim/neovim@d407a48