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

Find in files #259

Open
gbaoye opened this issue Dec 13, 2020 · 21 comments
Open

Find in files #259

gbaoye opened this issue Dec 13, 2020 · 21 comments
Labels

Comments

@gbaoye
Copy link

gbaoye commented Dec 13, 2020

简单而快速的批处理任务,在文本编辑软件中,有着无法取代的位置。

@zufuliu
Copy link
Owner

zufuliu commented Dec 13, 2020

需要些什么处理?查找和替换?

@gbaoye
Copy link
Author

gbaoye commented Dec 18, 2020

需要些什么处理?查找和替换?

对的,类似于弹出一个批处理的UI,然后,添加一些简单的编辑选项,对文件夹内所有的文本进行批量处理,这是一个非常伟大的功能,无论以后文本编译类的软件有多么的先进好用,而你的软件会在他们的电脑中,有着无法取代的地位。

@zufuliu
Copy link
Owner

zufuliu commented Dec 18, 2020

只能做个皮,对下面三个工具进行包装:

  1. https://github.com/BurntSushi/ripgrep (VS Code 使用这个工具,不支持 .hgignore 文件)
  2. https://github.com/ggreer/the_silver_searcher (支持 glob 形式的 .hgignore 文件)
  3. grep (需要自己编译不依赖 cygwin 或 msys 的,比如 http://gnuwin32.sourceforge.net/packages/grep.htm

自己写个工具不能保证性能。

@gbaoye
Copy link
Author

gbaoye commented Dec 20, 2020

只能做个皮,对下面三个工具进行包装:

  1. https://github.com/BurntSushi/ripgrep (VS Code 使用这个工具,不支持 .hgignore 文件)
  2. https://github.com/ggreer/the_silver_searcher (支持 glob 形式的 .hgignore 文件)
  3. grep (需要自己编译不依赖 cygwin 或 msys 的,比如 http://gnuwin32.sourceforge.net/packages/grep.htm

自己写个工具不能保证性能。

谢谢.....

@RomeoZhZh
Copy link

我也非常喜欢你写的Notepad2工具,很轻量,很好用,但是美中不足的就是不能自带的批量查找和替换指定目录及子目录里面的所有文件。建议作者大牛增加这个功能,那就完美了。类似于sublime的在文件夹中查找替换的功能,非常感谢,盼回复

@zufuliu
Copy link
Owner

zufuliu commented Mar 16, 2021

可以先用 https://tools.stefankueng.com/grepWin.html
打开 https://tortoisesvn.net/ 点右上面的 Other tools 打开 https://tools.stefankueng.com/

@gbaoye
Copy link
Author

gbaoye commented Mar 16, 2021

可以先用 https://tools.stefankueng.com/grepWin.html
打开 https://tortoisesvn.net/ 点右上面的 Other tools 打开 https://tools.stefankueng.com/

不不不,你误会我们了,我们对你寄予厚望,我们希望你可以代替notepad++,如果可以,你可以改掉你的名字,因为太2了,这是你的软件,以你的方式命名,不是notepad1,notepad2,notepad3,你可以尊重你那些先驱者,但是,别忘记这是你的东西,世间万物尤甚于此,优胜劣汰,有些东西应该被提起,但是不该被铭记,就像notepad++一样

@RomeoZhZh
Copy link

RomeoZhZh commented Mar 17, 2021

可以先用 https://tools.stefankueng.com/grepWin.html
打开 https://tortoisesvn.net/ 点右上面的 Other tools 打开 https://tools.stefankueng.com/

大牛,我和gbaoye的意思就是希望你的notepad2工具能够强大到代替其他的开发工具。
需求背景是这样的:
我们是做程序开发的,特别是像php和html及js等不需要像java那样编译的开发,之前是用Adobe Dreamweaver,后面又用了phpstorm,vscode等不同的工具,像我们开发经验在10年以上的,已经不需要那些繁重的工具,恰恰相反,我们只需要像记事本这样简单的工具就能满足我们,越简单越好,多年以前我一直用基础的notepad2版本,比系统自带的记事本强大,后来接触了大牛你的notepad2版本,发现除了强大记事本的功能外还发现支持各种语言语法展示及提示,那这样就能满足我们90%开发工具的需求,但是使用过程中发现有一点无法满足我们,就是查找或者替换现在只能基于当前打开的文档,而不能批量搜索整个目录及子目录, 也就是像notepad++或sublime或者dreamweaver那样的在文件夹中查找替换,我们是希望在现在notepad2的查找或者替换的时候,支持指定目录及子目录,而不是借助其他工具,借助其他工具,就又搞麻烦了,还不如用notepad++或sublime。因为这个操作是经常要做的,这样就能满足我把notepad2作为开发工具的需求了。 我应该说明白了吧。感谢

在文件夹中查找的时候列出匹配到的关键词,替换的时候告诉我哪些替换了,可以新开个对话窗口之类的列表就可以。

@zufuliu zufuliu changed the title 建议添加文件夹批量处理 Find in files Mar 17, 2021
@RomeoZhZh
Copy link

谢谢,简而言之就是 Find in files,有这个功能,就可以100%满足我作为php,html,JS 甚至C++和java的开发了,希望保持目前快速打开文件的性能,不要加太多臃肿的功能上去,我就是喜欢用notepad2打开文件,瞬间打开的感觉。感谢并支持你zufuliu。

@PNBRQK
Copy link

PNBRQK commented Mar 18, 2021

好像SciTE就有这个功能

@RomeoZhZh
Copy link

@zufuliu 除了 Find in files 应该对应的还有Replace in files 。
@PNBRQK 虽然这个有,但是我感觉notepad2 还是更简洁快速,只缺这个在文件夹中查找和替换了。

@lifenjoiner
Copy link
Contributor

个人愚见:
首先明确一下概念:单标签 (Single-tab)多标签 (Multi-tab)程序。明显,Notepad2 是单标签;Notepad++ 是多标签
然后,没有Find/Replace in Files就可以理解了。
多标签程序一个进程可以打开多个文件,会有SessionWorkspace的概念;单标签程序一个进程只可以打开一个文件,没有SessionWorkspace的概念(多个进程之间难协调)。
没有Workspace概念的话,加Find/Replace in Files反倒有些突兀……

Unix philosophy

Write programs that do one thing and do it well.
Write programs to work together.

专门的事情留给专门的软件做,继续保持Notepad2的小而美也挺好的~

@zufuliu
Copy link
Owner

zufuliu commented Sep 24, 2021

This feature depends on issue #382.

@lifenjoiner
Copy link
Contributor

lifenjoiner commented Jan 25, 2024

有人有兴趣试一下 CI Artifacts,给一些反馈吗?
用法在 #758
如果再能增加自定义按钮,对于喜欢用鼠标的也方便了。
CC: @Leroy-X

@zufuliu zufuliu pinned this issue Jan 27, 2024
@zufuliu zufuliu added the 🛠workaround Workaround available label Jan 27, 2024
@zufuliu
Copy link
Owner

zufuliu commented Jan 27, 2024

https://github.com/zufuliu/FindInFiles is "Find in Files" prototype (in C#), we can use this as workaround (e.g. ship with v4.24.03) before porting the code to C/C++.

Here is the program (requires .NET Desktop Runtime 8) and screenshot: FindInFiles-20240127.zip

Animation

@Sergy2001, @lifenjoiner any of you interested in porting the code to Notepad2, major works:

  • add a modeless dialog "Tools -> Find in Files", use current file as search path.
  • use a Scintilla window instead of rich text box as find result window (see issue Find result window #382), we can add a simple lexer or use container lexer.
  • write code to capture process output (e.g. based on SciTEWin::ExecuteOne() from SciTE's SciTEWin.cxx).
  • add a simple JSON parser (e.g. based on the one in https://github.com/zufuliu/llvm-utils/blob/main/clang/run-clang-tidy.cpp) to parse ripgrep output.
  • format ripgrep output and highlight matched text with persistent indicators.
  • double click to open Notepad2.

I think we can use main window as find result window (adding "Find in Files" mode in addition to normal and "Paste Board" modes, launch Notepad2 in this mode after click "Find in Files"), this would have less changes than put Scintilla window on the "Find in Files" dialog, and we can add more controls (to expose more options) on the dialog.

@zufuliu
Copy link
Owner

zufuliu commented Jan 27, 2024

Here is the program

Latest build is available at https://github.com/zufuliu/FindInFiles/actions, just unpack FindInFiles.zip and ripgrep (rg.exe, please download from https://github.com/BurntSushi/ripgrep/releases) to the same folder as Notepad2.exe.

@lifenjoiner
Copy link
Contributor

喔~ 您又花这么大力气专门写了一个程序!Respect ~

我的想法是这样的:

通过参数 /content /searchpath:"%cd%" 切换到 grepWin,并通过其 editorcmd=notepad2 /g %line% %path% 配置切换回来,是一种无需额外维护的简单方法。
这将是一种弱耦合,但足够好,模块化,并实现了“替换所有文件”的需求。

顺便说一下:用户甚至可以配置其他外部工具,这将是灵活的。


Switching into grepWin by parameters /content /searchpath:"%cd%", and switching back by its editorcmd=notepad2 /g %line% %path% config, is an easier way without extra maintenance.
It will be weak coupling, but good enough, modular, and solves "replace in files".

BTW: Even, users may configure their other external tools, that will be flexible.

@zufuliu
Copy link
Owner

zufuliu commented Jan 27, 2024

The prototype is just 300 lines (C#), and already works for most task, the drawback is it's depends on .NET.
I like the highlighted output (very close to VSCode, which also uses ripgrep for Find in Files). the output is better than grepWin's list box, without highlighting we could make a simple wrapper for exiting grep tools.

VSCodeFindResult

grepWin

@lifenjoiner
Copy link
Contributor

lifenjoiner commented Jan 27, 2024

For grepWin, choose "content" mode (UI: right bottom; CLI: /content) will be a bit better, although still no highlight.

BTW:

@zufuliu
Copy link
Owner

zufuliu commented Jan 27, 2024

  • I found dnGrep with highlight

It's also C# (WPF + ICSharpCode.AvalonEdit?). DocFetcher requires Java, AstroGrep requires .NET Framework 4.5 (should not a problem for most user). I can convert my prototype to .NET Framework + Json.NET to remove the dependecy on .NET Desktop Runtime.

@zufuliu
Copy link
Owner

zufuliu commented Jan 30, 2024

Standalone 27 KB FindInFiles.exe for .NET Framework 4.8 is available at https://github.com/zufuliu/FindInFiles/actions (e.g. download FindInFiles-net4.8 from https://github.com/zufuliu/FindInFiles/actions/runs/7710478194).

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

No branches or pull requests

5 participants