3
edits
(Add instructions to write Toaq in vim with a system keyboard layout) |
(Using an existing keyboard layout: buffer-local + toggle) |
||
Line 139: | Line 139: | ||
== Using an existing keyboard layout == | == Using an existing keyboard layout == | ||
If you already have a Toaq keyboard layout (for example, by following [[Input_methods#XKB|the XKB instructions]]), then you can <code>:source</code> the following script to make vim automatically switch layouts depending on mode. | If you already have a Toaq keyboard layout (for example, by following [[Input_methods#XKB|the XKB instructions]]), then you can <code>:source</code> the following script to make vim automatically switch layouts depending on mode. This functionality is toggled on or off each time you source the script in the same buffer. | ||
'''Follow the TODO instructions to make it work on your system.''' If you use an XKB method, be sure to use the name you gave your layout in evdev.lst and evdev.xml. | '''Follow the TODO instructions to make it work on your system.''' If you use an XKB method, be sure to use the name you gave your layout in evdev.lst and evdev.xml. | ||
{{collapsible|.vimrc-toaq|<pre>" Known issues: | {{collapsible|.vimrc-toaq|<pre>" Known issues: | ||
" 1. Modifiers do not persist through a layout switch. You need to release and re-press Shift for commands like FA | " 1. Modifiers do not persist through a layout switch. You need to release and re-press Shift for commands like FA. | ||
" 2. The cursor disappears when awaiting single-character input to commands like r | " 2. The cursor visually disappears when awaiting single-character input to commands like r | ||
" TODO: You need to choose a layout switching method from the choices below that works best for your system. Desktop Environments have their own methods of tracking and toggling the current keyboard layout. More info: | " TODO: You need to choose a layout switching method from the choices below that works best for your system. Desktop Environments have their own methods of tracking and toggling the current keyboard layout. More info: | ||
Line 157: | Line 157: | ||
function SetNormalLayout() | function SetNormalLayout() | ||
"TODO: | |||
""" Method 1 (Recommended): Native method provided by *your* DE (Example: KDE Plasma 5) | """ Method 1 (Recommended): Native method provided by *your* DE (Example: KDE Plasma 5) | ||
silent call system('qdbus org.kde.keyboard /Layouts setLayout 0') | silent call system('qdbus org.kde.keyboard /Layouts setLayout 0') | ||
Line 169: | Line 170: | ||
function SetToaqLayout() | function SetToaqLayout() | ||
"TODO: | |||
silent call system('qdbus org.kde.keyboard /Layouts setLayout 1') | silent call system('qdbus org.kde.keyboard /Layouts setLayout 1') | ||
"silent call system('setxkbmap toaq -print | xkbcomp - $DISPLAY') | "silent call system('setxkbmap toaq -print | xkbcomp - $DISPLAY') | ||
Line 176: | Line 178: | ||
endfunction | endfunction | ||
augroup | """ End TODO 's """ | ||
if exists("b:toaq_layout_switch") && b:toaq_layout_switch | |||
let b:toaq_layout_switch = 0 | |||
call SetNormalLayout() | |||
redraw | echo "Disabled Toaq layout switching" | |||
else | |||
let b:toaq_layout_switch = 1 | |||
redraw | echo "Enabled Toaq layout switching" | |||
endif | |||
if b:toaq_layout_switch | |||
augroup toaq_layout_switch_group_buflocal | |||
autocmd! * <buffer> | |||
autocmd VimEnter <buffer> call SetNormalLayout() "only matters when using -c | |||
autocmd InsertEnter <buffer> call SetToaqLayout() | |||
autocmd InsertLeave <buffer> call SetNormalLayout() | |||
augroup END | |||
else | |||
autocmd! toaq_layout_switch_group_buflocal * <buffer> | |||
endif | |||
" These autocmds are SPECIAL because <buffer> can only be OR'd with other {aupat}s, but we want buffer-local {aupat}s. | |||
" So instead, they will no-op if they're unwanted. | |||
augroup toaq_layout_switch_group_global | |||
autocmd! | autocmd! | ||
" The '/,\?' specifies search (forward, backward) only | " The '/,\?' specifies search (forward, backward) only | ||
autocmd CmdlineEnter /,\? call SetToaqLayout() | autocmd CmdlineEnter /,\? if exists("b:toaq_layout_switch") && b:toaq_layout_switch | call SetToaqLayout() | endif | ||
autocmd CmdlineLeave /,\? call SetNormalLayout() | autocmd CmdlineLeave /,\? if exists("b:toaq_layout_switch") && b:toaq_layout_switch | call SetNormalLayout() | endif | ||
augroup END | augroup END | ||
Line 199: | Line 221: | ||
endfunction | endfunction | ||
" Normal | if b:toaq_layout_switch | ||
nnoremap <silent> <expr> r "r" .. ToaqGetCharStr() | " Normal | ||
nnoremap <silent> <expr> f "f" .. ToaqGetCharStr() | nnoremap <buffer> <silent> <expr> r "r" .. ToaqGetCharStr() | ||
nnoremap <silent> <expr> F "F" .. ToaqGetCharStr() | nnoremap <buffer> <silent> <expr> f "f" .. ToaqGetCharStr() | ||
nnoremap <silent> <expr> t "t" .. ToaqGetCharStr() | nnoremap <buffer> <silent> <expr> F "F" .. ToaqGetCharStr() | ||
nnoremap <silent> <expr> T "T" .. ToaqGetCharStr() | nnoremap <buffer> <silent> <expr> t "t" .. ToaqGetCharStr() | ||
" Visual | nnoremap <buffer> <silent> <expr> T "T" .. ToaqGetCharStr() | ||
vnoremap <silent> <expr> r "r" .. ToaqGetCharStr() | " Visual | ||
vnoremap <silent> <expr> f "f" .. ToaqGetCharStr() | vnoremap <buffer> <silent> <expr> r "r" .. ToaqGetCharStr() | ||
vnoremap <silent> <expr> F "F" .. ToaqGetCharStr() | vnoremap <buffer> <silent> <expr> f "f" .. ToaqGetCharStr() | ||
vnoremap <silent> <expr> t "t" .. ToaqGetCharStr() | vnoremap <buffer> <silent> <expr> F "F" .. ToaqGetCharStr() | ||
vnoremap <silent> <expr> T "T" .. ToaqGetCharStr() | vnoremap <buffer> <silent> <expr> t "t" .. ToaqGetCharStr() | ||
" Motions | vnoremap <buffer> <silent> <expr> T "T" .. ToaqGetCharStr() | ||
onoremap <silent> <expr> f "f" .. ToaqGetCharStr() | " Motions | ||
onoremap <silent> <expr> F "F" .. ToaqGetCharStr() | onoremap <buffer> <silent> <expr> f "f" .. ToaqGetCharStr() | ||
onoremap <silent> <expr> t "t" .. ToaqGetCharStr() | onoremap <buffer> <silent> <expr> F "F" .. ToaqGetCharStr() | ||
onoremap <silent> <expr> T "T" .. ToaqGetCharStr() | onoremap <buffer> <silent> <expr> t "t" .. ToaqGetCharStr() | ||
onoremap <buffer> <silent> <expr> T "T" .. ToaqGetCharStr() | |||
else | |||
" There's a better solution here: | |||
" https://vi.stackexchange.com/questions/7734/how-to-save-and-restore-a-mapping | |||
" Normal | |||
nunmap <buffer> r | |||
nunmap <buffer> f | |||
nunmap <buffer> F | |||
nunmap <buffer> t | |||
nunmap <buffer> T | |||
" Visual | |||
vunmap <buffer> r | |||
vunmap <buffer> f | |||
vunmap <buffer> F | |||
vunmap <buffer> t | |||
vunmap <buffer> T | |||
" Motions | |||
ounmap <buffer> f | |||
ounmap <buffer> F | |||
ounmap <buffer> t | |||
ounmap <buffer> T | |||
endif | |||
</pre>}} | </pre>}} | ||
You might want to add | You might want to add mappings to your <code>~/.vimrc</code> to quickly source the script: | ||
< | <pre>noremap <Leader>t :source ~/.vimrc-toaq<CR> " toggle in current buffer | ||
noremap <Leader>T :windo source ~/.vimrc_toaq<CR> " toggle in every window</pre> | |||
[[Category:Input methods]] | [[Category:Input methods]] |
edits