Skip to content

Instantly share code, notes, and snippets.

@agaro1121
Last active October 21, 2023 00:44
Show Gist options
  • Save agaro1121/5abaac72c25f2f60a280c4a48117b7df to your computer and use it in GitHub Desktop.
Save agaro1121/5abaac72c25f2f60a280c4a48117b7df to your computer and use it in GitHub Desktop.
Nvim Macros to multiple files
  1. Create macro (let's say we're saving it to 'x')
  2. View macros in registry :reg x
  3. Copy content of macro "xp
  4. Store macro to file (file must be loaded by vim on startup. See here

Use "[register letter]p to paste into a file with the format below

let @x = "<macro contents>"
  1. Use find to generate a list of files that need to be updated ie find . -type f -name "*.yaml"
  2. Open files with nvim -u NONE $(<find command>)
  3. Apply macro to all files argdo normal @x
  4. Save all files

Alternatie solution

  1. Create macro (let's say we're saving it to 'x')
  2. View macros in registry :reg x
  3. Use telescope to fuzzy find the files you need
  4. Send them to quickfix list CTRL-q
  5. Run macro on all the files :cdo normal @x

Alternatie solution 2

  1. Create macro (let's say we're saving it to 'x')
  2. View macros in registry :reg x
  3. Use vimgrep to search to build a quickfix list of where to paste the text :vim /pattern/ dir/*.ext
  4. Run macro on all the files :cdo normal @x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment