0

I am looking at part of this vimrc file from Ben Frain

https://gist.github.com/benfrain/f09dd39e66fe2da9cf0a

" Allow line movement on wraps with CTRL+usual {{{
vmap <C-j> gj
vmap <C-k> gk
vmap <C-h> g$
vmap <C-6> g^
vmap <C-0> g^
nmap <C-j> gj
nmap <C-k> gk
nmap <C-4> g$
nmap <C-6> g^
nmap <C-0> g^
" }}}

I do notice an issue in that list e.g. ctrl-k already does gk. So when that works it's not from his mapping.

I am using macvim

Even if I try something simple

~/.vim$ cat vimrc
nmap <C-0> aaaa
~/.vim$ 

or

~/.vim$ cat vimrc
nmap <C-0> aaaa
vmap <C-0> aaaa
~/.vim$ 

it's not working, it's not mapping ctrl-0 to the typing of 'aaaa'

I've tried with /usr/local/bin/vim(that's macvim installed via brew cask install macvim) and i've tried /usr/bin/vim(that's the vim that comes preinstalled). So it makes no difference which vim I use.

And i'd like to know which, if any, ctrl keys can be mapped.

I have heard that it's a bad idea to map ctrl keys, maybe 'cos many are in use, and that it's better to use the leader key, whose default is backslash. So . map <leader>0 aaaa . and that works, but i'm still curious re the mapping of ctrl.

barlop
  • 12,887
  • 8
  • 80
  • 109
  • Related question [vim - How to map Ctrl+A and Ctrl+Shift+A differently? - Stack Overflow](https://stackoverflow.com/questions/1506764/how-to-map-ctrla-and-ctrlshifta-differently/2179779#2179779) – user202729 Feb 17 '23 at 02:35

2 Answers2

4

Vim doesn't "see" all available Ctrl-something combinations. Vim is developed for a Unix terminal and those terminals don't provide all Ctrl-keys to the application.

To test if a ctrl combination is mappable, do the following:

Open Vim and change into insert mode. Then hit Ctrl-v followed by the Ctrl combination you want to map. If something is displayed, the Ctrl combination is mappable.

Examples:

  • If you hit Ctrl-v followed by Ctrl-k the character ^k is displayed (usually in light blue). So Ctrl-k is mappable.
  • If you hit Ctrl-v followed by Ctrl-0 nothing is displayed. So Ctrl-0 is not mappable.
  • If you hit Ctrl-v followed by Ctrl-3 the character ^[ is displayed. So ... Ctrl-3 is equal to ESC.
Ralf
  • 1,773
  • 8
  • 17
  • any idea about finding out which command keys are mappable? (the command key on a macbook keyboard) – barlop May 22 '19 at 18:30
0

This page mentions difference between xmap, vmap and nmap https://vim.fandom.com/wiki/Mapping_keys_in_Vim_-Tutorial(Part_1)

:map <-- (presumably display all maps)

:nmap - Display normal mode maps
:imap - Display insert mode maps
:vmap - Display visual and select mode maps
:smap - Display select mode maps
:xmap - Display visual mode maps
:cmap - Display command-line mode maps
:omap - Display operator pending mode maps

and

nmap, nnoremap, nunmap          Normal mode
imap, inoremap, iunmap          Insert and Replace mode
vmap, vnoremap, vunmap          Visual and Select mode
xmap, xnoremap, xunmap          Visual mode
smap, snoremap, sunmap          Select mode
cmap, cnoremap, cunmap          Command-line mode
omap, onoremap, ounmap          Operator pending mode

It looks like you can't do the numbers with ctrl.

nmap is for normal mode so to type aaaa, you need to type iaaaa so as to go into insert mode first. So, with nmap, mapping to iaaaa to get 'aaaa' typed.

You can try nmap <C-a> iaaaa all the way up to <C-z>, and get a response from most of them. You can do map <C-a> aaaa or :map <C-a> aaaa

barlop
  • 12,887
  • 8
  • 80
  • 109