Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@yegappan
Copy link
Member

@yegappan yegappan commented Nov 11, 2020

The Neovim commit that introduced the pseudo key support is:
neovim/neovim@d407a48

@brammool
Copy link
Contributor

Unfortunately appears to fail on Mac, check Travis.

@brammool
Copy link
Contributor

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.

@brammool
Copy link
Contributor

Also in map.txt: "they must be followed by in the +{lhs} of the mapping definition." should be {rhs}.
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 ?

In ex_getln.c a nested "if" is not needed, can use one "if" with "&&".

@vim-ml
Copy link

vim-ml commented Nov 11, 2020 via email

@vim-ml
Copy link

vim-ml commented Nov 12, 2020 via email

@codecov
Copy link

codecov bot commented Nov 12, 2020

Codecov Report

Merging #7282 (d4ace00) into master (6f62448) will decrease coverage by 0.01%.
The diff coverage is 93.84%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
src/misc2.c 91.90% <ø> (ø)
src/getchar.c 86.28% <91.11%> (+0.15%) ⬆️
src/edit.c 92.52% <100.00%> (+<0.01%) ⬆️
src/ex_docmd.c 94.61% <100.00%> (+<0.01%) ⬆️
src/ex_getln.c 91.35% <100.00%> (+0.01%) ⬆️
src/insexpand.c 91.19% <100.00%> (ø)
src/map.c 90.98% <100.00%> (ø)
src/normal.c 95.93% <100.00%> (+<0.01%) ⬆️
src/ops.c 92.36% <100.00%> (ø)
src/screen.c 86.71% <100.00%> (+0.09%) ⬆️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f62448...c26df9c. Read the comment docs.

@chrisbra
Copy link
Member

ah, that is nice for the various screen..() functions as you do not have to work-around using the mode-changing.

@brammool
Copy link
Contributor

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.

@brammool brammool closed this in 957cf67 Nov 12, 2020
@lacygoill
Copy link

@yegappan: It seems that using <cmd> in an operator-pending mapping might break the dot command. That is, instead of recomputing the text-object, Vim re-uses a text area with the same geometry as for the previous command.

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:

---
---
bbb
---
ccc
ccc
---
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 :ono mapping:

# first snippet
ono i- <cmd>norm vi-<cr>

# second snippet
ono <silent> i- :<c-u>norm vi-<cr>

In practice, I think I always want the second behavior, so I'll never use <cmd> in an :ono mapping. And yet, operator-pending mode is mentioned at :h <cmd>:

This is more flexible than :<C-U> in Visual and Operator-pending mode, or
<C-O>: in Insert mode, because the commands are executed directly in the
current mode, instead of always going to Normal mode. Visual mode is

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 <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.

@lacygoill
Copy link

Also, it seems we don't need <silent> anymore with <cmd>. This could be added as an extra benefit in the "Note:" list.

@vim-ml
Copy link

vim-ml commented Nov 13, 2020 via email

@bfredl
Copy link
Contributor

bfredl commented Nov 13, 2020

@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.

@lacygoill
Copy link

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 to echo the column numbers
without leaving visual mode.

  • Yegappan

Sure, I just thought it was easier to simply press <esc> without having to delve into the code to find where the visual marks are used:

xnoremap <F3> <esc><cmd>call <sid>Func()<cr>
              ^---^

@lacygoill
Copy link

@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.

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:

---
---
bbb
---
ccc
ccc
---

@Shane-XB-Qian

This comment was marked as off-topic.

@Shane-XB-Qian

This comment was marked as off-topic.

@Shane-XB-Qian

This comment was marked as off-topic.

@vim-ml
Copy link

vim-ml commented Nov 13, 2020 via email

@Shane-XB-Qian

This comment was marked as off-topic.

@bfredl
Copy link
Contributor

bfredl commented Nov 13, 2020

I cannot reproduce map l <cmd>call system('ls')<cr> issues either on linux (as of patch 8.2.1981). Not sure what mode it would switch to, system() is just a function, not a mode (unlike say :terminal )

brammool added a commit that referenced this pull request Nov 18, 2020
Problem:    Redoing a mapping with <Cmd> doesn't work properly.
Solution:   Fill the redo buffer.  Use "<SNR>" instead of a key code.
            (closes #7282)
@chrisbra
Copy link
Member

It seems that using in an operator-pending mapping might break the dot command.

@lacygoill should be fixed with c77534c

bfredl added a commit to bfredl/neovim that referenced this pull request Nov 18, 2020
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
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request May 7, 2023
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]>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request May 7, 2023
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]>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request May 7, 2023
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]>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request May 7, 2023
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]>
clason pushed a commit to clason/neovim that referenced this pull request May 10, 2023
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]>
folke pushed a commit to folke/neovim that referenced this pull request May 22, 2023
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants