Skip to content

Cmdline history not updated when mapping both <Up> and <CR>#18607

Closed
zeertzjq wants to merge 1 commit intovim:masterfrom
zeertzjq:cmdline-history
Closed

Cmdline history not updated when mapping both <Up> and <CR>#18607
zeertzjq wants to merge 1 commit intovim:masterfrom
zeertzjq:cmdline-history

Conversation

@zeertzjq
Copy link
Member

@zeertzjq zeertzjq commented Oct 20, 2025

Problem: Cmdline history not updated when mapping both <Up> and <CR>.
Solution: Consider the command typed when in Cmdline mode and there is
no pending input.

fixes: #2771
related: neovim/neovim#36256

Although the existing behavior technically does match documentation, the
"completely come from mappings" part is a bit ambiguous, because one may
argue that the command doesn't completely come from mappings as long as
the user has typed a key in Cmdline mode. I'm not entirely sure if this
change will cause problems, but it seems unlikely.

@zeertzjq zeertzjq force-pushed the cmdline-history branch 2 times, most recently from f60a7b4 to 92d4827 Compare October 20, 2025 13:13
Comment on lines +64 to +65
- Only commands that are typed are remembered. A command coming completely
from a mapping is not put in the history.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also matches :h ": better:

		The command-line is only stored in this register when at least
		one character of it was typed.  Thus it remains unchanged if
		the command was completely from a mapping.

There it says "a mapping" instead of "mappings".

Copy link
Member

@chrisbra chrisbra Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "was completely" is a bit awkward, should probably be something like this?

Thus it remains unchanged if the command was executed from a mapping.

@zeertzjq zeertzjq force-pushed the cmdline-history branch 4 times, most recently from d8849b5 to 41c2690 Compare October 24, 2025 23:02
@chrisbra
Copy link
Member

How about this on top?

diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt
index ff64628e0..58c370c29 100644
--- a/runtime/doc/change.txt
+++ b/runtime/doc/change.txt
@@ -1324,7 +1324,7 @@ and ":put" commands and with CTRL-R.
                "@:" to repeat the previous command-line command.
                The command-line is only stored in this register when at least
                one character of it was typed.  Thus it remains unchanged if
-               the command was completely from a mapping.
+               the command was executed completely from a mapping.
                {not available when compiled without the |+cmdline_hist|
                feature}
                                                        *quote_#* *quote#*
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index 07b5e129a..120313ee0 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -2612,6 +2612,7 @@ func Test_recalling_cmdline_with_mappings()
   cnoremap <F2> <Cmd>let g:cmdline = getcmdline()<CR>
   cnoremap <CR> <CR>
   cnoremap <Up> <Up>
+  let _a = ['a', getreg('a'), getregtype('a')]

   call feedkeys(":echo 'foo'\<CR>", 'tx')
   call assert_equal("echo 'foo'", @:)
@@ -2655,7 +2656,18 @@ func Test_recalling_cmdline_with_mappings()
   call assert_equal("echo 'foo'", g:cmdline)
   call assert_equal("echo 'foo'", @:)

+  " a command coming from a mapping is also ignored in the history
+  call feedkeys(':let @a=":echo ''zzz''\<cr>"', 'tx')
+  call feedkeys(":norm @a\<cr>", 'tx')
+  call assert_equal('norm @a', @:)
+  call assert_equal('norm @a', histget(':', -1))
+  call assert_equal('let @a=":echo ''zzz''\<cr>"', histget(':', -2))
+  call assert_equal("echo 'foo'", histget(':', -3))
+  call assert_equal("echo 'bar'", histget(':', -4))
+
+
   unlet g:cmdline
+  call call('setreg', _a)
   cunmap <F2>
   cunmap <CR>
   cunmap <Up>

Problem:  Cmdline history not updated when mapping both <Up> and <CR>.
Solution: Consider the command typed when in Cmdline mode and there is
          no pending input.

fixes: vim#2771
related: neovim/neovim#36256

Although the existing behavior technically does match documentation, the
"completely come from mappings" part is a bit ambiguous, because one may
argue that the command doesn't completely come from mappings as long as
the user has typed a key in Cmdline mode.  I'm not entirely sure if this
change will cause problems, but it seems unlikely.
@chrisbra
Copy link
Member

thanks

@chrisbra chrisbra closed this in 97b6e8b Oct 26, 2025
@zeertzjq zeertzjq deleted the cmdline-history branch October 26, 2025 13:37
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Oct 26, 2025
… <CR>

Problem:  Cmdline history not updated when mapping both <Up> and <CR>.
Solution: Consider the command typed when in Cmdline mode and there is
          no pending input (zeertzjq).

Although the existing behavior technically does match documentation, the
"completely come from mappings" part is a bit ambiguous, because one may
argue that the command doesn't completely come from mappings as long as
the user has typed a key in Cmdline mode.  I'm not entirely sure if this
change will cause problems, but it seems unlikely.

fixes: vim/vim#2771
related: neovim#36256
closes: vim/vim#18607

vim/vim@97b6e8b

Co-authored-by: zeertzjq <zeertzjq@outlook.com>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Oct 26, 2025
… <CR>

Problem:  Cmdline history not updated when mapping both <Up> and <CR>.
Solution: Consider the command typed when in Cmdline mode and there is
          no pending input (zeertzjq).

Although the existing behavior technically does match documentation, the
"completely come from mappings" part is a bit ambiguous, because one may
argue that the command doesn't completely come from mappings as long as
the user has typed a key in Cmdline mode.  I'm not entirely sure if this
change will cause problems, but it seems unlikely.

fixes: vim/vim#2771
related: neovim#36256
closes: vim/vim#18607

vim/vim@97b6e8b
zeertzjq added a commit to neovim/neovim that referenced this pull request Oct 26, 2025
… <CR> (#36334)

Problem:  Cmdline history not updated when mapping both <Up> and <CR>.
Solution: Consider the command typed when in Cmdline mode and there is
          no pending input (zeertzjq).

Although the existing behavior technically does match documentation, the
"completely come from mappings" part is a bit ambiguous, because one may
argue that the command doesn't completely come from mappings as long as
the user has typed a key in Cmdline mode.  I'm not entirely sure if this
change will cause problems, but it seems unlikely.

fixes: vim/vim#2771
related: #36256
closes: vim/vim#18607

vim/vim@97b6e8b
github-actions bot pushed a commit to neovim/neovim that referenced this pull request Jan 23, 2026
… <CR> (#36334)

Problem:  Cmdline history not updated when mapping both <Up> and <CR>.
Solution: Consider the command typed when in Cmdline mode and there is
          no pending input (zeertzjq).

Although the existing behavior technically does match documentation, the
"completely come from mappings" part is a bit ambiguous, because one may
argue that the command doesn't completely come from mappings as long as
the user has typed a key in Cmdline mode.  I'm not entirely sure if this
change will cause problems, but it seems unlikely.

fixes: vim/vim#2771
related: #36256
closes: vim/vim#18607

vim/vim@97b6e8b
(cherry picked from commit 2407833)
github-actions bot pushed a commit to neovim/neovim that referenced this pull request Jan 23, 2026
… <CR> (#36334)

Problem:  Cmdline history not updated when mapping both <Up> and <CR>.
Solution: Consider the command typed when in Cmdline mode and there is
          no pending input (zeertzjq).

Although the existing behavior technically does match documentation, the
"completely come from mappings" part is a bit ambiguous, because one may
argue that the command doesn't completely come from mappings as long as
the user has typed a key in Cmdline mode.  I'm not entirely sure if this
change will cause problems, but it seems unlikely.

fixes: vim/vim#2771
related: #36256
closes: vim/vim#18607

vim/vim@97b6e8b
(cherry picked from commit 2407833)
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.

Problem when using custom cmap key to recall older command-line from history

2 participants