Tuesday, July 10, 2012

gI I A gA

Hi,
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 (http://www.vim.org/scripts/script.php?script_id=2136):
 
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!
        autocmd InsertLeave * call repeat#set('A' . getreg('.') . "\<ESC>", a:count)|augroup! repeatCustom
    augroup END
endfunction
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) 

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: