How do I reuse the last used search pattern in a “:substitute”

command? To reuse the last used search pattern in a “:substitute” command, don’t specify a new search pattern:

    :s/pattern/newtext/

    :s//sometext/

In the second “:s” command, as a search pattern is not specified, the pattern specified in the first “:s” command ‘pattern’ will be used. If you want to change the search pattern but repeat the substitution pattern you can use the special right hand side, you can use the tilde character:

    :s/newpattern/~/

Comments (1)


Pepsh Pepshinsky

Let’s see you to :help viminfo-file-name (option -i) :set viminfofile=NONE


Speak Your Mind