I want to see the output message:
1234
when I type 1234<Enter>
in normal mode of vim.
I've tried to write some vim script here
function! PrintNum(n)
echo n
endfunction
nmap n<Enter> call PrintNum(n)
where n
here is just a dummy variable that represents regex \\d+
.
How could I use some kind of regex in map command?
Note that I'm also not sure if I should use nmap
.
Here it is:
function! PrintNum(n)
echo a:n
endfunction
nnoremap <silent> <Enter> :<C-u>call PrintNum(v:count)<CR>
v:count
gets the number that can be put before any command. n
(internally referenced as a:n
), but I could have used v:count
also directly inside the function. :
command by default turns a count into a range, as we want a separate :call
, we remove this range via <Cu>
. <CR>
. The <silent>
avoids that you briefly see the mapped keys. :noremap
; it makes the mapping immune to remapping and recursion.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.