Vim Tips Wiki
(Remove html character entities)
(Change <tt> to <code>, perhaps also minor tweak.)
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=503
 
|id=503
 
|previous=502
 
|previous=502
 
|next=506
 
|next=506
|created=July 3, 2003
+
|created=2003
 
|complexity=advanced
 
|complexity=advanced
|author=Michael Metzger
+
|author=
|version=5.7
+
|version=6.0
 
|rating=43/15
 
|rating=43/15
 
|category1=Terminals
 
|category1=Terminals
 
|category2=
 
|category2=
 
}}
 
}}
  +
This tip contains information on using Vim over PuTTY.
Purpose: Add support for {rhs} of keyboard numeric keypad while in vim insert mode and using PuTTY as a SSH terminal connection.
 
   
  +
[http://www.chiark.greenend.org.uk/~sgtatham/putty/ PuTTY] is a terminal emulator for Windows. It is commonly used as an SSH client to connect to a Unix-based server using the secure shell protocol. Console Vim (not gvim) can be run on the server, using PuTTY as the terminal.
What to do: Add these mappings to your vimrc or gvimrc. PuTTY's default terminal type is xterm. Check your settings or just echo $TERM at the command prompt on most unix systems to verify xterm type.
 
   
 
PuTTY acts as an xterm. Check your settings or just <code>echo $TERM</code> at the command prompt on most Unix systems to verify the xterm type.
Code to add to [[vimrc]]:
 
   
  +
==Using the numeric keypad==
<pre>
 
  +
Why do letters show up when I try to enter numbers from the keypad? Why doesn't the numpad work as expected? Why does the NumLock key bring up help.txt?
:imap ^[Oq 1
 
:imap ^[Or 2
 
:imap ^[Os 3
 
:imap ^[Ot 4
 
:imap ^[Ou 5
 
:imap ^[Ov 6
 
:imap ^[Ow 7
 
:imap ^[Ox 8
 
:imap ^[Oy 9
 
:imap ^[Op 0
 
:imap ^[On .
 
:imap ^[OQ /
 
:imap ^[OR *
 
:imap ^[Ol +
 
:imap ^[OS -
 
</pre>
 
   
  +
These confusing things happen when PuTTY is in "application keypad mode".
==Comments==
 
You might also want to include the mappings for the normal mode as well. For example, going to a specific line
 
#+shift G will not work unless you put these additional mappings in _vimrc.
 
:map ^[Oq 1
 
:map ^[Or 2
 
:map ^[Os 3
 
:map ^[Ot 4
 
:map ^[Ou 5
 
:map ^[Ov 6
 
:map ^[Ow 7
 
:map ^[Ox 8
 
:map ^[Oy 9
 
:map ^[Op 0
 
   
  +
PuTTY can be configured so that keys on the numeric keypad (including NumLock) will send an escape sequence ("application keypad mode"), ''or'' will behave as a standard number pad (when NumLock is on, send the characters <code>[0-9/*-+.]</code>; otherwise, send the codes for the cursor movement keys).
----
 
Sadly, this does not work for me (vim v6.1.265, TERM=xterm). Using these mappings, vim resorts to the regular behaviour of inserting a new character on the previous line.
 
   
  +
For use in Vim, you want to disable application keypad mode:
----
 
  +
*Run PuTTY Configuration.
Additionally, those of you that are having issues with the keypad can remap it using the following command sequence in your vimrc file:
 
  +
*In the left pane, select Terminal, Features.
:imap ^[0A <Up>
 
  +
*Put a check mark next to "Disable application keypad mode".
:imap ^[0A <Down>
 
  +
*In the left pane, select Session.
:imap ^[0A <Left>
 
  +
*Save the settings.
:imap ^[0A <Right>
 
   
  +
Now the NumLock key and the numbers on the numpad should work in Vim, as expected.
These settings also seemed to correct the quirk of the mode text (or whatever it is properly called: --INSERT--) not showing up at the bottom of the screen when in insert mode.
 
   
  +
'''Explanation''' If PuTTY uses application keypad mode, pressing a key on the keypad (including NumLock), causes an [[wikipedia:Escape sequence|escape sequence]] to be sent to Vim; the Esc and following characters will cause many confusing things to occur in your Vim session.
----
 
  +
Maybe a simpler way to do this in PuTTY's settings: Set "Disable application keypad mode" under Terminal-->Features.
 
  +
==See also==
  +
*[[Invert the number row keys for faster typing]]
  +
*[[VimLock mode to enter numbers]]
  +
 
==Comments==
  +
May rename this tip so any information relevant to using PuTTY can be placed here.
  +
  +
The original tip was a confused suggestion to define certain mappings so that Vim recognizes the escape sequences generated when keys on the numeric keypad are pressed, if the keypad is set to "application keypad mode".
  +
  +
For example, in application keypad mode, pressing the <code>1</code> key on the numeric keypad causes PuTTY to send the escape sequence <code><Esc>Oq</code> (three byes). Pressing the NumLock key similarly generates an escape sequence.
  +
  +
It is possible to have Vim interpret the escape sequences using the following mappings (but this is '''not necessary''' – see tip):
 
<pre>
 
: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 -
 
</pre>
   
 
----
 
----
  +
Hmm, this may be true, but a mapping or similar method would allow you to distinguish between <k1> and 1, <kEnter> and <CR>, <kDivide> and /, etc. Perhaps we should clean up this mapping and present it as a viable alternative (I'm interested in this because I'm having trouble even on Windows gvim mapping <kEnter> to something different than <Enter>). --[[User:Fritzophrenic|Fritzophrenic]] 15:32, 17 July 2009 (UTC)
I'm using :
 
:imap <Esc>Oq 1
 
:imap <Esc>Or 2
 
:imap <Esc>Os 3
 
:imap <Esc>Ot 4
 
:imap <Esc>Ou 5
 
:imap <Esc>Ov 6
 
:imap <Esc>Ow 7
 
:imap <Esc>Ox 8
 
:imap <Esc>Oy 9
 
:imap <Esc>Op 0
 
:imap <Esc>On .
 
:imap <Esc>OQ /
 
:imap <Esc>OR *
 
:imap <Esc>Ol +
 
:imap <Esc>OS -
 
   
 
----
 
----
  +
This tip should remain here! After a while struggling with this very problem with vnc viewer 4.1.3 under XP with a Debian lenny vnc4server 4.1.1+X4.3.0-31, this vim remapping is the only solution which work. I hope using the vnc keyword should help others who has this problem to find this solution, as I found it by mere luck, writing a post on the vnc users mailing list and seeking for putty related examples and solutions. --LoneWolf, 9:32, 23 december 2009 (GMT)

Revision as of 05:33, 13 July 2012

Tip 503 Printable Monobook Previous Next

created 2003 · complexity advanced · version 6.0


This tip contains information on using Vim over PuTTY.

PuTTY is a terminal emulator for Windows. It is commonly used as an SSH client to connect to a Unix-based server using the secure shell protocol. Console Vim (not gvim) can be run on the server, using PuTTY as the terminal.

PuTTY acts as an xterm. Check your settings or just echo $TERM at the command prompt on most Unix systems to verify the xterm type.

Using the numeric keypad

Why do letters show up when I try to enter numbers from the keypad? Why doesn't the numpad work as expected? Why does the NumLock key bring up help.txt?

These confusing things happen when PuTTY is in "application keypad mode".

PuTTY can be configured so that keys on the numeric keypad (including NumLock) will send an escape sequence ("application keypad mode"), or will behave as a standard number pad (when NumLock is on, send the characters [0-9/*-+.]; otherwise, send the codes for the cursor movement keys).

For use in Vim, you want to disable application keypad mode:

  • Run PuTTY Configuration.
  • In the left pane, select Terminal, Features.
  • Put a check mark next to "Disable application keypad mode".
  • In the left pane, select Session.
  • Save the settings.

Now the NumLock key and the numbers on the numpad should work in Vim, as expected.

Explanation If PuTTY uses application keypad mode, pressing a key on the keypad (including NumLock), causes an escape sequence to be sent to Vim; the Esc and following characters will cause many confusing things to occur in your Vim session.

See also

Comments

May rename this tip so any information relevant to using PuTTY can be placed here.

The original tip was a confused suggestion to define certain mappings so that Vim recognizes the escape sequences generated when keys on the numeric keypad are pressed, if the keypad is set to "application keypad mode".

For example, in application keypad mode, pressing the 1 key on the numeric keypad causes PuTTY to send the escape sequence <Esc>Oq (three byes). Pressing the NumLock key similarly generates an escape sequence.

It is possible to have Vim interpret the escape sequences using the following mappings (but this is not necessary – see tip):

: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 -

Hmm, this may be true, but a mapping or similar method would allow you to distinguish between <k1> and 1, <kEnter> and <CR>, <kDivide> and /, etc. Perhaps we should clean up this mapping and present it as a viable alternative (I'm interested in this because I'm having trouble even on Windows gvim mapping <kEnter> to something different than <Enter>). --Fritzophrenic 15:32, 17 July 2009 (UTC)


This tip should remain here! After a while struggling with this very problem with vnc viewer 4.1.3 under XP with a Debian lenny vnc4server 4.1.1+X4.3.0-31, this vim remapping is the only solution which work. I hope using the vnc keyword should help others who has this problem to find this solution, as I found it by mere luck, writing a post on the vnc users mailing list and seeking for putty related examples and solutions. --LoneWolf, 9:32, 23 december 2009 (GMT)