Sometimes I change input source (keyboard language) and my number buttons get mapped to rarely used UTF-8 symbols, e.g. 1 gets changed to ą, 2 to č, 3 to ę, etc.

I have managed to map them in normal mode to numbers by using these mappings:

map     ą           1
map     č           2
map     ę           3
map     ė           4
map     į           5
map     š           6
map     ų           7
map     ū           8
map     „           9
map     “           0

However these mappings don't work in command-line mode (after pressing :) - original symbols are used. Is there a way to tell VIM that when I enter ą in command-line mode I mean 1?

  • 2
    Doesn't help for command-line mode, but you might like to take a look at :help 'langmap', to handle this in normal mode without having 10 separate mappings. Try :set langmap=ą1,č2,ę3,ė4,į5,š6,ų7,ū8,„9,“0
    – Rich
    Commented Feb 25, 2021 at 13:31
  • 1
    @Rich Wow, that's even better oO Thank you!
    – niekas
    Commented Feb 25, 2021 at 13:39
  • @Rich I came here to talk about langmap... You should turn that into an answer. (Even if it doesn't address command-line mode directly.)
    – filbranden
    Commented Feb 25, 2021 at 15:12

1 Answer 1


The :map command only creates mappings for normal, visual, select, and operator-pending modes. To add commandline mappings you need to use :cmap in addition to the :map.

:help map-modes has a table describing which map command maps in which mode:

     COMMANDS                    MODES
:map   :noremap  :unmap     Normal, Visual, Select, Operator-pending
:nmap  :nnoremap :nunmap    Normal
:vmap  :vnoremap :vunmap    Visual and Select
:smap  :snoremap :sunmap    Select
:xmap  :xnoremap :xunmap    Visual
:omap  :onoremap :ounmap    Operator-pending
:map!  :noremap! :unmap!    Insert and Command-line
:imap  :inoremap :iunmap    Insert
:lmap  :lnoremap :lunmap    Insert, Command-line, Lang-Arg
:cmap  :cnoremap :cunmap    Command-line
:tmap  :tnoremap :tunmap    Terminal-Job

You can use a for loop if you don't want to define all map commands more than once:

let s:maps = {
    \ 'ą': '1',
    \ 'č': '2',
\ }
for lhs, rhs in items(s:maps)
    exe printf(':map %s %s', lhs, rhs)
    exe printf(':cmap %s %s', lhs, rhs)

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.