Am 10.07.2012 17:06, schrieb rockybalboa4:
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)

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 ""
endfunc

--
Andy

--
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
  • gI I A gA rockybalboa4
    • Re: gI I A gA Andy Wokula

Reply via email to