nilsboy / vim-slash

Enhancing in-buffer search experience

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vim-slash

vim-slash provides a set of mappings for enhancing in-buffer search experience in Vim.

  • Automatically clears search highlight when cursor is moved
  • Improved star-search (visual-mode, highlighting without moving)

Installation

Using vim-plug:

Plug 'junegunn/vim-slash'

Configuration

Enable highlighting with moving:

let g:slash_immobile = 0

Comparison with vim-oblique

vim-slash is a smaller alternative to vim-oblique. vim-oblique depends on a reimplementation of Vim command-line interface which is incomplete and has a number of issues that cannot be easily fixed. vim-oblique is also much slower than the native /-search when working with large files.

Many features of vim-oblique are missing in vim-slash, but frankly, my dear, I don't give a damn.

Customization

zz after search

Places the current match at the center of the window.

noremap <plug>(slash-after) zz

Blinking line after search

function! s:flash()
  set cursorline!
  redraw
  sleep 20m
  set cursorline!
  return ''
endfunction

noremap <expr> <plug>(slash-after) <sid>flash()

Non-blocking blinking using Vim 8 timers

function! s:blink(times, delay)
  let s:blink = { 'ticks': 2 * a:times, 'delay': a:delay }

  function! s:blink.tick(_)
    let self.ticks -= 1
    let active = self == s:blink && self.ticks > 0

    if !self.clear() && active && &hlsearch
      let [line, col] = [line('.'), col('.')]
      let w:blink_id = matchadd('IncSearch',
            \ printf('\%%%dl\%%>%dc\%%<%dc', line, max([0, col-2]), col+2))
    endif
    if active
      call timer_start(self.delay, self.tick)
    endif
  endfunction

  function! s:blink.clear()
    if exists('w:blink_id')
      call matchdelete(w:blink_id)
      unlet w:blink_id
      return 1
    endif
  endfunction

  call s:blink.clear()
  call s:blink.tick(0)
  return ''
endfunction

noremap <expr> <plug>(slash-after) <sid>blink(2, 50)

About

Enhancing in-buffer search experience


Languages

Language:Vim Script 100.0%