Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run command-line command on non-contiguous lines, specifying individual line numbers?

Tags:

vim

For example, say I want to replace foo with bar on lines 1,3,11, and 15. How could I do that?

:1,15s/foo/bar

will replace foo with bar on lines 1-15. But I want to specify multiple individual lines (1,3,11,15), not a range (1-15).

like image 852
Rob Bednark Avatar asked Dec 30 '25 23:12

Rob Bednark


1 Answers

How do you come up with the line numbers? If this is a manual process of visual inspection, you could make use of the multiselect plugin. It allows you to select multiple, non-contiguous ranges, and then you can apply a command on them:

:MSExecCmd s/foo/bar
like image 195
Ingo Karkat Avatar answered Jan 01 '26 15:01

Ingo Karkat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!