Reputation: 8718
How to know which command is executed by a default Vim shortcut?
I've seen similar questions where the accepted answer only applied for custom (user or plugin defined shortcuts).
For example, I want to map the action performed by (scroll half page down) with another shortcut, by I don't know which command to call. I cannot map it to <c-d>
because I'm using that shortcut for another command (:q
).
Upvotes: 0
Views: 241
Reputation: 172768
Several good answers already, but I think you're mostly missing the difference between :map
and :noremap
. With the latter (and recommended one!), existing mappings aren't considered.
So if you have a mapping to <C-d>
, and still want to use that "scroll down by half page" elsewhere, just use :nnoremap ... <C-d>
.
As others have remarked, there's no built-in function, the default <C-d>
key is the function. Within functions (vs. mappings, where you'd use :noremap
), you can also use :normal!
to trigger it: :execute "normal! \<C-d>"
.
Upvotes: 1
Reputation: 196886
The default "shortcuts" are not "shortcuts": they are low-level commands. You don't need to know what commands they are mapped to as they are not mapped to anything.
If you want to use the functionality provided by d
in a mapping, just use d
:
nnoremap <key> <something>d<somethingelse>
With regard to one of your comments below: Ex commands are all line-wise because Ex was line-wise so it doesn't really make sense to think about them as command-line versions of normal mode commands, which are generally character-wise.
Upvotes: 1
Reputation: 8718
I couldn't find commands for default shortcuts, but I discover a way to achieve what I wanted:
" My custom map, use noremap to prevent <c-u> from using overridden definition
nnoremap <Space> <c-d>
map <c-d> :q <cr>
Upvotes: 0
Reputation: 7688
To see the default mappings can look in :help index
.
As you mention for custom mappings you can use :map X
, :imap X
, etc.
Upvotes: 0
Reputation: 195269
you can create customized mapping, e.g nnoremap <leader>a ggVG
<leader>a
was mapped to command sequence:gg V G
I guess the "default shortcut" you meant was like the gg or V or G
in above example. Those "shortcuts" do call some function/programs, but we don't know those functions, since they are built-in stuff, if you want to know them you have to read vim's source codes.
To your question, creating mapping for scroll half page down
, you could try
nnoremap {yourKeysHere} <c-d>
:h ctrl-d
for detail, <c-d>
will scroll half screen down. In another word, you just create mapping to those "default shortcuts" then you got it.
If this doesn't answer your question, pls give concrete requirement, what you want to achieve.
Upvotes: 0