Last active
September 4, 2025 05:56
-
-
Save Integralist/8d01300efcd2006c69e8b9492c0eada8 to your computer and use it in GitHub Desktop.
Revisions
-
Integralist revised this gist
May 28, 2025 . No changes.There are no files selected for viewing
-
Integralist revised this gist
Jun 3, 2021 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ If you use `cfdo`, then your action will be applied to each _file_ in the quickf ## tl;dr Using `cdo` is more straight forward, but `cfdo` is probably more efficient/performant. ## Difference? @@ -26,9 +26,11 @@ The file `example1.txt` shows up multiple times, while `example2.txt` only shows The file `example1.txt` shows up multiple times because we searched for a phrase such as `foo` and that phrase happened to appear multiple times within `example1.txt`, while it only appeared once within `example2.txt`. If you wanted to replace `foo` with `bar` using a subtitution like `s/foo/bar/`, and you used `cdo`, then all occurences of `foo` would be replaced because the substitution would be executed across each _entry_ in the quickfix window. But if you used `cfdo` then the substitution would only be applied once to the _file_ because you didn't use `%` (e.g. `:%s/foo/bar/` meaning apply the substitution across the entire buffer) so only the first line of the file would have the substitution applied. You could still use `cfdo` but you would need to specify `%`. > **NOTE**: I've found that my quickfix window is updated frequently/dynamically when using certain build tools (e.g. vim-go with gopls), in this case I'm better off using `cfdo` with `%s/foo/bar/e | update` which will write the buffer once, rather than the multiple times compared to `cdo` with `s/foo/bar/e | update`. It's also much more efficient using `cfdo` as it won't write the buffer multiple times. ## Examples -
Integralist revised this gist
Jan 20, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,9 @@ If you use `cdo`, then your 'action' (i.e. how you're going to _replace_ content If you use `cfdo`, then your action will be applied to each _file_ in the quickfix window. ## tl;dr You probably want `cdo` not `cfdo`. ## Difference? -
Integralist revised this gist
Jan 20, 2021 . 1 changed file with 7 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,9 +9,11 @@ If you use `cdo`, then your 'action' (i.e. how you're going to _replace_ content If you use `cfdo`, then your action will be applied to each _file_ in the quickfix window. **tl;dr**: you probably want `cdo` not `cfdo`. ## Difference? To understand the difference, let's consider an example scenario: We have quickfix window that has two files: @@ -24,7 +26,7 @@ The file `example1.txt` shows up multiple times because we searched for a phrase If you wanted to replace `foo` with `bar` using a subtitution like `s/foo/bar/`, and you used `cdo`, then all occurences of `foo` would be replaced because the substitution would be executed across each _entry_ in the quickfix window. But if you used `cfdo` then the substitution would only be applied once to the _file_ and because you've not used `%` (e.g. `:%s/foo/bar/` meaning apply the substitution across the entire buffer) only the first line of the file would be seen. You could still use `cfdo` but you might need to try specifying `%`. ## Examples @@ -34,8 +36,8 @@ To execute a substitution for every 'entry' listed in the quickfix window use `c :cdo s/v2/v3/ | update ``` To execute a macro for every 'file' listed in the quickfix window, you would still use `cdo` and not `cfdo`! This is interesting because you might expect the macro to execute across the entire file, but remember that macros only execute once and if you need them to be executed multiple times then you need to tell them to execute across a 'range' (e.g. the entire buffer or a section of lines). So by using `cdo` instead it means you can rely on the macro being executed against every _instance_ of the thing you're searching for (even if it appears multiple times within a file). ``` :cdo execute "norm @q" | update ``` -
Integralist revised this gist
Jan 20, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ The file `example1.txt` shows up multiple times, while `example2.txt` only shows The file `example1.txt` shows up multiple times because we searched for a phrase such as `foo` and that phrase happened to appear multiple times within `example1.txt`, while it only appeared once within `example2.txt`. If you wanted to replace `foo` with `bar` using a subtitution like `s/foo/bar/`, and you used `cdo`, then all occurences of `foo` would be replaced because the substitution would be executed across each _entry_ in the quickfix window. But if you used `cfdo` then the substitution would only be applied once to the _file_ and because you've not used `%` (e.g. `:%s/foo/bar/` meaning apply the substitution across the entire buffer) only the first line of the file would be seen. You could still use `cfdo` but you would either need to specify `%` or use a macro (see below example). @@ -31,7 +31,7 @@ You could still use `cfdo` but you would either need to specify `%` or use a mac To execute a substitution for every 'entry' listed in the quickfix window use `cdo`: ``` :cdo s/v2/v3/ | update ``` To execute a macro for every 'file' listed in the quickfix window use `cfdo`: -
Integralist revised this gist
Jan 20, 2021 . 1 changed file with 23 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,9 +3,30 @@ There are two 'types' to be aware of with a quickfix window: 1. entry: the actual _line_ content (e.g. `:grep foo` will show a specific line that matched within a file). 2. file: the actual _file_ itself (e.g. the path to the file that contained the match). To replace content using vim (via the quickfix window) you need to choose whether you want to apply the change via the quickfix 'entry' or via the 'file' as a whole. If you use `cdo`, then your 'action' (i.e. how you're going to _replace_ content) will be applied to every _entry_ in the quickfix window. If you use `cfdo`, then your action will be applied to each _file_ in the quickfix window. --- **So to understand the difference, let's consider an example scenario:** We have quickfix window that has two files: 1. `example1.txt` 2. `example2.txt` The file `example1.txt` shows up multiple times, while `example2.txt` only shows up once. The file `example1.txt` shows up multiple times because we searched for a phrase such as `foo` and that phrase happened to appear multiple times within `example1.txt`, while it only appeared once within `example2.txt`. If you wanted to replace `foo` with `bar` using a subtitution like `s/foo/bar`, and you used `cdo`, then all occurences of `foo` would be replaced because the substitution would be executed across each _entry_ in the quickfix window. But if you used `cfdo` then the substitution would only be applied once to the _file_ and because you've not used `%` (e.g. `:%s/foo/bar` meaning apply the substitution across the entire buffer) only the first line of the file would be seen. You could still use `cfdo` but you would either need to specify `%` or use a macro (see below example). ## Examples To execute a substitution for every 'entry' listed in the quickfix window use `cdo`: -
Integralist revised this gist
Jan 20, 2021 . 2 changed files with 20 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ There are two 'types' to be aware of with a quickfix window: 1. entry: the actual _line_ content (e.g. `:grep foo` will show a specific line that matched within a file). 2. file: the actual _file_ itself (e.g. the path to the file that contained the match). If you want to replace content in a file you need to choose whether you want to apply the change via the quickfix 'entry' or via the 'file' as a whole. This is best demonstrated by examples... To execute a substitution for every 'entry' listed in the quickfix window use `cdo`: ``` :cdo s/v2/v3 | update ``` To execute a macro for every 'file' listed in the quickfix window use `cfdo`: ``` :cfdo execute "norm @q" | update ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ -
Integralist created this gist
Jan 5, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ :cfdo execute "norm @q" | update