In Vim, is there a way to paste text in the search line?

后端 未结 7 1648
情话喂你
情话喂你 2020-12-22 16:29

I want to search for $maximumTotalAllowedAfterFinish and replace it with $minimumTotalAllowedAfterFinish. Instead of typing the long text:

相关标签:
7条回答
  • 2020-12-22 17:05

    You can place the cursor on the word that you want to add to your pattern and then press / or : to enter either the search or the command mode, and then press CtrlRCtrlW to copy the word. Source

    0 讨论(0)
  • 2020-12-22 17:18

    Copy it as normal, then do CtrlR" to paste. There are lots of other CtrlR shortcuts (e.g, a calculator, current filename, clipboard contents). Type :help c_<C-R> to see the full list.

    0 讨论(0)
  • 2020-12-22 17:18

    Or create the command in a vim buffer , e.g. type it in the buffer:

    s/foo/bar/gci
    

    And copy it to a named register, with "ayy (if the cursor is on that line!).

    Now you can execute the contents of the "a" register from Vim's Ex command line with:

    :[OPTIONAL_RANGE]@a
    

    I use it all the time.

    0 讨论(0)
  • 2020-12-22 17:21

    Copy:
    1) v (or highlight with mouse, in visual mode)
    2) y (yank)

    Paste:
    1) / (search mode)
    2) Ctrl + R + 0 (paste from yanked register)

    0 讨论(0)
  • 2020-12-22 17:22

    You can insert the contents of a numbered or named register by typing CTRLR {0-9a-z"%#:-=.}. By typing CTRL-R CTRL-W you can paste the current word under the cursor. See:

    :he cmdline-editing
    

    for more information.

    0 讨论(0)
  • 2020-12-22 17:24

    Type q: to get into history editing mode in a new buffer. Then edit the last line of the buffer and press Enter to execute it.

    0 讨论(0)
提交回复
热议问题