Created
September 30, 2023 00:36
-
-
Save wolandark/6af85607ee26055bb519ac69d03edb07 to your computer and use it in GitHub Desktop.
Settings for using an alternative keymapping in Vim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let g:alt_keymap = 'persian' " Change to your prefered keymap located at $VIMRUNTIME/keymap/ | |
let g:alt_enabled = 1 | |
function! CallToggleKeymap() | |
if g:alt_enabled | |
call ToggleKeymap() | |
endif | |
endfunction | |
function! ToggleKeymap() | |
if &keymap == '' | |
execute 'setlocal keymap=' . g:alt_keymap | |
silent !echo -ne "\033]12;cyan\007" | |
redraw! | |
autocmd VimLeave * silent !echo -ne "\033]112\007" | |
else | |
set keymap= | |
silent !echo -ne "\033]112\007" | |
redraw! | |
endif | |
endfunction | |
command! SwitchKeymap call CallToggleKeymap() | |
function! ListKeymapFiles() | |
:Explore $VIMRUNTIME/keymap/ | |
endfunction | |
" Optionally create custom key mappings to SwitchKeymap command |
keymap-2023-09-30_05.36.13.mp4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note on the gist
The escape sequences are there to change the cursor color when the keymap changes. I chose cyan.
This is not needed and can be removed from the functions.
Essentially all that is needed is to provide a truthy value to
g:alt_enabled
, such as1
and to set your keymap variable ing:alt_keymap
.How it works
g:alt_enabled
is truthy and then call the main function.:set keymap=
sets the keymap to default, which is English. If the check comes out true, we switch the keymap to the value of theg:alt_keymap
and send escape codes to the terminal for a different cursor color.Vim can't change the cursor color or shape when running in the terminal.
VimLeave
and also reset the cursor color when the default empty string keymap is set.redraw
command is essential, even though it makes the terminal flash for a second, without it statuslines and other things will look broken.There is an easier way to change cursor color for Gvim, but I don't use Gvim. See
:h guicursor
and:h lcursor
.Commands:
To Toggle Keymaps:
:CallToggleKeymap
||:SwitchKeymap
To Browse Available Keymaps"
:ListKeymapFiles
Keybinding
inoremap <C-p> <C-o>:SwitchKeymap<CR>
nnoremap <C-p> :SwitchKeymap<CR>
Keep in mind that
C-p
in insert mode is bound to match previous (see:h i_CTRL-P
) and in normal mode does the same ask
.You may want to use other keys.
About Escape Codes
Most decent terminals support changing the cursor shape and color with ANSI escape codes.
Terminals such as but not limited to:
etc ...
You can test your terminal with these commands:
printf '\e]12;rgb:ff/88/cc\007'
should give you a pink cursorecho -ne "\033]12;cyan\007"
should give you a cyan cursor just like in the gist