Create a gist now

Instantly share code, notes, and snippets.

@wellle /append.vim
Last active Apr 6, 2016

Commands to append after (and insert before) any text object. http://redd.it/1z93ww
nnoremap <silent> <Leader>a :set opfunc=Append<CR>g@
nnoremap <silent> <Leader>i :set opfunc=Insert<CR>g@
function! Append(type, ...)
call feedkeys("`]a", 'n')
endfunction
function! Insert(type, ...)
call feedkeys("`[i", 'n')
endfunction
@wellle
Owner

Example:

Route::get('/create', 'GamesController@index');

From beginning of line, typing \ai'_foo leads to:

Route::get('/create_foo', 'GamesController@index');

Following up with \ii)1, leads to:

Route::get(1, '/create_foo', 'GamesController@index');
@wellle
Owner

Combine with targets.vim to enable commands like these:

Route::get('/create', 'GamesController@index');

From beginning of line, typing \i3in'Foo loads to:

Route::get('/create', 'FooGamesController@index');
@joshtch

This does weird things if you try to append to a multi-line textobject (like ip). You might find it preferable to make it start a new line, like this:

nnoremap <silent> <Leader>a :set opfunc=Append<CR>g@
nnoremap <silent> <Leader>i :set opfunc=Insert<CR>g@
function! Append(type, ...)
    normal! `]
    if a:type == 'char'
        call feedkeys("a", 'n')
    else
        call feedkeys("o", 'n')
    endif
endfunction
function! Insert(type, ...)
    normal! `[
    if a:type == 'char'
        call feedkeys("i", 'n')
    else
        call feedkeys("O", 'n')
    endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment