I write in English and Swedish in vim and have the lines below in my .vimrc to switch to and from a pseudo-Swedish keyboard layout. Basically some keys are remapped with inoremmap when doing <Leader>s to output Swedish characters, and characters that are masked by this are reached by hitting the key twice. <Leader>e undoes these mappings to return to English typing. This all works fine except for with the r operation. For example, when the Swedish mappings are in effect, r[ does not change the letter to å, but to [. How can I make these mappings also affect the r operation?

Note that I do not want to use the OS's keyboard switch since this would effect operations in normal mode.

" Switch to Swedish
function! SweType()
  set spelllang=sv
  inoremap ; ö
  inoremap ;; ;
  inoremap : Ö
  inoremap :: :
  inoremap [ å
  inoremap { Å
  inoremap ' ä
  inoremap '' '
  inoremap " Ä
  inoremap "" "
  inoremap [[ [
  inoremap {{ {
nmap <Leader>s :<C-U>call SweType()<CR>

" Switch to English
function! EngType()
  set spelllang=en_us
  inoremap ; ;
  iunmap ;;
  inoremap : :
  iunmap ::
  inoremap [ [
  iunmap [[
  inoremap { {
  iunmap {{
  inoremap ' '
  iunmap ''
  inoremap " "
  iunmap ""
nmap <Leader>e :<C-U>call EngType()<CR>
  • This might help: :help 'langmap'. Commented Nov 18, 2015 at 15:39

1 Answer 1


You should be able to remap the whole sequence of keys in normal mode :

nnoremap r[ rå

Edited the answer, as I'm not sure in which mode we are when we hit r. Maybe a sub mode of insert mode that is left as soon as another key is pressed.

  • Isn't the mode your in after pressing r called operator pending mode or so? Commented Nov 18, 2015 at 16:06
  • 1
    I don't know in which mode we are when we hit r but as far I as I know there's no mapping for it (inoremap, vnoremap, cnoremap... have no effect). As for the operator pending mode, I think it's something else. When you hit the key of an operator (d to delete, c to cut, s to substitute etc.), vim waits for a movement to know on which characters it must act. I think that the term operator pending mode refers to that moment. But maybe I misunderstood the concept.
    – saginaw
    Commented Nov 18, 2015 at 16:37
  • 1
    The text that is between your cursor and the position you reach after you give a movement could be considered as an object, on which the operator acts. You can define your own objects with the onoremap command. It's explained in more details here : learnvimscriptthehardway.stevelosh.com/chapters/15.html
    – saginaw
    Commented Nov 18, 2015 at 16:38

Your Answer

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

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