Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active September 4, 2025 05:56
Show Gist options
  • Select an option

  • Save Integralist/8d01300efcd2006c69e8b9492c0eada8 to your computer and use it in GitHub Desktop.

Select an option

Save Integralist/8d01300efcd2006c69e8b9492c0eada8 to your computer and use it in GitHub Desktop.

Revisions

  1. Integralist revised this gist May 28, 2025. No changes.
  2. Integralist revised this gist Jun 3, 2021. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions Examples.md
    Original 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

    You probably want `cdo` not `cfdo`.
    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_ 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.
    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 might need to try specifying `%`.
    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

  3. Integralist revised this gist Jan 20, 2021. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion Examples.md
    Original 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`.
    ## tl;dr

    You probably want `cdo` not `cfdo`.

    ## Difference?

  4. Integralist revised this gist Jan 20, 2021. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions Examples.md
    Original 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`.

    **So to understand the difference, let's consider an example scenario:**
    ## 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 would either need to specify `%` or use a macro (see below example).
    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 use `cfdo`:
    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).

    ```
    :cfdo execute "norm @q" | update
    :cdo execute "norm @q" | update
    ```
  5. Integralist revised this gist Jan 20, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Examples.md
    Original 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.
    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
    :cdo s/v2/v3/ | update
    ```

    To execute a macro for every 'file' listed in the quickfix window use `cfdo`:
  6. Integralist revised this gist Jan 20, 2021. 1 changed file with 23 additions and 2 deletions.
    25 changes: 23 additions & 2 deletions Examples.md
    Original 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).

    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.
    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.

    This is best demonstrated by examples...
    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`:

  7. Integralist revised this gist Jan 20, 2021. 2 changed files with 20 additions and 1 deletion.
    20 changes: 20 additions & 0 deletions Examples.md
    Original 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
    ```
    1 change: 0 additions & 1 deletion vim execute macro across files in a quickfix list
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    :cfdo execute "norm @q" | update
  8. Integralist created this gist Jan 5, 2021.
    1 change: 1 addition & 0 deletions vim execute macro across files in a quickfix list
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    :cfdo execute "norm @q" | update