Find and Replace within selection in `vi`

前端 未结 6 1655
不知归路
不知归路 2021-01-30 08:09

How do I do a Find and Replace within a selection in vi?

6条回答
  •  Happy的楠姐
    2021-01-30 08:40

    Most of the other solutions suggested here work over the ENTIRE line in which the selection occurs, which may not be what you want.

    To search and replace ONLY in the selection, first visually select the text, then use a command like so:

    :%s/\%VSEARCH/REPLACE/g
    

    This will do the search and replace only in the visually selected section, replacing SEARCH with REPLACE. If you have more than one line selected, this will work over multiple lines too.

提交回复
热议问题