practicalli / neovim

Neovim, Conjure and LSP for Clojure development using Fennel configuration
https://practical.li/neovim/
Creative Commons Attribution Share Alike 4.0 International
21 stars 5 forks source link

Substitution in neovim #33

Open practicalli-johnny opened 1 year ago

practicalli-johnny commented 1 year ago

Neovim built-in substitution command

:%s command substitutes text in the current buffer, e.g substitute the word have by had

:%s/have/had/g`

The g modifier replaced all occurrences on the same line, omitting g only replaces the first occurrence on each line.

c modifier prompts for confirmation of each replace occurrence.

Use visual select to replace all of the 32 arguments to functions by 100 without replacing 32 in the declarations

let = 32; let = 32; let _ = 32;

let x = foo(32); let y = bar(32); let z = zoo(32); let a = quux(32); let b = tronfibulate(32);

Select all the lines starting from let x = … to let b = … and press :

enter the substitute command to scope it to that selection;

% means the whole file

:'<,'>, are visual marks.

Using visual select the substitute command

:'<,'>s/32/100/g

the replacement was limited to the portion of text selected. That works in visual, line and block visual modes

:help s_flags for more information about the substitute flags.