简体   繁体   中英

How to map :!ruby % to a key combination in gvim?

I want to map :!ruby % to Ctrl + j in gvim, but I can't understand exactly how.

So, I know that there are different type of maps working in different modes - normal, visual, insert, etc. What I tried doing is adding :map <Cj> :!ruby % to vimrc and it's not working. The error is:

Error detected while processing function <SNR>100_Move

Also, vim.wikia.com lists this as an example map

:map <F2> :echo 'Current time is ' . strftime('%c')<CR>

What does <CR> stand for? I've seen it in a lot of the example commands there.

I would appreciate any help, thank you!

Try this command

:nmap <C-j> :!ruby %<CR>
  • nmap - normal mode map
  • <CR> - is like hitting enter
map  --> insert+normal+operator-pending mapping
imap --> insert mode mapping
nmap --> normal mode mapping
omap --> operator-pending mapping
cmap --> command-line mapping
vmap --> visual+select mode mapping
xmap --> visual mode mapping
smap --> select mode mapping

It is a good idea to be as specific as possible.

See :help map-modes and, more generally, :help map.txt .

Also see :help key-notation for the meaning of <CR> (already explained by nomad) and other special keys.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM