gI I A gA

Showing 1-2 of 2 messages
gI I A gA rockybalboa4 7/10/12 8:06 AM
I have been learning for some time how you could mimick gI-I on the right side of a line specifically with count and . (dot) to repeat. I admit that the trailing whitespace isn't commonly used in text files, but I was sold on the idea that you could remap anything vim. Only recently I created something very hackish that seems to work using repeat.vim (
nnoremap <silent> <expr> A ':<C-u>augroup repeatCustom<bar>execute ''autocmd!''<bar>execute ''autocmd InsertLeave * call repeat#set(''''A'''' . getreg(''''.'''') . "\<lt>ESC>", v:count1)<bar>augroup! repeatCustom''<bar>augroup END<CR>g_' . (v:count ? v:count : '') . 'a'
nnoremap gA A
I can't use a function for everything as you can't end the function in insert mode. Well, I think now that I could actually refactor this for clarity like this:
function! s:A(count)
    augroup repeatCustom
        autocmd InsertLeave * call repeat#set('A' . getreg('.') . "\<ESC>", a:count)|augroup! repeatCustom
    augroup END
nnoremap <silent> <expr> A ':<C-u>call <SID>A(v:count1)<CR>g_' . (v:count ? v:count : '') . 'a'
nnoremap gA A
Is it the best and the simplest way? The only way? (assuming that I don't want to rewrite repeat.vim) 
Re: gI I A gA Andy Wokula 7/11/12 6:53 AM
Very good, just two issues:
- you allow repeat#set() to remap keys returned by getreg('.')
- you do :augroup! while there are active autocmds from that group

nmap A   <Plug>(Append)
nn   gA  A

nmap        <Plug>(Append)      <SID>(Append)
nn <script> <Plug>(LastAppend)  <SID>(Append)<C-A><Esc>

nn <expr><silent> <SID>(Append)  ':<C-U><BS>'. <sid>AppendSetup(). 'g_'. (v:count ? v:count : ''). 'a'

augroup RepeatCustom
augroup End

func! <sid>AppendSetup()
     au! RepeatCustom InsertLeave *  call repeat#set("\<Plug>(LastAppend)", v:count1)| au! RepeatCustom
     return ""