Skip to content
Iury O. G. Figueiredo edited this page Jun 24, 2020 · 2 revisions

A vy plugin to do quick searches in large code bases with the_silver_searcher. This plugin is very handy for quickly looking up snippets, jumping to specific project code lines etc.

Install

The plugin uses https://github.com/ggreer/the_silver_searcher it is necessary to install that package.

Then uncomment the code below in your ~/.vy/vyrc file.

# Used to perform lax searches over pre defined
# folders.
# from vyapp.plugins.sniper import Sniper
# Setup the path for where sniper will 
# search for string patterns when in wide search
# mode.
# Sniper.DIRS = ['/home/user/projects']
# autocall(Sniper)

Usage

The sniper plugin is mostly useful for quickly looking up snippets in large code bases. It also can be used to look up string patterns in project files. It is inspired by https://github.com/vyapp/fstmt plugin.

The most basic usage consists of searching for a given string in the folders that were specified when adding sniper to your vyrc file.

Most of the sniper key commands are implemented in INPUT mode, it means that sniper changes its state when the input text widget is active and the key presses are performed.

The plugin implements just two key commands in NORMAL mode.

<Key-B>

The above key command displays an input text widget it is meant to be in INPUT mode when it happens. Once in INPUT mode you can press key commands to set how sniper will work.

The key commands to set sniper options are described below.

These key commands are trigged in INPUT mode it is when the input text widget is active.

Set LAX search type:

<Key-x>

After pressing the above key command in INPUT mode you would see a message informing the search type has changed to LAX.

The LAX search works like this:

Suppose you insert the following string:

de pat pr

The above string would be split by using space and would turn into a list:;

['de', 'pat', 'pr']

After that sniper turns it back into a regex string like:

de.+pat.+pr

Then it performs the search using that regex in the defined folders or in the current opened file project, the latter happens when wide search is set to False.

In the above example it would match lines like:

def set_pattern_priority
def get_path_project
.
.
.

This is very useful to spare time for looking up files or just jumping to specific regions of code in your project.

Set REGEX search type:

<Key-r>

The above key command set the search type to REGEX when it is pressed in INPUT mode. When REGEX search type is set it performs searches based on regex. You can insert a regex and it will use the_silver_searcher to perform the search.

Once the regex is inserted and your return key is pressed it will display all occurrences of the pattern in the searched files. You can browse them

Notice that if you wanted to open a given occurrence in the current AreaVi instance then you could press:

<Key-S>

When in the dialog window that displays the matches.

Set LITERAL search:

<Key-l>

The above key command when pressed in INPUT mode it allows one to perform literal pattern searches. It means that whatever you insert in the input text widget it will attempt to find identical occurrences of the pattern in the defined folders.

If you inserted the string below:

def chmod

Then sniper would show all places where the above string shows up.. It will try to find the string in each one of the files that are in the folders that were defined in the Sniper class variable DIRS.

The key command below is used to display again the results of the search:

<Key-b>

Set a file pattern to ignore:

<Key-i>

The key command above allows to set a file pattern to be ignored when performing the search. The silver searcher will ignore whatever looks like the pattern that was inserted.

Set wide search off:

<Key-w>

This key command can be set when you want to perform searches in files of a given project. The sniper plugin will try to find a .git, .hg or .svn file that corresponds to the project root of the current opened file. In case it doesn't find such a file it will try to search in your vy HOME directory. When vy HOME is not set then the search will be performed solely in the current opened file.

Note: The sniper module is documented and can have its documenttion inspected from vy.

Clone this wiki locally