Skip to content

Instantly share code, notes, and snippets.

@raa0121
Forked from mopp/smart!.vim
Last active December 21, 2015 06:19
Show Gist options
  • Save raa0121/6263182 to your computer and use it in GitHub Desktop.
Save raa0121/6263182 to your computer and use it in GitHub Desktop.
let lst = [ ['<', "smartchr#loop(' < ', ' << ', '<')" ],
\ ['>', "smartchr#loop(' > ', ' >> ', ' >>> ', '>')"],
\ ['+', "smartchr#loop(' + ', ' ++ ', '+')"],
\ ['-', "smartchr#loop(' - ', ' -- ', '-')"],
\ ['/', "smartchr#loop(' / ', '//', '/')"],
\ ['&', "smartchr#loop(' & ', ' && ', '&')"],
\ ['%', "smartchr#loop(' % ', '%')"],
\ ['*', "smartchr#loop(' * ', '*')"],
\ ['<Bar>', "smartchr#loop(' | ', ' || ', '|')"],
\ [',', "smartchr#loop(', ', ',')"]]
for i in lst
call smartinput#map_to_trigger('i', i[0], i[0], i[0])
call smartinput#define_rule({ 'char' : i[0],
\ 'at' : '\%#',
\ 'input' : '<C-R>=' . i[1] . '<CR>'})
call smartinput#define_rule({ 'char' : i[0],
\ 'at' : '^\([^"]*"[^"]*"\)*[^"]*"[^"]*\%#',
\ 'input' : i[0]})
call smartinput#define_rule({ 'char' : i[0],
\ 'at' : '^\([^'']*''[^'']*''\)*[^'']*''[^'']*\%#',
\ 'input' : i[0] })
endfor
call smartinput#define_rule({ 'char' : '>',
\ 'at ' : ' < \%#',
\ 'input' : '<BS><BS><BS><><Left>'})
call smartinput#map_to_trigger('i', '=', '=', '=')
call smartinput#define_rule({ 'char' : '=',
\ 'at' : '\%#',
\ 'input' : "<C-R>=smartchr#loop(' = ', ' == ', '=')<CR>"})
call smartinput#define_rule({ 'char' : '=',
\ 'at' : '[&+-/<>|] \%#',
\ 'input' : '<BS>= '})
call smartinput#define_rule({ 'char' : '=',
\ 'at' : '!\%#',
\ 'input' : '= '})
call smartinput#define_rule({ 'char' : '=',
\ 'at' : '^\([^"]*"[^"]*"\)*[^"]*"[^"]*\%#',
\ 'input' : '='})
call smartinput#define_rule({ 'char' : '=',
\ 'at' : '^\([^'']*''[^'']*''\)*[^'']*''[^'']*\%#',
\ 'input' : '='})
call smartinput#map_to_trigger('i', '<BS>', '<BS>', '<BS>')
call smartinput#define_rule({ 'char' : '<BS>',
\ 'at' : '(\s*)\%#',
             \ 'input' : '<C-O>dF(<BS>'})
call smartinput#define_rule({ 'char' : '<BS>',
\ 'at' : '{\s*}\%#',
\ 'input' : '<C-O>dF{<BS>'})
call smartinput#define_rule({ 'char' : '<BS>',
\ 'at' : '<\s*>\%#',
\ 'input' : '<C-O>dF<<BS>'})
call smartinput#define_rule({ 'char' : '<BS>',
\ 'at' : '\[\s*\]\%#',
\ 'input' : '<C-O>dF[<BS>'})
for op in ['<', '>', '+', '-', '/', '&', '%', '*', '|']
call smartinput#define_rule({ 'char' : '<BS>',
\ 'at' : ' ' . op . ' #/%',
\ 'input' : '<BS><BS><BS>'})
endfor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment