Skip to main content
added 132 characters in body
Source Link
Rich
  • 32.6k
  • 4
  • 74
  • 141

You could do it with a substitution:

:5,20s/\<i\>/j/g
  • 5,20: betweenBetween lines 5 and 20,
  • s: substitute,
  • /\<i\>/ all instances of the word i (the \< and \> match word boundaries,
  • j with the letter j,
  • /g: everywhere in the line.

If you don't want to use line numbers, you could instead first select the area where you want to make the substitution in visual mode, and then Vim will pre-populate the command line with a range specifying the selection when you press :.

If you want to make the replacement everywhere in the current buffer, you can use the % range, instead:

:%s/\<i\>/j/g

You could do it with a substitution:

:5,20s/\<i\>/j/g
  • 5,20: between lines 5 and 20,
  • s: substitute,
  • /\<i\>/ all instances of the word i (the \< and \> match word boundaries,
  • j with the letter j,
  • /g: everywhere in the line.

If you don't want to use line numbers, you could instead first select the area where you want to make the substitution in visual mode, and then Vim will pre-populate the command line with a range specifying the selection when you press :.

You could do it with a substitution:

:5,20s/\<i\>/j/g
  • 5,20: Between lines 5 and 20,
  • s: substitute,
  • /\<i\>/ all instances of the word i (the \< and \> match word boundaries,
  • j with the letter j,
  • /g: everywhere in the line.

If you don't want to use line numbers, you could instead first select the area where you want to make the substitution in visual mode, and then Vim will pre-populate the command line with a range specifying the selection when you press :.

If you want to make the replacement everywhere in the current buffer, you can use the % range, instead:

:%s/\<i\>/j/g
Source Link
Rich
  • 32.6k
  • 4
  • 74
  • 141

You could do it with a substitution:

:5,20s/\<i\>/j/g
  • 5,20: between lines 5 and 20,
  • s: substitute,
  • /\<i\>/ all instances of the word i (the \< and \> match word boundaries,
  • j with the letter j,
  • /g: everywhere in the line.

If you don't want to use line numbers, you could instead first select the area where you want to make the substitution in visual mode, and then Vim will pre-populate the command line with a range specifying the selection when you press :.