如何使用 less 使用模式修饰符进行不区分大小写的搜索?
似乎执行此操作的唯一方法是在最初运行 less 时传递 -i 参数。 有谁知道一些秘密黑客可以让这样的事情发挥作用
/something to search for/i
It seems like the only way to do this is to pass the -i parameter in when you initially run less. Does anyone know of some secret hack to make something like this work
/something to search for/i
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您还可以在 less 运行时键入命令
-I
。 它切换搜索的大小写敏感性。You can also type command
-I
while less is running. It toggles case sensitivity for searches.您还可以设置环境变量
LESS
,我使用
LESS=-Ri
,这样我就可以将grep
的彩色输出泵入其中,并维护ANSI 颜色序列。我发现 less 的另一个很少使用的功能是以
+F
作为参数启动它(或者在 less 中点击 SHIFT+F )。 这会导致它跟随您打开的文件,就像tail -f
一样。 如果您正在从应用程序中查看日志文件,并且可能想要进行分页备份(例如,如果每秒生成 100 行日志记录),则非常方便。You can also set the environment variable
LESS
I use
LESS=-Ri
, so that I can pump colorized output fromgrep
into it, and maintain the ANSI colour sequences.Another little used feature of less that I found is starting it with
+F
as an argument (or hitting SHIFT+F while in less). This causes it to follow the file you've opened, in the same way thattail -f <file>
will. Very handy if you're watching log files from an application, and are likely to want to page back up (if it's generating 100's of lines of logging every second, for instance).补充@Juha所说的:实际上
-i
通过 SmartCasing 打开不区分大小写,即如果您的搜索包含大写字母,则搜索将区分大小写,否则,它将是不区分大小写。 可以将其视为 Vim 中的:set smartcase
。例如:使用
-i
,在“Log,..”中搜索“log”将匹配,而在“log,..”中搜索“Log”将不匹配。Add-on to what @Juha said: Actually
-i
turns on Case-insensitive with SmartCasing, i.e if your search contains an uppercase letter, then the search will be case-sensitive, otherwise, it will be case-insensitive. Think of it as:set smartcase
in Vim.E.g.: with
-i
, a search for 'log' in 'Log,..' will match, whereas 'Log' in 'log,..' will not match.看来您可以在每次搜索的基础上调用此功能,如下所示:
此选项位于
less
的交互式帮助中,您可以通过h
访问该帮助:我没有广泛使用已检查,但 MacOS 以及其他 Linux 发行版上的
less
版本 487 中的帮助将此选项列为可用。在 MacOS 上,您还可以通过
brew
安装更新版本的less
:参考资料
It appears that you can summon this feature on a per search basis like so:
This option is in
less
's interactive help which you access viah
:I've not extensively checked but the help in
less
version 487 on MacOS as well as other Linux distros lists this option as being available.On MacOS you can also install a newer version of
less
viabrew
:References
使用 -i 标志时,请确保完全以小写形式输入搜索字符串,因为如果任何字母为大写,则它是完全匹配的。
另请参阅:less(1) 的 -I(大写 i)标志来更改此行为。
When using -i flag, be sure to enter the search string completely in lower case, because if any letter is upper case, then its an exact match.
See also: the -I (capital i) flag of less(1) to change this behavior.