POSTS

Search and Replace in Vim

Reading time: 1 min Written by Marco Tschannett

Searching and replacing text in a document is a common task. While programming we usually try to use refactring capabilities of our editors. Sometimes this is not feasable.

Disclaimer: This is part of my vim commands “repo”. I use this posts to archive solutions for text editiong problems I faced while using vim. To listen all shortcuts look here.

Problem

I want to search and replace a or all occurances of a phrase in the current file.

Solution

    # Einzlenes Ergebnis ersetzen
    %s/[Suchstring]/[Ersetzungsstring]/

    #Alle Ergebnisse ersetzen
    :%s/[Suchstring]/[Ersetzungsstring]/g

Important

The search phrase will be interpreted as a regular expression. Reserved expressions like a . or a \ must therefore be escaped.

Tags

comments powered by Disqus