Created
July 26, 2012 08:44
-
-
Save mattn/3181042 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let s:marks = [] | |
function! s:multi_on(bang, ...) | |
redir => marks | |
silent marks | |
redir END | |
let mx = '^\s*\(\S\+\)\s\+\(\d\+\)\s\+\(\d\+\)\s.*' | |
let s:marks = [] | |
for m in map(split(marks, "\n")[1:], 'matchlist(v:val, mx)[1:3]') | |
if index(a:000, m[0]) != -1 | |
call add(s:marks, m) | |
endif | |
endfor | |
augroup MultiGroup | |
au! | |
au InsertCharPre <buffer> call s:multi_push() | |
au InsertLeave <buffer> call s:multi_off() | |
augroup END | |
startinsert | |
if a:bang == '!' | |
call feedkeys("\<right>", 'n') | |
endif | |
endfunction | |
function! s:multi_off() | |
augroup MultiGroup | |
au! | |
augroup END | |
endfunction | |
let s:char = '' | |
function! s:multi_push() | |
let s:char .= v:char | |
call feedkeys("\<plug>(multi-update)", 'm') | |
endfunction | |
function! s:multi_update() | |
let pos = getpos('.') | |
for m in s:marks | |
let line = getline(m[1]) | |
let line = m[2] > 0 ? (line[:m[2]-1].s:char.line[m[2]:]) : (s:char.line[m[2]:]) | |
call setline(m[1], line) | |
for r in s:marks | |
if r[1] == m[1] && r[2] > m[2] | |
let r[2] += len(s:char) | |
endif | |
endfor | |
let m[2] += len(s:char) | |
endfor | |
call setpos('.', pos) | |
let s:char = '' | |
return '' | |
endfunction | |
command! -nargs=+ -bang Multi call s:multi_on('<bang>', <f-args>) | |
inoremap <silent> <plug>(multi-update) <c-r>=<sid>multi_update()<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great!