Vim - Search and replace the results

后端 未结 4 724
刺人心
刺人心 2021-02-13 05:13

I\'m getting more and more comfortable with Vim after a few months. BUT, there is only one simple feature I can\'t get any answer from the web. That is \"Search and replace the

4条回答
  •  野性不改
    2021-02-13 05:56

    Well, since #keyword# and #new_keyword# account for most of the characters, and you need some way to differentiate between them (i.e., a character in vim, or tab between entry fields in dialog in a different editor), you're left with maybe four or five keystrokes beyond that.

    So I think you're probably overestimating number of keystrokes and also forgetting that (1) it becomes very natural, and (2) working this way allows you also to naturally modify the action performed by specifying a different range or option flag.

    But you can cut down on keystrokes. If you want you can map a key to automatically bring up the command line with '%s/' already in place. e.g.:

    nmap s :%s/
    

    The command above would remap 's' (I'm not recommending remapping to that key, but it gives the idea) and set you up to insert the keyword.

    Also, you can set the 'gdefault' option to default to substituting multiple times per line. This lets you skip the ending '/g' in your keystrokes:

    set gdefault
    

    See ':h gdefault' for help section on that option.

    In the end I would say just get used to the default way it works, because using it that way allows you to keep same basic operation when you want to specify different ranges or option flags, and creating a new special map is just another thing to remember. gdefault may be worth setting if you think you're going to want it majority of time, adding /g flag at end when gdefault is set has effect of turning /g off. . .

提交回复
热议问题