Using Regular Expressions in Vim
On OpenBSD and Debian, Vim’s built-in regex support allows simple but powerful text manipulation for notes, drafts, and prose.
Search
/pattern— forward search forpattern?pattern— backward searchn/N— repeat search forward/backward*/#— search for word under cursor
Replace
:%s/old/new/g— replace all occurrences in the file:%s/old/new/gc— replace with confirmation:s/old/new/— replace on current line only
Anchors and Characters
^— start of line$— end of line.— any character\s/\S— whitespace / non-whitespace\w/\W— word character / non-word\+— one or more\*— zero or more\{m,n\}— repeatmtontimes
Examples for Daily Prose
- Delete trailing spaces:
:%s/\s\+$//e
- Fix double spaces after periods:
:%s/\. \./. ./g
- Capitalize first word of a paragraph:
:g/^\s*\w/\norm! gUiw
- Highlight TODO comments:
:/TODO
Notes on OpenBSD / Debian
- Base
vimay lack some regex features; install full Vim viapkg_add vim(OpenBSD) orapt install vim(Debian). :w !sudo tee %works on OpenBSD and Debian for editing protected files.- Regex operations are safe for plain text and prose, ideal for cleaning drafts, notes, and markdown files.