home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Unix Power ToolsUnix Power ToolsSearch this book

18.11. Text-Input Mode Cursor Motion with No Arrow Keys

Some people don't like to press ESC first to move the cursor while they're using vi. These keymaps change CTRL-h, CTRL-j, CTRL-k, and CTRL-l to do the same things during input mode as the commands h, j, k, and l do in command mode.

NOTE: Is your erase character set to CTRL-h (Section 5.8) outside vi? If it is, mapping CTRL-h (usually labeled BACKSPACE on your keyboard) will change the way CTRL-h works during text-input mode: instead of erasing the characters you've typed since you entered text-input mode, now CTRL-h will move backwards over what you type without erasing it. One workaround is to change your Unix erase character to the DELETE or RUBOUT key by typing the command stty erase '^?' before you start vi. Then your DELETE key will erase what you type, and the BACKSPACE key will jump back over it without deleting.

The lines for your .exrc file (Section 17.30) are as follows:

Figure Go to http://examples.oreilly.com/upt3 for more information on: exrc

map! ^H ^[i
map! ^K ^[ka
map! ^L ^[la
map! ^V
 ^[ja
" Note: the two lines above map ^J (LINEFEED)

That last map takes two lines; it's tricky and may not work right on all versions of vi. No, it isn't a map for CTRL-v, though that's what it looks like. It maps ^J, the LINEFEED key. The ^V comes at the very end of its line. When you're entering that keymap, type CTRL-v and then press LINEFEED or CTRL-j. The cursor will move to the start of the next line; type a SPACE and the rest of the macro. It's a good idea to add the reminder comment (starting with the comment character, a double quote (")), on the line below the map.

NOTE: This map for CTRL-j is obviously something for which the people who wrote my version of vi didn't plan. For example, look at the mess it makes when I ask for a list of my text-input keymaps:

:map!^H      ^H      ^[i
^K      ^K      ^[ka
^L      ^L      ^[la

        ^[ja

Before you use this map on important files, you probably should test it carefully.

-- JP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.