ayamir / nvimdots

A well configured and structured Neovim.
BSD 3-Clause "New" or "Revised" License
2.83k stars 451 forks source link

Find and replace text in project #1157

Closed kevin1sMe closed 3 months ago

kevin1sMe commented 5 months ago

Feature description

像VSCode中有Cmd+Shift+F在项目中全局搜索和替换,当前nvimdots好像不具备这个能力(或者有了请指教)。希望有类似功能,比如集成这个插件?

https://github.com/nvim-pack/nvim-spectre

CharlesChiuGit commented 5 months ago

Global search in project:

https://github.com/ayamir/nvimdots/blob/218838d15f7af7e250eb16b847485e85fca2a3d3/lua/keymap/tool.lua#L110-L115

Global rename in project:

https://github.com/ayamir/nvimdots/blob/218838d15f7af7e250eb16b847485e85fca2a3d3/lua/keymap/completion.lua#L40-L44

Jint-lzxy commented 5 months ago

And we've recently added nvim-bqf back in. You might want to give the fzf + :cdo combo a shot (I've been using this for quite some time lmao).

FYI: :h :vimgrep

                    *:vim* *:vimgrep* *E682* *E683*
:vim[grep][!] /{pattern}/[g][j][f] {file} ...
            Search for {pattern} in the files {file} ... and set
            the error list to the matches.  Files matching
            'wildignore' are ignored; files in 'suffixes' are
            searched last.

            {pattern} is a Vim search pattern.  Instead of
            enclosing it in / any non-ID character (see
            |'isident'|) can be used, so long as it does not
            appear in {pattern}.
            'ignorecase' applies.  To overrule it put |/\c| in the
            pattern to ignore case or |/\C| to match case.
            'smartcase' is not used.
            If {pattern} is empty (e.g. // is specified), the last
            used search pattern is used. |last-pattern|

            Flags:
            'g'  Without the 'g' flag each line is added only
                 once.  With 'g' every match is added.

            'j'  Without the 'j' flag Vim jumps to the first
                 match.  With 'j' only the quickfix list is
                 updated.  With the [!] any changes in the current
                 buffer are abandoned.

            'f'  When the 'f' flag is specified, fuzzy string
                 matching is used to find matching lines. In this
                 case, {pattern} is treated as a literal string
                 instead of a regular expression.  See
                 |fuzzy-matching| for more information about fuzzy
                 matching strings.

            |QuickFixCmdPre| and |QuickFixCmdPost| are triggered.
            A file that is opened for matching may use a buffer
            number, but it is reused if possible to avoid
            consuming buffer numbers.

and :h :cdo

                            *:cdo*
:cdo[!] {cmd}       Execute {cmd} in each valid entry in the quickfix list.
            It works like doing this: >
                :cfirst
                :{cmd}
                :cnext
                :{cmd}
                etc.
<           When the current file can't be |abandon|ed and the [!]
            is not present, the command fails.
            When going to the next entry fails execution stops.
            The last buffer (or where an error occurred) becomes
            the current buffer.
            {cmd} can contain '|' to concatenate several commands.

            Only valid entries in the quickfix list are used.
            A range can be used to select entries, e.g.: >
                :10,$cdo cmd
<           To skip entries 1 to 9.

            Note: While this command is executing, the Syntax
            autocommand event is disabled by adding it to
            'eventignore'.  This considerably speeds up editing
            each buffer.
            Also see |:bufdo|, |:tabdo|, |:argdo|, |:windo|,
            |:ldo|, |:cfdo| and |:lfdo|.
kevin1sMe commented 4 months ago

Global search in project:

https://github.com/ayamir/nvimdots/blob/218838d15f7af7e250eb16b847485e85fca2a3d3/lua/keymap/tool.lua#L110-L115

Global rename in project:

https://github.com/ayamir/nvimdots/blob/218838d15f7af7e250eb16b847485e85fca2a3d3/lua/keymap/completion.lua#L40-L44

这个不太符合诉求 , 这几个快捷键也有一直用,fw不能有条件过滤,也不能替换呀? 至于几个refactor的rename,有时是纯文本处理,不能完全依赖于LSP呢。

kevin1sMe commented 4 months ago

/open

ayamir commented 4 months ago

You can integrate it by yourself first. IMO the situation of pure text search and replace exists indeed.

kevin1sMe commented 4 months ago

And we've recently added nvim-bqf back in. You might want to give the fzf + :cdo combo a shot (I've been using this for quite some time lmao).

FYI: :h :vimgrep

                  *:vim* *:vimgrep* *E682* *E683*
:vim[grep][!] /{pattern}/[g][j][f] {file} ...
          Search for {pattern} in the files {file} ... and set
          the error list to the matches.  Files matching
          'wildignore' are ignored; files in 'suffixes' are
          searched last.

          {pattern} is a Vim search pattern.  Instead of
          enclosing it in / any non-ID character (see
          |'isident'|) can be used, so long as it does not
          appear in {pattern}.
          'ignorecase' applies.  To overrule it put |/\c| in the
          pattern to ignore case or |/\C| to match case.
          'smartcase' is not used.
          If {pattern} is empty (e.g. // is specified), the last
          used search pattern is used. |last-pattern|

          Flags:
          'g'  Without the 'g' flag each line is added only
               once.  With 'g' every match is added.

          'j'  Without the 'j' flag Vim jumps to the first
               match.  With 'j' only the quickfix list is
               updated.  With the [!] any changes in the current
               buffer are abandoned.

          'f'  When the 'f' flag is specified, fuzzy string
               matching is used to find matching lines. In this
               case, {pattern} is treated as a literal string
               instead of a regular expression.  See
               |fuzzy-matching| for more information about fuzzy
               matching strings.

          |QuickFixCmdPre| and |QuickFixCmdPost| are triggered.
          A file that is opened for matching may use a buffer
          number, but it is reused if possible to avoid
          consuming buffer numbers.

and :h :cdo

                          *:cdo*
:cdo[!] {cmd}     Execute {cmd} in each valid entry in the quickfix list.
          It works like doing this: >
              :cfirst
              :{cmd}
              :cnext
              :{cmd}
              etc.
<         When the current file can't be |abandon|ed and the [!]
          is not present, the command fails.
          When going to the next entry fails execution stops.
          The last buffer (or where an error occurred) becomes
          the current buffer.
          {cmd} can contain '|' to concatenate several commands.

          Only valid entries in the quickfix list are used.
          A range can be used to select entries, e.g.: >
              :10,$cdo cmd
<         To skip entries 1 to 9.

          Note: While this command is executing, the Syntax
          autocommand event is disabled by adding it to
          'eventignore'.  This considerably speeds up editing
          each buffer.
          Also see |:bufdo|, |:tabdo|, |:argdo|, |:windo|,
          |:ldo|, |:cfdo| and |:lfdo|.

嗯 ,这个是可能比较长的操作链条达成的效果,没有那么所见即所得,另外我本地运行这块很慢,和vscode下没法比,不确定啥原因

CharlesChiuGit commented 4 months ago

i think u just need to learn (n)vim more.

https://vim.fandom.com/wiki/Search_and_replace

it's literally "see as u do" from a pure text operation perspective.

CharlesChiuGit commented 4 months ago

u can always learn vim in vscode first 'til u are comfortable enough to use nvim directly.

https://github.com/vscode-neovim/vscode-neovim

CharlesChiuGit commented 4 months ago

另外我本地运行这块很慢,和vscode下没法比,不确定啥原因

we're not psychics.

kevin1sMe commented 3 months ago

u can always learn vim in vscode first 'til u are comfortable enough to use nvim directly.

https://github.com/vscode-neovim/vscode-neovim

Thank you for the reminder. I've been using vim for many years, and have been coding exclusively in vim for 4-5 years. I indeed haven't been exposed to nvim for long. I am familiar with things like %s, <>, vimgrep, sed/awk, etc.

It seems that @Jint-lzxy @ayamir understand my concerns. Your reply, however, doesn't offer anything constructive, I'm sorry, but I don't feel it's helpful to me. This project is great, and I've recommended it on my blog before. I hope it continues to grow and improve!

ayamir commented 3 months ago

This project is great, and I've recommended it on my blog before. I hope it continues to grow and improve!

I'm looking for an internship recently and just passed the HR interview of Tencent lol. So I have sometime to improve this project now. Currently working for refactoring the plugins.