Skip to content
suewonjp edited this page Feb 7, 2017 · 3 revisions

g - Quickly search text from files

gi - Same as g except that case insensitive matching is performed

General Usages

g and gi commands search text from files returned by lf or lfi

  1. g [ text pattern ] [ params for lf ... ]
  • The 1st parameter [text pattern] is Basic Regular Expression (which is used by the regular grep command by default) pattern.
  • All parameters except the 1st parameter obey the rule of lf command
  1. g
  • Will show help message

Basically, g and gi commands have the same quirks that lf command has because it is invoked behind the scene;
See lf or lfi for more details

Examples

$ cat Documents/test/tmp.txt

Java
JavaScript

$ g [Jj]ava$ . Docu .txt

Documents/text/tmp.txt:1:Java

$ g

... help message ...

How To Override Behavior Of g Using _LIST_FILE_GREP_OPTIONS

g command invokes grep -n by default

You can override this default setting by defining _LIST_FILE_GREP_OPTIONS environment variable

For example, you can do as follows to make g accept Extended Regular Expression pattern

    $ _LIST_FILE_GREP_OPTIONS="-E -n"

Unset _LIST_FILE_GREP_OPTIONS as follows to restore the default setting

    $ unset _LIST_FILE_GREP_OPTIONS

Notice that making _LIST_FILE_GREP_OPTIONS empty as follows will have a complete different effect; ( It wont't provide any parameter for grep unlike the default setting which is grep -n )

    $ _LIST_FILE_GREP_OPTIONS=

Also notice that g ignores GREP_OPTIONS variable so setting GREP_OPTIONS for other applications doesn't affect behavior of g
( See man page for grep about GREP_OPTIONS )