1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-24 06:20:05 +08:00
SpaceVim/docs/_posts/2018-01-23-grep-on-the-fly-in-spacevim.md

99 lines
4.4 KiB
Markdown
Raw Normal View History

2018-01-23 20:23:05 +08:00
---
2018-01-23 21:40:47 +08:00
title: "Grep on the fly in SpaceVim"
2018-05-27 20:54:33 +08:00
categories: [feature, blog]
2018-01-23 22:03:35 +08:00
excerpt: "Run grep asynchronously, show search results in real-time based on user input, support searching the entire project, searching loaded files or only searching current file"
2018-01-23 21:40:47 +08:00
image: https://user-images.githubusercontent.com/13142418/35278709-7856ed62-0010-11e8-8b1e-e6cc6374b0dc.gif
2018-07-05 16:22:44 +08:00
commentsID: "Grep on the fly"
comments: true
2018-01-23 20:23:05 +08:00
---
2019-01-19 12:03:26 +08:00
# [Blogs](../blog/) >> Asynchronous grep on the fly
{{ page.date | date_to_string }}
2018-01-23 20:23:05 +08:00
2018-01-23 21:40:47 +08:00
FlyGrep means **grep on the fly**, it will update the result as you type. Of course, it is running
2018-01-23 23:28:53 +08:00
asynchronously. Before using this feature, you need to install a searching tool. FlyGrep works
through search tools: `ag`, `rg`, `ack`, `pt` and `grep`, Choose one you like.
2018-01-23 20:23:05 +08:00
2018-01-23 23:28:53 +08:00
This ia a built-in plugin in SpaceVim, and we also separated a plugin : [FlyGrep.vim](https://github.com/wsdjeg/FlyGrep.vim)
2018-01-23 21:00:47 +08:00
## Install
In linux os, flygrep use grep by default, if you want a more fast tool, you can choose one of following:
- [ripgrep(rg)](https://github.com/BurntSushi/ripgrep)
- [the_silver_searcher(ag)](https://github.com/ggreer/the_silver_searcher)
- [the_platinum_searcher(pt)](https://github.com/monochromegane/the_platinum_searcher)
2018-01-23 21:00:47 +08:00
## Features
2018-01-23 20:23:05 +08:00
2018-01-23 23:28:53 +08:00
- **Search in a project**
2018-01-23 21:40:47 +08:00
2018-01-23 23:28:53 +08:00
In SpaceVim, you can use `SPC s p` or `SPC s /` to search in the current project.
2018-01-23 21:40:47 +08:00
![searching project](https://user-images.githubusercontent.com/13142418/35278709-7856ed62-0010-11e8-8b1e-e6cc6374b0dc.gif)
2018-01-23 23:28:53 +08:00
- **Search in current file**
2018-01-23 21:00:47 +08:00
2018-01-23 23:28:53 +08:00
You can use `SPC s s` to search in the current file. To search word under the cursor, you can press `SPC s S`.
2018-01-23 21:00:47 +08:00
2018-01-23 21:40:47 +08:00
![searching current file](https://user-images.githubusercontent.com/13142418/35278847-e0032796-0010-11e8-911b-2ee8fd81aed2.gif)
2018-01-23 23:28:53 +08:00
- **Search in all loaded buffers**
2018-01-23 21:00:47 +08:00
To searching in all loaded buffers, you need to press `SPC s b`, and you can also use `SPC s B` to search word under the point.
2018-01-23 21:40:47 +08:00
![searching-loaded-buffer](https://user-images.githubusercontent.com/13142418/35278996-518b8a34-0011-11e8-9a7a-613668398ee2.gif)
2018-01-23 21:00:47 +08:00
2018-01-23 23:28:53 +08:00
- **Search in an arbitrary directory**
2018-01-23 21:00:47 +08:00
2018-01-23 21:40:47 +08:00
If you want to searching in a different directory instead of current directory, you can
use `SPC s f`. Then insert the path of the arbitrary directory.
2018-01-23 21:00:47 +08:00
2018-01-23 23:28:53 +08:00
- **Search in a project in the background**
2018-01-23 21:08:20 +08:00
2018-01-23 23:28:53 +08:00
If you need background searching, you can press `SPC s j`, after searching is done, the index will be displayed on statusline. you can use `SPC s l` to list all the search results.
2018-01-23 20:23:05 +08:00
2018-01-23 21:00:47 +08:00
## Key bindings
The search commands in SpaceVim are organized under the `SPC s` prefix with the next key is the tool to use and the last key is the scope. For instance `SPC s a b` will search in all opened buffers using `ag`.
If the last key (determining the scope) is uppercase then the current word under the cursor is used as default input for the search. For instance `SPC s a B` will search with word under cursor.
2018-01-23 23:28:53 +08:00
If the tool key is omitted then a default tool will be automatically selected for the search. This tool corresponds to the first tool found on the system of the list `g:spacevim_search_tools`, the default calling sequence is `rg`, `ag`, `pt`, `ack` then `grep`. For instance `SPC s b` will search in the opened buffers using `pt` if `rg` and `ag` have not been found on the system.
2018-01-23 21:00:47 +08:00
The tool keys are:
| Tool | Key |
| ---- | --- |
| ag | a |
| grep | g |
| ack | k |
| rg | r |
| pt | t |
2018-01-23 20:23:05 +08:00
2018-01-23 21:00:47 +08:00
The available scopes and corresponding keys are:
2018-01-23 20:23:05 +08:00
2018-01-23 21:00:47 +08:00
| Scope | Key |
| -------------------------- | --- |
| opened buffers | b |
| files in a given directory | f |
| current project | p |
2018-01-23 20:23:05 +08:00
2018-01-23 21:00:47 +08:00
**Within FlyGrep buffer:**
2018-01-23 20:23:05 +08:00
2018-01-23 21:08:20 +08:00
| Key Binding | Description |
| ---------------- | --------------------------------- |
| `<Esc>` | close FlyGrep buffer |
| `<Enter>` | open file at the cursor line |
| `<Tab>` | move cursor line down |
| `<C-j>` | move cursor line down |
| `<S-Tab>` | move cursor line up |
| `<C-k>` | move cursor line up |
| `<Bs>` | remove last character |
2018-01-23 23:28:53 +08:00
| `<C-w>` | remove the word before the cursor |
| `<C-u>` | remove the line before the cursor |
| `<C-k>` | remove the line after the cursor |
2018-01-23 21:08:20 +08:00
| `<C-a>`/`<Home>` | Go to the beginning of the line |
| `<C-e>`/`<End>` | Go to the end of the line |