Reputation: 39
I am working in vim. I have a piece text that looks like :
one = 24
two = 52
three = 56
four = 74
Is there a way to use visual select to yank and paste up to the equal to sign in each line ? I want an operation that leaves me with the following result :
one = 24
two = 52
three = 56
four = 74
one =
two =
three =
four =
My current solution is to copy the whole thing, then jump to the one = 24
line in what I copied and then record this macro : 0f=ld$j
to @w and then repeat it three times with 3@w. Is there a way to do this using visual select and yank and paste ?
Upvotes: 0
Views: 1613
Reputation: 21
From anywhere on each line:
0vf=
Upvotes: 1
Reputation: 171
You could use a mapping like this
vnoremap ,s y:let @"=system('sed -nE "s/=.*/=/p"',@")<cr>
When selecting now some lines in in visual mode, type ,s
. This will put the desired modification into the "
register and you can paste them now using p
wherever you want.
Upvotes: 0
Reputation: 4673
How about
:global /=/ copy $ | substitute /=\zs.*//
We use global
to select the original lines, then copy
them to the end $
and remove the parts after =
with substitute
.
Upvotes: 0
Reputation: 32926
I tend to use :substitute
for these things
" First I yank and paste, in normal mode
yapP
" Then I transform
gv " to reselect, while in normal mode
:s/=.*/=/ " that will actual display :'<,'>s/.....
The actual reselection part may need a little work depending on where the cleared snippet shall appear. May be something like yapo<esc>p:'[,']s/=.*/=/
+ enter
Upvotes: 2
Reputation: 276
You can visually select the lines to apply normal commands to them with :norm
.
Thus, you could do:
ggVG:norm f=ld$
Upvotes: 1