Skip to content

Instantly share code, notes, and snippets.

@romgrk
Last active May 13, 2016 07:54
Show Gist options
  • Save romgrk/50bdda1ee3041e6d92e9 to your computer and use it in GitHub Desktop.
Save romgrk/50bdda1ee3041e6d92e9 to your computer and use it in GitHub Desktop.
" Author: romgrk | License: JSON-like
" This SHOULD (RFC 2119) go in a $RUNTIME/ftplugin/vim/ directory.
" (personnally I have it in $RUNTIME/after/ftplugin/vim.vim)
" Alt+i in insert mode in vimscript files inserts the next keystroke as vim-notation
" - there are some special keys: e.g.
" <A-i><S-,> inserts '<lt>' literally
" <A-i>i inserts '<SID>' literally
" <A-i>b inserts '<buffer>' literally
let s:leader = '<A-i>'
let s:altkeys = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
let s:altkeys .= '1234567890-=[]{};:''"\,<.>/?!@#$%^&*()_+`~'
let s:ctrlkeys = 'ABCDEFGKLNOPQRSTUVWXYZ1234567890-=[{};:''"\,<.>/?!#$%^&*()_+`~'
" Special keys {{{
unlet! s:specialKeys
let s:specialKeys = [
\ ['<', '<lt>lt>'],
\ ['<CR>', '<lt>CR>'],
\ ['<Tab>', '<lt>Tab>'],
\ ['<Esc>', '<lt>Esc>'],
\ ['<space>', '<lt>space>'],
\ ['<BS>', '<lt>BS>'],
\ ['=', '<lt>C-r>='],
\ ['p', '<lt>Plug>'],
\ ['P', '<lt>Plug>()<Left>'],
\ ['b', '<lt>buffer>'],
\ ['e', '<lt>expr>'],
\ ['s', '<lt>silent>'],
\ ['S', '<lt>SID>'],
\ ['i', '<lt>SID>'],
\ ['u', '<lt>unique>'],
\ ['\', '<lt>Bar>'],
\ [',', '<lt>leader>'],
\ ['j', '<lt>Down>'],
\ ['k', '<lt>Up>'],
\ ['h', '<lt>Left>'],
\ ['l', '<lt>Right>'],
\]
" }}}
fu! s:imap (leader, key, val)
let leader = a:leader
let key = a:key
let val = a:val
execute 'imap <buffer> ' . leader . key . ' ' . val
endfu
for i in range(len(s:altkeys))
let k = s:altkeys[i]
let key = '<A-' . k . '>'
let val = '<lt>' . key[1:]
call s:imap(s:leader, key, val)
endfor
for i in range(len(s:ctrlkeys))
let k = s:ctrlkeys[i]
let key = '<C-'.k.'>'
let val = '<lt>'.key[1:]
call s:imap(s:leader, key, val)
let key = '<C-A-'.k.'>'
let val = '<lt>'.key[1:]
call s:imap(s:leader, key, val)
endfor
for [key, val] in s:specialKeys
call s:imap(s:leader, key, val)
endfor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment