Search and replace in Vim across all the project files

后端 未结 11 1906
我寻月下人不归
我寻月下人不归 2020-12-07 07:00

I\'m looking for the best way to do search-and-replace (with confirmation) across all project files in Vim. By \"project files\" I mean files in the current directory, some

11条回答
  •  猫巷女王i
    2020-12-07 07:38

    1. Make sure you’re using Neovim (or Vim 7.4.8+, but really just use Neovim)
    2. Install FZF for the command line and as a vim plugin
    3. Install Ag, so that it’s available automatically to FZF in vim
    4. If using iTerm2 on OSX, set the alt/option key to Esc+

    Usage

    Search the text you want to change in the current directory and it’s children with

    :Ag text

    • Keep typing to fuzzy filter items
    • Select items with alt-a
    • Deselect items with alt-d
    • Enter will populate the quickfix list
    • :cfdo %s/text/newText/g | :w

    Now you have chabges made inside Vim NeoVim

    source

提交回复
热议问题