Wikia

Vim Tips Wiki

Changes: VimLock mode to enter numbers

Edit

Back to page

(Assign tip id + convert to TipNew template)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 3: Line 3:
 
|previous=1563
 
|previous=1563
 
|next=1565
 
|next=1565
|created=May 10, 2008
+
|created=2008
 
|complexity=basic
 
|complexity=basic
 
|author=Benshi
 
|author=Benshi
Line 47: Line 47:
 
</pre>
 
</pre>
   
Now you can press <tt>Ctrl-i</tt> to enter insert mode and map the keys "<tt>a s d f g h j k l ;</tt>" to the digits "<tt>1 2 3 4 5 6 7 8 9 0</tt>". Pressing <tt>Esc</tt> will end this mode and restore the letter keys. Since <tt>Ctrl-i</tt> is Tab, you can just press the Tab key to enter VimLock mode.
+
Now you can press <code>Ctrl-i</code> to enter insert mode and map the keys "<code>a s d f g h j k l ;</code>" to the digits "<code>1 2 3 4 5 6 7 8 9 0</code>". Pressing <code>Esc</code> will end this mode and restore the letter keys. Since <code>Ctrl-i</code> is Tab, you can just press the Tab key to enter VimLock mode.
   
The mappings assume a QWERTY US keyboard where the <tt>;</tt> key is on the right of <tt>L</tt>. If necessary, change <tt>;</tt> to suit your keyboard.
+
The mappings assume a QWERTY US keyboard where the <code>;</code> key is on the right of <code>L</code>. If necessary, change <code>;</code> to suit your keyboard.
   
 
==References==
 
==References==

Latest revision as of 06:33, July 13, 2012

Tip 1564 Printable Monobook Previous Next

created 2008 · complexity basic · author Benshi · version 7.0


It can be convenient to use the numeric keypad when you need to enter a lot of numbers. However, your keyboard may not have a keypad, or you may not want to move your hands from the home row.

The following script allows you to switch Vim to a special "VimLock" mode (like pressing the Num Lock key). In this mode, pressing keys on the home row (a, s, d, ...) will generate digits (1, 2, 3, ...) rather than letters. Press Escape to exit from VimLock mode.

Put the following in your vimrc:

nnoremap <C-I> :call VimLock(1)<CR>i
function! VimLock(enable)
  if a:enable
    inoremap a 1
    inoremap s 2
    inoremap d 3
    inoremap f 4
    inoremap g 5
    inoremap h 6
    inoremap j 7
    inoremap k 8
    inoremap l 9
    inoremap ; 0
    inoremap <Esc> <Esc>:call VimLock(0)<CR>
  else
    iunmap a
    iunmap s
    iunmap d
    iunmap f
    iunmap g
    iunmap h
    iunmap j
    iunmap k
    iunmap l
    iunmap ;
    iunmap <Esc>
  endif
endfunction

Now you can press Ctrl-i to enter insert mode and map the keys "a s d f g h j k l ;" to the digits "1 2 3 4 5 6 7 8 9 0". Pressing Esc will end this mode and restore the letter keys. Since Ctrl-i is Tab, you can just press the Tab key to enter VimLock mode.

The mappings assume a QWERTY US keyboard where the ; key is on the right of L. If necessary, change ; to suit your keyboard.

ReferencesEdit

CommentsEdit

Around Wikia's network

Random Wiki