Perform search in files easily
Clone or download
eugen0329 #42 fix case insensitive matching for pt (#44)
#42 fix case insensitive matching
Latest commit 9d26f8d Sep 5, 2018

README.md

Vim ESearch

Build Status Code Climate

NeoVim/Vim plugin performing project-wide async search and replace, similar to SublimeText, Atom et al.

ESearch Demo gif


  1. Features
  2. Installation
  3. Usage
  4. Customization
    4.1. General Configs
    4.2. Mappings
    4.3. Colors

Features

  • Builtin support for superfast engines like ag (The Silver Searcher), ack, pt (The Platinum Searcher), rg (ripgrep), git-grep along with the native *nix util grep.
  • Advanced pattern input prompt with fuzzy- and spell suggestion-driven completion.
  • Live updating of results as in Emacs, SublimeText and similar (requires Vim 8 / NeoVim job control or vimproc to be installed).
  • Special esearch window or quickfix list, habitual for all, can be used as an output target.
  • Search-and-Replace feature with the same syntax as builtin :substitute command (Example :1,5ESubstitute/from/to/gc).
  • Collaborates with nerdtree to provide search in a specific directory.

Installation

In your ~/.config/nvim/init.vim or ~/.vimrc :

Plugin 'eugen0329/vim-esearch'

NOTE Plugin command (which comes with Vundle) can be replaced with another command of the plugin manager you use (Plug, NeoBundle etc.)

Usage

Type <leader>ff and insert a search pattern (usually <leader> is \). Use s, v and t buttons to open file under the cursor in split, vertical split and in tab accordingly. Use Shift along with s, v and t buttons to open a file silently. Press Shift-r to reload currrent results.

To switch between case-sensitive/insensitive, whole-word-match and regex/literal pattern in command line use Ctrl-oCtrl-r, Ctrl-oCtrl-s or Ctrl-oCtrl-w (mnemonics is set Option: Regex, case Sesnsitive, Word regex).

Customization

General Configs

Global ESearch configuration example:

let g:esearch = {
  \ 'adapter':    'ag',
  \ 'backend':    'vimproc',
  \ 'out':        'win',
  \ 'batch_size': 1000,
  \ 'use':        ['visual', 'hlsearch', 'last'],
  \}
  • 'adapter'
    Adapter is a system-wide executable, which is used to dispatch your search request. Currently available adapters are 'ag', 'ack', 'pt', 'rg', 'git' and 'grep'.
  • 'backend'
    Backend is a strategy, which is used to collaborate with an adapter. Currently available: async backends - 'nvim', 'vimproc', 'vim8', and vim builtin system() func call based backend 'system'
    NOTE 'nvim' and 'vimproc' requires NeoVim and vimproc respectively.
  • 'out'
    Results output target: 'win' - ESearch window (see demo) or 'qflist' - quickfix window
  • 'batch_size'
    So not to hang your vim while updating results, ESearch uses batches. Thus, 'batch_size' refers to the number of result lines can be processed at one time
  • 'use'
    With this option you can specify the initial search request string, which will be picked from a specific source. Order is relevant for priorities of this sources usage. To always start with an empty input - set this option to []. Sources are:
    • 'visual'
      Selected text. Only available from the visual mode.
    • 'hlsearch'
      Current search (with /) highlight
    • 'last'
      Previously used ESearch pattern
    • 'clipboard'
      Text yanked with y, deleted with s, l etc.
    • 'system_clipboard'
      Text you copied with Ctrl-c or cut with Ctrl-x.
    • 'system_selection_clipboard'
      Text selected with mouse or other similar method (only works on Linux).
    • 'word_under_cursor'
      A word under the cursor.

Mappings

In ~/.config/nvim/init.vim / ~/.vimrc:

Use the following functions to redefine default mappings (NOTE default mapping are listed as an example here):

    " Start esearch prompt autofilled with one of g:esearch.use initial patterns
    call esearch#map('<leader>ff', 'esearch')
    " Start esearch autofilled with a word under the cursor
    call esearch#map('<leader>fw', 'esearch-word-under-cursor')

    call esearch#out#win#map('t',       'tab')
    call esearch#out#win#map('i',       'split')
    call esearch#out#win#map('s',       'vsplit')
    call esearch#out#win#map('<Enter>', 'open')
    call esearch#out#win#map('o',       'open')

    "    Open silently (keep focus on the results window)
    call esearch#out#win#map('T', 'tab-silent')
    call esearch#out#win#map('I', 'split-silent')
    call esearch#out#win#map('S', 'vsplit-silent')

    "    Move cursor with snapping
    call esearch#out#win#map('<C-n>', 'next')
    call esearch#out#win#map('<C-j>', 'next-file')
    call esearch#out#win#map('<C-p>', 'prev')
    call esearch#out#win#map('<C-k>', 'prev-file')

    call esearch#cmdline#map('<C-o><C-r>', 'toggle-regex')
    call esearch#cmdline#map('<C-o><C-s>', 'toggle-case')
    call esearch#cmdline#map('<C-o><C-w>', 'toggle-word')
    call esearch#cmdline#map('<C-o><C-h>', 'cmdline-help')

To redefine results match highlight use:

Colors

hi ESearchMatch ctermfg=black ctermbg=white guifg=#000000 guibg=#E6E6FA

Known issues

  • Ignore case option in pt works by building a regex so as a result you have implicit regexp matching here and have to escape special characters or switch to case sensitive mode.