Skip to content

Instantly share code, notes, and snippets.

@wellle
Last active March 17, 2023 13:02
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wellle/9289224 to your computer and use it in GitHub Desktop.
Save wellle/9289224 to your computer and use it in GitHub Desktop.
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
Copy link
Author

wellle commented Mar 1, 2014

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
Copy link
Author

wellle commented Mar 1, 2014

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
Copy link

joshtch commented Mar 2, 2014

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