2

I am using Vim version 7.4 from 2012-Dez-06 of Ubuntu 16.04, and I use PuTTY 0.67 on W10. I want to map the keys of the NUM pad in .vimrc. This doesn't work:

map <k1> COMMAND
map k1 COMMAND
map <C-k1> COMMAND
map <S-k1> COMMAND
map *keypad-1* COMMAND
map keypad-1 COMMAND

If I do for example:

map 1 dd

it works and the line is deleted if I hit 1.

If I hit in vi the NUM buttons I get q, r, s, t ... If I map q to a command only the normal q button will execute the command but not 1 on the NUM pad. My .vimrc is:

# cat ~/.vimrc
syntax on
set t_Co=256
colorscheme elflord
if &diff
    colorscheme apprentice
endif

The h keycodes (Thanks to Ashok) is:

Notation        Bedeutung                   Äquivalent  Dezimale/r Wert/e   ~
-----------------------------------------------------------------------
<Nul>           Null                    CTRL-@    0 (gespeichert als 10) *<Nul>*
<BS>            Zeichenrückschritt      CTRL-H    8     *backspace*
<Tab>           Tabulator               CTRL-I    9     *tab* *Tab*
                                                        *linefeed*
<NL>            Zeilenvorschub          CTRL-J   10 (benutzt für <Nul>)
<FF>            Seitenvorschub          CTRL-L   12     *formfeed*
<CR>            Wagenrücklauf           CTRL-M   13     *carriage-return*
<Return>        dasselbe wie <CR>                               *<Return>*
<Enter>         dasselbe wie <CR>                               *<Enter>*
<Esc>           Fluchttaste             CTRL-[   27     *escape* *<Esc>*
<Space>         Leertaste                        32     *space*
<lt>            weniger-als             <        60     *<lt>*
<Bslash>        Backslash               \        92     *backslash* *<Bslash>*
<Bar>           vertikaler Strich       |       124     *<Bar>*
<Del>           Löschen                         127
<CSI>           Befehlsfolgeneinleiter  ALT-Esc 155     *<CSI>*
<xCSI>          CSI in der GUI getippt                  *<xCSI>*

<EOL>           Zeilenende (kann <CR>, <LF> oder <CR><LF> sein, hängt ab vom
                System und 'fileformat')        *<EOL>*

<Up>            Cursor rauf                     *cursor-up* *cursor_up*
<Down>          Cursor runter                   *cursor-down* *cursor_down*
<Left>          Cursor links                    *cursor-left* *cursor_left*
<Right>         Cursor rechts                   *cursor-right* *cursor_right*
<S-Up>          Umschalttaste Cursor rauf
<S-Down>        Umschalttaste Cursor runter
<S-Left>        Umschalttaste Cursor links
<S-Right>       Umschalttaste Cursor rechts
<C-Left>        Steuerung Cursor links
<C-Right>       Steuerung Cursor rechts
<F1> - <F12>    Funktionstaste 1 bis 12         *function_key* *function-key*
<S-F1> - <S-F12> Umschalttaste Funktionstaste 1 bis 12  *<S-F1>*
<Help>          Hilfetaste
<Undo>          Undo-Taste
<Insert>        Einfügetaste
<Home>          Anfang                          *home*
<End>           Ende                            *end*
<PageUp>        Bild rauf                               *page_up* *page-up*
<PageDown>      Bild runter                             *page_down* *page-down*
<kHome>         Anfang auf dem Ziffernblock (oben links)*keypad-home*
<kEnd>          Ende auf dem Ziffernblock (unten links) *keypad-end*
                                                        *keypad-page-up*
<kPageUp>       Bild rauf auf dem Ziffernblock (oben rechts)
                                                        *keypad-page-down*
<kPageDown>     Bild runter auf dem Ziffernblock (unten rechts)
<kPlus>         + auf dem Ziffernblock                  *keypad-plus*
<kMinus>        - auf dem Ziffernblock                  *keypad-minus*
<kMultiply>     * auf dem Ziffernblock                  *keypad-multiply*
<kDivide>       / auf dem Ziffernblock                  *keypad-divide*
<kEnter>        Enter auf dem Ziffernblock              *keypad-enter*
<kPoint>        Dezimalzeichen auf dem Ziffernblock     *keypad-point*
<k0> - <k9>     0 bis 9 auf dem Ziffernblock            *keypad-0* *keypad-9*
<S-...>         Umschalttaste                   *shift* *<S-*
<C-...>         Steuerungstaste                 *control* *ctrl* *<C-*
<M-...>         Alt-Taste oder Meta-Taste       *meta* *alt* *<M-*
<A-...>         dasselbe wie <M-...>            *<A-*
<D-...>         Befehlstaste (nur Macintosh)    *<D-*
<t_xx>          Taste mit dem Eintrag »xx« in der TermCap

I am using Putty with ssh and the following keyboard setting: . . .

enter image description here How can I map the keys of the numeric key pad?

3
  • 1
    click on the tick if my answer helps !! Means a lot !! :D Nov 6, 2016 at 17:23
  • 1
    You should use imap for the insert mode.
    – orbit
    Nov 11, 2016 at 21:24
  • I'm glad you found the answer! Just so you know, it's allowed, and even encouraged to answer your own question (link). But you should post it as an answer rather than editing it into your post. I've edited your answer, but you can see your former answer here. I would encourage you to copy and paste the answer section into a real answer
    – DJMcMayhem
    Nov 11, 2016 at 21:37

2 Answers 2

4

The keypad identifiers have a k* prefix. Like mapping control + numkey 1 to :NerdTree would be

Map <C-k1> :NerdTree<CR>

AFAIK these mappings wont work when the NumLock is off.

also :h keycodes in vim shows a lot more of these keybindings.

EDIT : OP uses PuTTY for ssh-ing into vim. PuTTY has numkeys disabled by default which is the reason why it shows alphabets instead of numericals.

to solve this : PuTTY settings -> Terminal -> Features->put a check mark on "Disable application keypad mode". -> sessions -> save !!

11
  • Thank for the hint: :h keycodes tells me that I have to use <k1> (without C-) but is doesn't work. It seems that k1 is already mapped and I cannot remap the button.
    – musbach
    Nov 4, 2016 at 22:38
  • What do u mean 'k1 is already mapped '?? And any combination (like ctrl, shift, alt) can be used with k* to invoke a command. Nov 4, 2016 at 22:40
  • The NUM 1 is already mapped by a command which duplicates the lines. If I want to map k1 to e.g. dd it doesn't work and the former command is executed.
    – musbach
    Nov 4, 2016 at 22:45
  • Then use k2 😉 or try S-k1 or C-k1 Nov 4, 2016 at 22:47
  • No way. Always th same.
    – musbach
    Nov 4, 2016 at 22:51
1

The default settings of PuTTY are just fine. Do not change anything in PuTTY-> Terminal -> Keyboard (see above) or disable in PuTTY-> Terminal -> Features anything:

enter image description here

You can map in vi the NUM keys in the following way:

inoremap <Esc>Oq 1
inoremap <Esc>Or 2
inoremap <Esc>Os 3
inoremap <Esc>Ot 4
inoremap <Esc>Ou 5
inoremap <Esc>Ov 6
inoremap <Esc>Ow 7
inoremap <Esc>Ox 8
inoremap <Esc>Oy 9
inoremap <Esc>Op 0
inoremap <Esc>On .
inoremap <Esc>OQ /
inoremap <Esc>OR *
inoremap <Esc>Ol +
inoremap <Esc>OS -
inoremap <Esc>OM <Enter>

This setting is an example for using the NUM key as they should be. Of course you can change the mappings as usual.

1
  • I am glad that you could solve your problem. Nice job @musbach. Sorry my help couldnt solve, but it taught me a lot about that topic. Applause to your persistence ! Nov 12, 2016 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.