call lexima#set_default_rules() call lexima#insmode#map_hook('before', '', '') call lexima#insmode#map_hook('before', '', '') let s:rules = {} " common let s:rules._ = [] let s:rules._ += [ \ { 'char': '', 'at': '\%#\s*)', 'leave': ')' }, \ { 'char': '', 'at': '\%#\s*\}', 'leave': '}' }, \ { 'char': '', 'at': '\%#\s*\]', 'leave': ']' }, \ { 'char': '', 'at': '\%#\s*>', 'leave': '>' }, \ { 'char': '', 'at': '\%#\s*`', 'leave': '`' }, \ { 'char': '', 'at': '\%#\s*"', 'leave': '"' }, \ { 'char': '', 'at': '\%#\s*''', 'leave': '''' }, \ ] let s:rules._ += [ \ { 'char': '<', 'at': '\<\h\w*\%#', 'input_after': '>' }, \ { 'char': '', 'at': '<\%#>', 'delete': '>' }, \ { 'char': '>', 'at': '\%#>', 'leave': '>' }, \ { 'char': '', 'at': '\%#\s*>', 'leave': '>' }, \ ] " python let s:rules.python = [] let s:rules.python += [ \ { 'char': '_', 'at': '\W\+_\%#', 'input': '_', 'input_after': '__' }, \ { 'char': '', 'at': '__\%#__', 'input': '', 'delete': 2 }, \ { 'char': '', 'at': '\%#__', 'leave': 2 }, \ ] " help let s:rules.help = [] let s:rules.help += [ \ { 'char': '*', 'input': '*', 'input_after': '*' }, \ { 'char': '*', 'at': '\%#\*', 'leave': '*' }, \ { 'char': '', 'at': '|\%#|', 'delete': '|' }, \ { 'char': '', 'at': '\*\%#\*', 'delete': '*' }, \ { 'char': '', 'at': '\%#|', 'leave': '|' }, \ { 'char': '', 'input': '|', 'input_after': '|' }, \ { 'char': '', 'at': '\%#|', 'leave': '|' }, \ { 'char': '', 'at': '\%#\*', 'leave': '*' }, \ ] " toml " NOTE: it is using vim's bug. see also vim-jp/issues#1380 let s:rules.toml = [] let s:rules.toml += [ \ { 'char': '', 'at': "'''\\n\\_^\\%#'''", 'input': 'zz"_D', 'input_after': '' }, \ ] " vim " from https://github.com/thinca/config/blob/5413e42a18/dotfiles/dot.vim/vimrc#L2755 function! s:vim_input_bslash() abort let base = 'd0a%s ' let disable_smartindent_string = ':setlocal indentkeys-=oa' \ .. '%s:setlocal indentkeys+=oa' return printf(disable_smartindent_string, \ printf(base, repeat('', g:vim_indent_cont)) \ ) endfunction let s:rules.vim = [] let s:rules.vim += [ \ { 'char': '', 'at': '{\%#}', 'input': s:vim_input_bslash(), 'input_after': ' ' }, \ { 'char': '', 'at': '{\%#$', 'input': s:vim_input_bslash(), 'input_after': ' }' }, \ { 'char': '', 'at': '(\%#)', 'input': s:vim_input_bslash(), 'input_after': ' ' }, \ { 'char': '', 'at': '(\%#$', 'input': s:vim_input_bslash(), 'input_after': ' )' }, \ { 'char': '', 'at': '\[\%#\]', 'input': s:vim_input_bslash(), 'input_after': ' ' }, \ { 'char': '', 'at': '\[\%#$', 'input': s:vim_input_bslash(), 'input_after': ' \]' }, \ ] " markdown let s:rules.markdown = [] " smart itemize indent let s:rules.markdown += [ \ { 'char': '', 'at': '^\s*[-*]\s*\%#$', 'input': '' }, \ { 'char': '', 'at': '^\s*[-*]\s*\%#$', 'input': '' }, \ ] " smart checkbox " let s:rules.markdown += [ " \ { 'char': '[', 'at': '^\s*[-*]\s*\%#$', 'input': '[]' }, " \ { 'char': 'x', 'at': '^\s*[-*]\s*\[ \]\%#$', 'input': 'x' }, " \ ] " typescript let s:rules.typescript = [] let s:rules.typescript += [ \ { 'char': '>', 'at': '([a-zA-Z, ]*>\%#)', 'delete': ')', 'input': ') => {', 'input_after': '}' }, \ ] let s:rules.typescriptreact = copy(s:rules.typescript) function! s:lexima_init() abort for [filetype, rules] in items(s:rules) for val in rules if filetype !=# '_' && type(filetype) == v:t_string let base = { 'filetype': filetype } else let base = {} endif call lexima#add_rule(extend(base, val)) endfor endfor endfunction call s:lexima_init() " from https://github.com/yuki-yano/dotfiles/blob/9bfee6c807/.vimrc#L3335 function! s:lexima_alter_command(original, altanative) abort let input_space = '' .. a:altanative .. '' let input_cr = '' .. a:altanative .. '' let rule = { \ 'mode': ':', \ 'at': '^\(''<,''>\)\?' .. a:original .. '\%#', \ } call lexima#add_rule(extend(rule, { 'char': '', 'input': input_space })) call lexima#add_rule(extend(rule, { 'char': '', 'input': input_cr })) endfunction command! -nargs=+ LeximaAlterCommand call lexima_alter_command() LeximaAlterCommand hg\%[rep] helpgrep LeximaAlterCommand bon\%[ew] botrightnew LeximaAlterCommand hea\%[lthcheck] checkhealth LeximaAlterCommand cap\%[ture] Capture LeximaAlterCommand capturej\%[son] CaptureJson LeximaAlterCommand capj\%[son] CaptureJson LeximaAlterCommand quic\%[krun] QuickRun LeximaAlterCommand qr\%[un] QuickRun LeximaAlterCommand fixw\%[hitespace] FixWhitespace LeximaAlterCommand dd\%[u] Ddu LeximaAlterCommand dei\%[n] Dein LeximaAlterCommand deinr\%[eadme] DeinReadme LeximaAlterCommand readm\%[e] DeinReadme LeximaAlterCommand colo\%[rscheme] ColorScheme LeximaAlterCommand ra\%[ndomcolorscheme] RandomColorScheme LeximaAlterCommand todo\%[list] TodoList LeximaAlterCommand mi\%[ninote] MiniNote LeximaAlterCommand not\%[e] MiniNote LeximaAlterCommand deinu\%[pdatemine] DeinUpdateMine