/docs/_posts/2018-01-23-grep-on-the-fly-in-spacevim.md

https://github.com/SpaceVim/SpaceVim · Markdown · 99 lines · 68 code · 31 blank · 0 comment · 0 complexity · 4891abc1ca338a49e962eaa628d12ce1 MD5 · raw file

  1. ---
  2. title: "Grep on the fly in SpaceVim"
  3. categories: [feature, blog]
  4. description: "Grep and replace asynchronously, display searching results on the fly based on user input"
  5. image: https://user-images.githubusercontent.com/13142418/80607963-b704d300-8a68-11ea-99c4-5b5bd653cb24.gif
  6. commentsID: "Grep on the fly"
  7. comments: true
  8. ---
  9. # [Blogs](../blog/) >> Asynchronous grep on the fly
  10. {{ page.date | date_to_string }}
  11. FlyGrep means **grep on the fly**, it will update the result as you type. Of course, it is running
  12. asynchronously. Before using this feature, you need to install a searching tool. FlyGrep works
  13. through search tools: `ag`, `rg`, `ack`, `pt` and `grep`, Choose one you like.
  14. This ia a built-in plugin in SpaceVim, and we also separated a plugin : [FlyGrep.vim](https://github.com/wsdjeg/FlyGrep.vim)
  15. ## Install
  16. In linux os, flygrep use grep by default, if you want a more fast tool, you can choose one of following:
  17. - [ripgrep(rg)](https://github.com/BurntSushi/ripgrep)
  18. - [the_silver_searcher(ag)](https://github.com/ggreer/the_silver_searcher)
  19. - [the_platinum_searcher(pt)](https://github.com/monochromegane/the_platinum_searcher)
  20. ## Features
  21. - **Search in a project**
  22. In SpaceVim, you can use `SPC s p` or `SPC s /` to search in the current project.
  23. ![searching project](https://user-images.githubusercontent.com/13142418/80607963-b704d300-8a68-11ea-99c4-5b5bd653cb24.gif)
  24. - **Search in current file**
  25. You can use `SPC s s` to search in the current file. To search word under the cursor, you can press `SPC s S`.
  26. ![searching current file](https://user-images.githubusercontent.com/13142418/35278847-e0032796-0010-11e8-911b-2ee8fd81aed2.gif)
  27. - **Search in all loaded buffers**
  28. 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.
  29. ![searching-loaded-buffer](https://user-images.githubusercontent.com/13142418/35278996-518b8a34-0011-11e8-9a7a-613668398ee2.gif)
  30. - **Search in an arbitrary directory**
  31. If you want to searching in a different directory instead of current directory, you can
  32. use `SPC s f`. Then insert the path of the arbitrary directory.
  33. - **Search in a project in the background**
  34. 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.
  35. ## Key bindings
  36. 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`.
  37. 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.
  38. 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.
  39. The tool keys are:
  40. | Tool | Key |
  41. | ---- | --- |
  42. | ag | a |
  43. | grep | g |
  44. | ack | k |
  45. | rg | r |
  46. | pt | t |
  47. The available scopes and corresponding keys are:
  48. | Scope | Key |
  49. | -------------------------- | --- |
  50. | opened buffers | b |
  51. | files in a given directory | f |
  52. | current project | p |
  53. **Within FlyGrep buffer:**
  54. | Key Bindings | Descriptions |
  55. | ----------------- | --------------------------------- |
  56. | `<Esc>` | close FlyGrep buffer |
  57. | `<Enter>` | open item in current window |
  58. | `Ctrl-t` | open item in new tab |
  59. | `<Tab>` | move cursor line down |
  60. | `Ctrl-j` | move cursor line down |
  61. | `Shift-<Tab>` | move cursor line up |
  62. | `Ctrl-k` | move cursor line up |
  63. | `<Backspace>` | remove last character |
  64. | `Ctrl-w` | remove the word before the cursor |
  65. | `Ctrl-u` | remove the line before the cursor |
  66. | `Ctrl-k` | remove the line after the cursor |
  67. | `Ctrl-a`/`<Home>` | Go to the beginning of the line |
  68. | `Ctrl-e`/`<End>` | Go to the end of the line |