far.vim icon indicating copy to clipboard operation
far.vim copied to clipboard

When running Fardo on C++ file all matches just turn red and no changes take place

Open axsaucedo opened this issue 4 years ago • 4 comments

When I perform a :Far from to % command, the matches are found in the current buffer, but it seems the replacements are not being processed when running :Fardo - basically all the lines just turn red, and no errors appear, as follows:

image

What is the best way to provide debug logs for this?

axsaucedo avatar Feb 14 '21 06:02 axsaucedo

I think I'm facing similar issues. @axsaucedo have you got a source different from the default set for far? Are your cwd different from the file path?

Anyway, since one of the symptoms is similar, and I'm guessing the underlying cause is the same, I'm posting here my report.

Steps to reproduce the issues

  • Create a minimal init.vim:
" filename: init.vim
call plug#begin('~/.vim/plugged')
Plug 'brooth/far.vim'                          
call plug#end()                                                                                                             
 
let g:far#source="rg"
 
" from
  • While the cwd is the same as the init.vim (launch nvim -u init.vim init.vim):

    • When using the default far source (commenting the source line in the init.vim):

      • Trying a replacement with :Farr from to % and then :Fardo will work as expected
      • Trying the same replacement but with the filename, an absolute or relative path as file mask will work too
    • When using an alternative far source (like rg):

      • Trying the replacement with % or the filename (init.vim) as file mask will work
      • Using an absolute or relative path (./init.vim) as file mask will result in far looking for matches in all files in the cwd (same as if * were used), but the replacement will work
  • The following example is correct, but being bottom-up is not the best one. Read my next message for a better one.

    While the cwd is different from the init.vim path (mkdir test; cd test and then nvim -u ../init.vim ../init.vim):

    • When using the default far source everything is working as expected

    • When using an alternative source:

      • Trying the replacement with % as file mask will find the match, but trying to replace with :Fardo will not work, leaving the match line red colored
      • Trying the replacement with the filename, an absolute or relative path as file mask will not even find the match

EDIT: I get that rg and the others treat filemasks differently than vimgrep (as indicated by the docs), so parts of this report is 'working as intended', but the inconsistency here is confusing and maybe should be highlighted in the readme.

CarloDePieri avatar Feb 14 '21 11:02 CarloDePieri

Actually, I realized that being bottom-up, the second part of my previous report was not really the best example. Allow me to present a more common use case with the relative issues:

  • While the cwd is different from the init.vim path (mkdir test; echo 'from' > test.vim and then nvim -u init.vim test/test.vim):

    • When using the default far source, :Far from to % will find no match, BUT the cwd will change to the path of the file, so repeating the command will work now. Do note that the cwd is permanently changed, which is bad IMO.

    • When using an alternative source, like rg:

      • Trying the replacement with % as file mask will find the match, but trying to replace with :Fardo will not work, leaving the match line red colored. The cwd will not change.
      • Trying this replacement will work :Far from to test/test.vim as expected, which is strange since test/test.vim is the expansion of %.

CarloDePieri avatar Feb 15 '21 12:02 CarloDePieri

No luck, I have tried with both rg and ag and I get the same problem when running :Fardo. I tried with vimgrep too, but it doesn't even find matches in the current file when using %. I guess I'll continue to use sed for replacing text in the current buffer.

alexcocinda avatar Apr 02 '21 07:04 alexcocinda

I found a workaround for replacing text in the current buffer. I saw in ChristianChiarulli's nvcode repo that he use different sources for the current buffer and for the project, but I didn't understand why at that time. The solution is to use always use vimgrep for the current buffer and use %:p instead of plain %. For example: :Far --source=vimgrep from to %:p. Refer to this for more details about the % register.

alexcocinda avatar Apr 02 '21 08:04 alexcocinda