Useful mapping to write some Spanish words in Vim

Usually I write on an UK keyboard and just change the keyboard layout when I need to type some Spanish text. This is easy and handy, just pressing alt + shift I’m able to change the layout.

Recently I’ve started to help with the translation of Perl Maven Tutorial to Spanish. Problem here is that code and Spanish text is mixed so I have to switch the layout constantly and turns out to be a nightmare. I could just type using Spanish keyboard layout but coding in general becomes tougher and Vim commands in particular become hell. (How was I able to do this for so many years?)

So I came across with some simple mappings that allow me to write most Spanish words I might need keeping the UK keyboard layout:

function! SpanishMap()
  if (g:spanishMap)
    iunmap 'a| iunmap 'e| iunmap 'i| iunmap 'o| iunmap 'u
    iunmap ;a| iunmap ;e| iunmap ;i| iunmap ;o| iunmap ;u
    inoremap 'a á| inoremap 'e é| inoremap 'i í| inoremap 'o ó| inoremap 'u ú
    inoremap ;a ña| inoremap ;e ñe| inoremap ;i ñi| inoremap ;o ño| inoremap ;u ñu
  let g:spanishMap = !g:spanishMap
let g:spanishMap = 0
call SpanishMap()
noremap <C-F12> :call SpanishMap()<CR>

So now I can type words in the same way I would do on a Spanish keyboard. Writing something like:

Con estas razones perd‘ia el pobre caballero el juicio, y desvel‘abase por entenderlas y desentra;arles el sentido,

I’ll get:

Con estas razones perdía el pobre caballero el juicio, y desvelábase por entenderlas y desentrañarles el sentido,

A minor bug that appears, if I try to quote something like ‘a wrong quote’ I’ll get something like á wrong quote’.

I can still use double quotes or disable it temporarily by using ctrl + F12, so it is good enough to me :)

Pedal for Vim

Awesome idea:

VIM Clutch is a hardware pedal for improved text editing speed for users of the magnificent VIM text editor (1, 2). When the pedal is pressed down, the pedal types “i” causing VIM to go into Insert Mode. When released, it types and you are back in Normal Mode.

VIM Clutch by Aleksandr Levchuk



> #!/usr/bin/perl
> use strict;
> use David;
> print David::imagination;
< Comment! >
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||