Skip to content

Commit 6836ed2

Browse files
using-neovim: search-replace with grug-far
resolve: #77
1 parent fdf43c5 commit 6836ed2

File tree

5 files changed

+57
-34
lines changed

5 files changed

+57
-34
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- dev: book configuration & make task for deploying to staging
3333
- dev: add scheduled stale issue & pull request check
3434
- intro: troubleshoot guide with examples
35+
- using-neovim: search-replace with grug-far
3536

3637
### Changed
3738
- ci: spell lychee & repository trufflehog linters warn only (false positives)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Grug Far
2+
3+
A very efficient search and replace tool using the external [ripgrep command](https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md) line tool.
4+
5+
++spc++ ++"s"++ is the search and replace menu
6+
7+
++"g"++ ++"?"++ for help menu in the Grug-far buffer
8+
9+
10+
!!! NOTE "Search and replace with Grug-Far"
11+
12+
++spc++ ++"s"++ ++"s"++ to search across the current workspace (project)
13+
14+
Enter a Search pattern, press ++esc++ and all occurrences across the project are shown
15+
16+
Enter a Replace pattern, press ++esc++ to see occurrences with their replacement
17+
18+
++comma++ ++"r"++ to replace all occurrences with the replace pattern
19+
20+
++comma++ ++"j"++ / ++"k"++ replace at current line & move to next / previous change
21+
22+
23+
24+
??? TIP "Search results in Quicklist"
25+
++comma++ ++"q"++ adds search results to quickfix list to edit occurrences with other Neovim tools
26+
27+
28+
## Search buffer
29+
30+
Enter patterns in the **Search** and **Replace** and the results are show in a diff below.
31+
32+
++tab++ and ++shift++ ++tab++ navigate between search buffer sections.
33+
34+
![Grug-Far Search buffer](https://github.com/practicalli/graphic-design/blob/live/editors/neovim/astronvim-5/neovim-search-grug-far-search-dark.png?raw=true){loading=lazy}
35+
36+
??? EXAMPLE "Usefull Ripgrep options for Grug-Far"
37+
- `-i/--ignore-case`: ignore case differences, e.g. `rg -i fast` matches `fast`, `fASt`, `FAST`, etc.
38+
- `-F/--fixed-strings`: Disable regular expression matching and treat the pattern as a literal string.
39+
- `-w/--word-regexp`: pattern matches are surrounded by word boundaries, e.g. `pattern` is `\b(?:pattern)\b`.
40+
- `-c/--count`: a count of total matched lines.
41+
- `-a/--text`: Search binary files as if they were plain text.
42+
- `-U/--multiline`: Permit matches to span multiple lines.
43+
- `-z/--search-zip`: Search compressed files (gzip, bzip2, lzma, xz, lz4, brotli, zstd). This is disabled by default.
44+
- `-C/--context`: Show the lines surrounding a match.
45+
- `-L/--follow`: Follow symbolic links while recursively searching.
46+
- `-M/--max-columns`: Limit the length of lines printed by ripgrep.
47+
48+
[All Ripgrep Options](https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#common-options)

docs/using-neovim/search-replace/index.md

+2-30
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Neovim has several built-in commands to search for patterns in the current buffe
44

55
Additional tools that work across all the files in a project:
66

7-
- ++spc++ ++"s"++ ++"s"++ [search and replace commands using Spectre](#spectre)
8-
- ++spc++ ++"l"++ ++"r"++ to rename symbols using [Clojure LSP](/neovim/repl-driven-development/refactor-tools/)
7+
- ++spc++ ++"s"++ ++"s"++ search and replace using [Grug-far](grug-far.md)
8+
- ++spc++ ++"l"++ ++"r"++ to rename symbols using [Clojure LSP](/neovim/clojure-repl-workflow/refactor-tools/)
99

1010
> [:fontawesome-solid-book-open: multiple cursors](../multiple-cursors.md) for in-place editing within a buffer
1111
@@ -54,34 +54,6 @@ Use search to populate the Neovim quickfix list and change occurrences across al
5454
Including the `c` option to confirm each replacement
5555

5656

57-
58-
### Spectre
59-
60-
[:fontawesome-solid-book-open: Spectre](spectre.md){target=_blank} shows occurrences of a pattern throughout all project files, replace individual or all occurrences.
61-
62-
!!! EXAMPLE "Search and replace with Spectre"
63-
64-
++spc++ ++"s"++ is the search and replace menu
65-
66-
Enter a Search pattern and all occurrences across the project are shown
67-
68-
Enter a Replace pattern to see occurrences with their replacement
69-
70-
++"R"++ to replace all occurrences with the replace pattern
71-
72-
++"C"++ to replace current occurrence
73-
74-
75-
++"q"++ adds the Spectre search results to quickfix list to edit occurrences with other Neovim tools
76-
77-
78-
![nvim-spectr](https://github.com/windwp/nvim-spectre/wiki/assets/demospectre.gif)
79-
80-
[:globe_with_meridians: ripgrep](https://github.com/BurntSushi/ripgrep){target=_blank} and [:globe_with_meridians: sed](https://www.gnu.org/software/sed/) are required.
81-
82-
[:globe_with_meridians: Spectre](https://github.com/nvim-pack/nvim-spectre){target=_blank .md-button}
83-
84-
8557
<!-- TODO: review :cdo and similar commands
8658
8759
use ack.vim/ag.vim with the :cdo command, an intuitive and near-native project-wide find-and-replace solution is now available.

docs/using-neovim/search-replace/spectre.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Spectre
22

3+
!!! WARNING "Not included in Astro 5 - see Grug-Far"
4+
35
++spc++ ++"s"++ ++"s"++ to toggle Spectre (open/close) to search and replace tool.
46

57
`?` for the Spectre key mappings
@@ -19,7 +21,7 @@
1921
![Neovim Spectre search replace](https://github.com/practicalli/graphic-design/blob/live/editors/neovim/screenshots/neovim-search-replace-spectre-search-dark.png?raw=true#only-light){loading=lazy}
2022

2123

22-
++"d"++ ++"d"++ to toggle an occurance
24+
++"d"++ ++"d"++ to toggle an occurance
2325

2426
++"R"++ replaces all occurances (after selecting the occurances to change)
2527

@@ -35,9 +37,8 @@ A DONE checkbox is show at then end of each selection which has been reaplaced
3537
Use Git or Neovim undo to rollback changes made by Spectre.
3638

3739

38-
[:globe_with_meridians: Spectre](https://github.com/nvim-pack/nvim-spectre){target=_blank} is available via the AstroNvim Community project pack and included in the Practicalli astronvim-config
40+
[:globe_with_meridians: Spectre](https://github.com/nvim-pack/nvim-spectre){target=_blank} is available via the AstroNvim Community project pack and included in the Practicalli astronvim-config
3941

4042
[:globe_with_meridians: ripgrep](https://github.com/BurntSushi/ripgrep){target=_blank} and [:globe_with_meridians: sed](https://www.gnu.org/software/sed/) are required.
4143

42-
[:fontawesome-brands-github: Spectre project](https://github.com/nvim-pack/nvim-spectre){target=_blank .md-button}
43-
44+
[:fontawesome-brands-github: Spectre project](https://github.com/nvim-pack/nvim-spectre){target=_blank .md-button}

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ nav:
152152
- Registers: using-neovim/registers.md
153153
- Search Replace:
154154
- using-neovim/search-replace/index.md
155+
- Grug-Far: using-neovim/search-replace/grug-far.md
155156
- Substitute: using-neovim/search-replace/substitute.md
156157
- Spectre: using-neovim/search-replace/spectre.md
157158
- Spell Check: neovim-basics/spell-check.md

0 commit comments

Comments
 (0)