The question is actually rather short, don't be afraid. :-)
I'm Russian, and so to tweak Vim in a way it will understand its commands even if a Russian language is currently active, I have the following part in my vimrc:
set keymap=russian-jcukenwin " jcukenwin for Windows and Linux,
" jcukenmac for macOS
set iminsert=0
set imsearch=0
set laststatus=2
" To change the color of statusline when keyboard layout is changed
function MyKeyMapHighlight()
if &iminsert == 0
highlight tabLine ctermfg=darkBlue guifg=darkBlue guibg=darkGrey
highlight StatusLine ctermfg=darkBlue guifg=darkBlue guibg=Gray30
else
highlight tabLine ctermfg=darkBlue guifg=darkBlue guibg=darkGrey
highlight StatusLine ctermfg=darkRed guifg=darkRed guibg=Gray30
endif
endfunction
call MyKeyMapHighlight()
autocmd WinEnter * :call MyKeyMapHighlight()
" To switch languages by using Control-Space instead of C-^ (C-6 on Windows)
cmap <silent> <C-Space> <C-^>
imap <silent> <C-Space> <C-^>X<Esc>:call MyKeyMapHighlight()<CR>a<C-H>
nmap <silent> <C-Space> a<C-^><Esc>:call MyKeyMapHighlight()<CR>
vmap <silent> <C-Space> <Esc>a<C-^><Esc>:call MyKeyMapHighlight()<CR>gv
The only part which interests me currently is mappings. I'm trying to understand where to put and where to not put spaces when we define mappings. For example, if I delete spaces after <C-Space>
, it doesn't work.
" Doesn't work
cmap <silent> <C-Space><C-^>
imap <silent> <C-Space><C-^>X<Esc>:call MyKeyMapHighlight()<CR>a<C-H>
nmap <silent> <C-Space>a<C-^><Esc>:call MyKeyMapHighlight()<CR>
vmap <silent> <C-Space><Esc>a<C-^><Esc>:call MyKeyMapHighlight()<CR>gv
- Why the second version doesn't work?
- Are there explanations/rules/best practices where to put and not put spaces when we define mappings in Vim?