timhwang21.gitbook.io
  • Intro
  • Blog
    • 2023
    • 2022
    • 2021
    • 2020
    • 2019
  • CLI
    • Git
      • Bulk resolve merge conflicts
      • git rebase-onto
      • Patch from diff
    • Shell
      • Recipes
    • Vim
      • Batch editing
      • Buffers
      • <Ctrl-r>
      • External commands
      • :global
      • Help
      • Registers
      • Splits
    • Tools
  • Programming
    • React
      • Testing Styled Components
    • Typescript
      • curryRecord
      • Exhaustive conditionals with ADTs
      • newtype
      • OmitTypes
      • Safe JSON clone
      • Type inferrers
      • XOR type
    • Ruby
      • Pry
      • RSpec
    • Rails
      • Attributes
      • Cheap many to many
      • (Don't use) counter cache
    • Databases
      • Metrics
      • Testing indexes
  • Personal
    • Uses
    • Github
    • Medium
    • LinkedIn
    • Photography
Powered by GitBook
On this page
  • Opening a list of files
  • Operating on a list of files within vim using cdo, cfdo
  • Operating on a list of files using argument list
  • Batch editing files outside vim using argdo
  • Bulk editing files from within vim
  1. CLI
  2. Vim

Batch editing

Opening a list of files

vim `ag -lQ TERM`

Operating on a list of files within vim using cdo, cfdo

The following takes an existing quickfix list (for example, from :Ack TERM), applies the replacement, and saves them.

cdo runs the command for each entry in the quickfix list while cfdo runes the command for each file in the quickfix list.

:cfdo %s/TERM/REPLACEMENT/g

Operating on a list of files using argument list

Batch editing files outside vim using argdo

The following command takes a list of files including TERM, applies the replacement, and saves them.

vim `ag -lQ TERM` +"argdo %s/TERM/REPLACEMENT/g | update"

Bulk editing files from within vim

The following allows adding all files matching a glob to the arglist, where you can then operate on them. This example uses :exec and string concatenation to open all files matching the extension .tsx in the parent directory of the current file.

:exec 'args ' . expand('%:h') . '/**.tsx'
PreviousVimNextBuffers

Last updated 3 years ago