vim search replace on some specific lines

  • A+

Vim substitute command :%s/old/new/g will replace all occurrences of old by new. But I want to do this replacement only in lines that do not start with #. I mean in my file there are some lines starting with # (called commented lines) which I want to exclude in search replace. Is there any way to do it?


You should mix it with the g (see help :global) command:



:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: