Find and Replace within selection in `vi`

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

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

6条回答
  •  情深已故
    2021-01-30 08:53

    Select the text in visual mode (I assume that's what you're doing), then press : to start typing a command, you'll see something like this appear in the command line:

    :'<,'>
    

    That means that the command will apply to the selection. Then type s/search/replace/ and hit enter. (Add a g after the third slash if you want to replace all matches, and a c if you want a confirmation for every replace)

提交回复
热议问题