Last active
August 4, 2023 07:46
-
-
Save romainl/b00ccf58d40f522186528012fd8cd13d to your computer and use it in GitHub Desktop.
Substitute operator
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
function! Substitute(type, ...) | |
let cur = getpos("''") | |
call cursor(cur[1], cur[2]) | |
let cword = expand('<cword>') | |
execute "'[,']s/" . cword . "/" . input(cword . '/') | |
call cursor(cur[1], cur[2]) | |
endfunction | |
nmap <silent> <key> m':set opfunc=Substitute<CR>g@ | |
" Usage: | |
" <key>ipfoo<CR> Substitute every occurrence of the word under | |
" the cursor with 'foo' in the current paragraph | |
" <key>Gfoo<CR> Same, from here to the end of the buffer | |
" <key>?bar<CR>foo<CR> Same, from previous occurrence of 'bar' | |
" to current line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment