Created
June 11, 2020 19:02
-
-
Save Houl/31d1340c2de566de071bd02e6049382e to your computer and use it in GitHub Desktop.
Sticky digraphs
This file contains 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
" File: D2567.vim | |
" Created: 2020 Jun 11 | |
" Last Change: 2020 Jun 11 | |
" Version: 0.1 | |
" Author: Andy Wokula <anwoku@yahoo.de> | |
" License: Vim License, see :h license | |
" Provides: sticky-digraphs | |
" Usage: (Insert mode) | |
" | |
" Type <C-K><C-K> to enter sticky digraphs mode, hit <Esc> or <C-K> to | |
" stop. In "sticky digraphs" mode, all keys you type enter digraphs. | |
" The mode does not time out automatically. | |
" | |
" Example: | |
" <C-K><C-K>abcdef is short for <C-K>ab<C-K>cd<C-D>ef | |
" | |
imap <C-K> <Plug>(sticky-digraphs) | |
imap <Plug>(sticky-digraphs) <SID>__<lt>C-K>__ | |
imap <SID>__<lt>C-K>__<C-K> <SID>(init)<SID>__digr0__ | |
ino <SID>__<lt>C-K>__ <C-K> | |
imap <expr> <SID>(init) <sid>Init() | |
imap <SID>__digr0__<C-K> <Nop> | |
imap <SID>__digr0__<Esc> <Nop> | |
imap <expr> <SID>__digr0__ <sid>Getch(0) ? '<SID>__digr1__' : '<C-R>_<SID>__digr0__' | |
imap <SID>__digr1__<C-K> <Nop> | |
imap <SID>__digr1__<Esc> <Nop> | |
ino <expr><script> <SID>__digr1__ <sid>Getch(1) ? '<C-K>'. <sid>Chars(). '<SID>__digr0__' : '<C-R>_<SID>__digr1__' | |
func! <sid>Init() | |
let s:chars = ['', ''] | |
return '' | |
endfunc | |
func! <sid>Getch(n) | |
let chr = getchar(1) ? s:GetChar() : "" | |
if chr != "" | |
let s:chars[a:n] = chr | |
return 1 | |
else | |
return 0 | |
endif | |
endfunc | |
func! <sid>Chars() | |
return join(s:chars, '') | |
endfunc | |
func! s:GetChar() | |
let chr = getchar() | |
return chr != 0 ? nr2char(chr) : chr | |
endfunc | |
" vim:et: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment