Last active
March 17, 2023 13:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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');
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
Example:
From beginning of line, typing
\ai'_foo
leads to:Following up with
\ii)1,
leads to: