Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Search And Replace In Neovim And Vim

## Everywhere in the file

Code

:%s/foo/bar/g

## On the current line

Code

:s/foo/bar/g

## Change on current line and next two lines (+2)

Code

:.,+2s/foo/bar/g

Change in each line starting with 'baz'.

Code

:g/^baz/s/foo/bar/g

## In all open tabs

Code

:tabdo %s/foo/bar/g

## Change only on specific lines

Code

:5,12s/foo/bar/g

## Change all lines from mark `a` to mark `b` inclusive.

Code

:'a,'bs/foo/bar/g

## Change from the current line (.) to the last line ($) inclusive.

Code

:.,$s/foo/bar/g