Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the best way to edit similar strings?

Tags:

vim

I need to make next task:

file:

string1 data1 data

I need to create more strings with only changes in digits

string2 data2 data
string3 data3 data
string4 data4 data

How can i do it fast ?

like image 892
RusAlex Avatar asked Dec 22 '22 20:12

RusAlex


2 Answers

select that input line, yank it into buffer a: "ayy.

Then record the following sequence: qq

  1. "ap Paste the line below
  2. ctrl-a Increment the digit
  3. w Move forward one word
  4. ctrl-a Increment the digit
  5. "ayy Yank this line in as your new baseline

End your macro with q

Then repeat it as many times as you need (let's say 42), with 42@q

like image 81
jkerian Avatar answered Jan 22 '23 16:01

jkerian


Several plugins manage that: visincr.vim, increment.vim.

I use visincr and that is very easy: Visual block, :I.

like image 32
Benoit Avatar answered Jan 22 '23 16:01

Benoit