Vim Tips Wiki
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
FANDOM
Explore
Current Wiki
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Vim Tips Wiki
1,649
pages
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
Editing
Repeating a substitute from current cursor position
Back to page
Edit
Edit source
View history
Talk (0)
Edit Page
Repeating a substitute from current cursor position
We recommend that you
log in
before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your
Watchlist
.
Creating an account
is quick and free.
The edit appears to have already been undone.
Anti-spam check. Do
not
fill this in!
{{review}} {{TipImported |id=573 |previous=572 |next=575 |created=October 3, 2003 |complexity=intermediate |author=Charles E. Campbell, Jr. |version=6.0 |rating=4/3 |category1= |category2= }} The :RS /pattern/subpattern/{flags} command+function as shown below allows one to repeat a RS-substitute after the current cursor position. For example: <pre> " The cursor position is indicated with '^' on next line. one two three one two three one two three ^ :RS /two/TWO/ one TWO three one two three one two three ^ move cursor: one TWO three one two three one two three ^ (I think tip author intended to repeat :RS here?) cursor ends up: one TWO three one two three one TWO three </pre> Put the following into your vimrc if you'd like to be able to do this. <pre> " RS: repeat substitution command com! -range -nargs=* RS call RepeatSubst(<q-args>) " RepatSubst: fun! RepeatSubst(subexpr) if a:subexpr != "" let g:repeatsubst= a:subexpr endif let curcol= col(".") let sep = strpart(g:repeatsubst,0,1) let pat = substitute(g:repeatsubst,'^.\(.\{-}\)'.sep.'.*$','\1','') s/\%#./\r&/ let curcol= curcol + matchend(getline("."),pat) exe "s".g:repeatsubst norm! k j! exe 'norm! '.curcol.'|' endfun </pre> ==Comments==
Summary:
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Navigation
(
view source
)
Template:Review
(
view source
)
Template:TipImported
(
view source
)
Follow on IG
TikTok
Join Fan Lab