Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search and replace in project? #528

Closed
lhyaax opened this issue Nov 28, 2017 · 12 comments
Closed

search and replace in project? #528

lhyaax opened this issue Nov 28, 2017 · 12 comments

Comments

@lhyaax
Copy link

lhyaax commented Nov 28, 2017

How to search and replace in project?
:Ag can search file , and then ?

@trevordmiller
Copy link

Assuming you are using Vim 7.4+, you can use cdo and cfdo to run commands over items in the quickfix list natively. :Ag from this plugin does let you populate the quickfix list - so the whole flow is this:

Plugin specific:

Native:

  • Once quickfix list is populated, you can run a file substitute command then save every file in the quickfix list like this:
    :cfdo %s/foo/bar/g | :w

This seems a bit complicated, but it's actually really powerful because you can run any other command, not just substitute. For example. you could run a macro on each matching quickfix item like this:

:cdo normal @q

etc.

More info on cdo and cfdo: https://robots.thoughtbot.com/lists-vim-and-you#from-inside-of-vim

Related: #586

@dakom
Copy link

dakom commented Nov 28, 2018

Can you please suggest how to do ALT-A in xfce-terminal? (it selects the terminal menu by default)

@rakshans1
Copy link

rakshans1 commented Dec 22, 2019

Hi
I am trying to implement search and replace in the project with new fzf change reload

I want to achieve following features

  1. Start Rg with the current word below the cursor
  2. Update if the query is changed
  3. Selection with alt-a / tab will automatically be added to quickfix list by fzf
  4. Run :cfdo %s/newquery/ /g | :w with new query

https://github.com/rakshans1/dotfiles/blob/master/config/nvim/plugin/fzf.vim#L82

I am able to get till step 3 but not able to retrieve new search query for substitution

junegunn/fzf#1750

@partounian
Copy link

ALT-A doesn't work for me using neovim, oh-my-zsh, and iTerm2. I have set the Option key to send Esc+ as recommended. Anyone else having this issue?

@junegunn
Copy link
Owner

@partounian I needed to put these in my Vim configuration file:

if has('nvim')
  tnoremap <a-a> <esc>a
  tnoremap <a-b> <esc>b
  tnoremap <a-d> <esc>d
  tnoremap <a-f> <esc>f
endif

@sheerun
Copy link

sheerun commented Sep 12, 2021

it doesn't really solve the issue as all patterns in quicklst files are replaced, while I'd expect only selected lines are replaced

@sheerun
Copy link

sheerun commented Sep 12, 2021

Following is the correct command:

:cdo s/foo/bar/ | :w

@sheerun
Copy link

sheerun commented Sep 12, 2021

Does anyone know how to get last searched phrase from fzf? something like / register. I need it so I can pass it as an argument to the :cdo

@MushiTheMoshi
Copy link

is there a way to customize ALT+a in vim? I have already assigned a tmux shortcut to that one....

@MeNsaaH
Copy link

MeNsaaH commented Apr 4, 2023

@MushiTheMoshi did you figure this out?

@MeNsaaH
Copy link

MeNsaaH commented Apr 4, 2023

Found it #731

@MushiTheMoshi
Copy link

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants