سؤال

Is there any way to edit (add/remove characters) multiples lines of same column in Vim using a single command?

For example,

Sky can be white
Sky can be black
Sky can be red
Sky can be purple
Sky can be green
Sky can be yellow
Sky can be blue

If we wants to add the string "not" in the 8th column of all lines from 2 to 6, using a single command, like below, how we can do it without using Visual Block (Ctrl-v)?

Sky can be white
Sky cannot be black
Sky cannot be red
Sky cannot be purple
Sky cannot be green
Sky cannot be yellow
Sky can be blue
هل كانت مفيدة؟

المحلول

Two solutions come to mind:

:2,6norm eeanot<CR>

We use :norm[al] to execute the normal mode command eeanot on lines 2 to 6.

:2,6s/can/&not<CR>

We run a classic substitution on lines 2 to 6. In the replacement part, & represents the matched text so we don't have to repeat can before not.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top