I forgot that you can prepare a series of commands separated by |.
The solution I'm happy with is:
if has("nvim")
set inccommand=nosplit " Remove horizontal split that shows a preview of whats changing
endif
" E means edit with confirms, e is no confirm.
" Second letter is source: w is word under cursor, y is yanked text.
" Even with very no magic (\V) modifier, still need to escape / and \ with \
" The \< and \> means don't do a raw string replace but a word replace
" so if you want to replace someVar, it won't touch vars name someVarOther
" edit word in whole file
nnoremap <leader>ew :%s/\V\<<c-r><c-w>\>//gI \|normal <c-o><c-left><c-left><left><left><left><left>
" Edit confirm word in whole file
nnoremap <leader>Ew :,$s/\V\<<c-r><c-w>\>//gIc \|1,''-&&<c-left><left><left><left><left><left>
" edit word under cursor within the visual lines
" gv selects the last vis selection (line, block or select)
vnoremap <leader>ew <Esc>yiwgv:s/\V\<<c-r>"\>//gI \| normal <c-o><c-left><c-left><c-left><left><left><left><left>
" Visually selected text in file
" If mode is visual line mode, edit the prev yank acros the vis lines, else across the whole file
" see :help escape()
vnoremap <expr> <leader>ey mode() ==# "V" ?
\ ":s/\\V<c-r><c-r>=escape(@\", '/\\')<cr>//gI \| normal <c-o><c-left><c-left><c-left><left><left><left><left>"
\: "y:%s/\\V<c-r><c-r>=escape(@\", '/\\')<cr>//gI \| normal <c-o><c-left><c-left><c-left><left><left><left><left>"
nnoremap <leader>ey :%s/\V<c-r>=escape(@", '/\\')<cr>//gI <bar> normal <c-o><c-left><c-left><c-left><left><left><left><left>
nnoremap <leader>Ey :%s/\V<c-r>=escape(@", '/\\')<cr>//gIc <bar> normal <c-o><c-left><c-left><c-left><left><left><left><left><left>
''
after substitution?