GithubHelp home page GithubHelp logo

vim-search-pulse's Introduction

The vim search pulse plugin: easily locate the cursor after a search

Description

When you perform a search, the cursor jumps to the closest match. It's often hard to locate it's new position. With this plugin the cursor line (by default) or the search pattern will "pulse" thus requiring your eyes attention.

For the cursor line to be set only in the active window you may want to install this plugin: https://github.com/vim-scripts/CursorLineCurrentWindow

Activate the cursor line highlighing by putting set cursorline in your .vimrc file.

Cursor line pulse animation:

cursor line pulse

Pattern pulse animation:

pattern pulse

Installation

Use pathogen or a pathogen compatible plugin manager.

Configuration

Sets whether the cursor line pulses (default is cursor_line):

let g:vim_search_pulse_mode = 'cursor_line'

or just the search pattern:

let g:vim_search_pulse_mode = 'pattern'

If you want to set your own mappings, do:

let g:vim_search_pulse_disable_auto_mappings = 1

Otherwise the plugin will do the following for you:

nmap n n<Plug>Pulse
nmap N N<Plug>Pulse
nmap * *<Plug>Pulse
nmap # #<Plug>Pulse
" Pulses cursor line on first match
" when doing search with / or ?
cmap <silent> <expr> <enter> search_pulse#PulseFirst()

The pulse duration is 200 milliseconds by default. You can set your own using the following global variable. For example:

let g:vim_search_pulse_duration = 400

The colors used by the pulse are [237, 238, 239, 240, 241] (gray scale) by default. A color map can be found at: http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html

You can set your own and as many as you want using the following global variable. For example (green scale):

let g:vim_search_pulse_color_list = [22, 28, 34, 40, 46]

If you are using gvim, these are the default colors:

`['#3a3a3a', '#444444', '#4e4e4e', '#585858', '#606060']`

To disable/enable set the value of g:vim_search_pulse_disable to 0 or 1

To execute arbitrary commands before and after pulse runs, use these autocmds:

autocmd User PrePulse
autocmd User PostPulse

For example, to turn on cursorcolumn during the pulse and then off right after:

augroup Pulse
    autocmd! User PrePulse
    autocmd! User PostPulse
    autocmd  User PrePulse  set cursorcolumn
    autocmd  User PostPulse set nocursorcolumn
augroup END

This functionality requires Vim 7.3.438 or newer.

Integration with the incsearch.vim plugin

incsearch.vim provides a very nice improved incremental searching. With a little configuration, it can work with the vim search pulse:

" incsearch and vim search pulse
let g:vim_search_pulse_disable_auto_mappings = 1
let g:incsearch#auto_nohlsearch = 1
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)

" Next or previous match is followed by a Pulse
map n <Plug>(incsearch-nohl-n)<Plug>Pulse
map N <Plug>(incsearch-nohl-N)<Plug>Pulse
map * <Plug>(incsearch-nohl-*)<Plug>Pulse
map # <Plug>(incsearch-nohl-#)<Plug>Pulse
map g* <Plug>(incsearch-nohl-g*)<Plug>Pulse
map g# <Plug>(incsearch-nohl-g#)<Plug>Pulse

" Pulses the first match after hitting the enter keyan
autocmd! User IncSearchExecute
autocmd User IncSearchExecute :call search_pulse#Pulse()

Integration with the vim-asterisk plugin

vim-asterisk provides improved star motions. Here's the configuration:

let g:vim_search_pulse_disable_auto_mappings = 1

nmap * <Plug>(asterisk-*)<Plug>Pulse
nmap # <Plug>(asterisk-#)<Plug>Pulse
nmap n n<Plug>Pulse
nmap N N<Plug>Pulse
" Pulses cursor line on first match
" when doing search with / or ?
cmap <silent> <expr> <enter> search_pulse#PulseFirst()

Known bugs

MacVim

Credits

This plugin is inspired by:

The animated gif was created using http://www.cockos.com/licecap/

Thanks to everyone who participated in making this plugin better.

vim-search-pulse's People

Contributors

djjcast avatar inside avatar jebaum avatar justinmk avatar livelazily avatar yongrenjie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vim-search-pulse's Issues

Error occurred when searching for backslash

Hello, thanks great plugin :) !

reproduce

backslash.txt

\

minimal.vimrc

" /path/to/pack_minimal/pack/m/start/vim-search-pulse
set packpath=/path/to/pack_minimal

let g:vim_search_pulse_mode = 'pattern'
let g:vim_search_pulse_disable_auto_mappings = 1

packadd vim-search-pulse
nmap n n<Plug>Pulse
  1. gvim.exe -Nu minimal.vimrc backslash.txt
  2. /\<CR>

Actual behavior

Error occurred.

Expected behavior

No errors.

other

An error also occurred in the following operations.

  1. /\v\\<CR> (no error)
  2. /\zs\v\\<CR> (error occurred)

Plugin breaks :cabbrev expansion

I have a few :cabbrev mappings that I use frequently, like :qq as a shortcut for :q!.

With this plugin installed, abbreviations are no longer triggered with Enter, although Space will still activate them. It looks like the plugin rebinds <CR> in command mode to a function that does some work then returns a string <CR>, which is presumably interpreted as a keystroke, although I do not know why. However, the "keystroke" is not triggering abbreviations.

Pulse doesn't work in 'vim-asterisk' / 'incsearch.vim' plugins

It would be great to have support with the plugins below, as for now the /search gets remapped and doesn't work.
For example, you get the error even though I set no mapping :

function incsearch#forward..<SNR>110_search..<SNR>110_get_input..154..152..165..138..188..<SNR>120_call..258..252..<SNR>144__auto_cmap..<SNR>
145_rhs_key_list, line 5 Vim(return):E118: Too many arguments for function: maparg

https://github.com/haya14busa/incsearch.vim/
https://github.com/haya14busa/vim-asterisk
https://github.com/osyo-manga/vim-anzu
https://github.com/junegunn/vim-oblique

doautocmd when done pulsing

I found that I liked having cursorcolumn set while the actual pulse is happening to really direct my eyes to the exact location of the match, and then having cursorcolumn be automatically unset after the pulse is over. To achieve this I added the line

doautocmd <nomodeline> User PostPulse

to the end of the search_pulse#Pulse() function, and adjusted my maps and added an autocmd to handle it. This seems potentially useful for other things as well, would you be interested in a PR for it?

Bugs with doautocmd

Found a couple bugs this morning with the doautocmd that I'll fix tonight when I get home, this is to remind me to do that / document it.

  1. In older versions of vim, either doautocmd itself or the <nomodeline> option for it aren't present. make sure they are so that the plugin doesn't break in those conditions. (vim 7.3, for example, doesn't have these, and throws an error on every search).

  2. If the user chooses not to do anything with the autocmds, the message No matching autocommands will get echoed to the commandline, this should be silenced.

why open folds by default?

plugin has this line:

" Open folds
normal zv

Many users don't want this behavior, why not leave it up to them (they can easily modify their mappings to be nmap nzv<Plug>Pulse)? The plugin is meant to change the appearance of a rearch result, it's disappointing that it also modifies behavior.

Reset s:oldc after colorscheme changed

Currently, changing colorschemes after vim has been loaded leaves vim-pulse with an old value for the default "CursorLine" color (which is captured when vim-pulse is initialized, here). It would be great if this could be updated when colorscheme is changed, by using the ColorScheme autocommand event.

Add custome "<Plug>Pulse" maps

1st of all, I'm a beginner with VIM, so the following ads are focused on VIM users of my skill-level, and might be obvious to experts, and therefore unnecessary rubbish to add to the docu, that's ok.

After reading the plug-in-docu, specially this paragraph

Otherwise the plugin will do the following for you:

nmap n n<Plug>Pulse
nmap N N<Plug>Pulse
nmap * *<Plug>Pulse
[...]

I realized I could remap all jumps, adding <Plug>Pulse to them. May I request to show any of this examples, in a new mini-section of your nice docu? please. Something like:
And take advantage of<Plug>Pulse, use it anywhere your imagination leads you to! E.g.

" Pulse after jump with Ctrl-I or Ctrl-O 
nmap <C-O> <C-O><Plug>Pulse
nmap <C-I> <C-I><Plug>Pulse
" pulse current line
nmap <leader>p' <Plug>Pulse
" change line
nmap gg gg<Plug>Pulse
nmap G G<Plug>Pulse
" matching brackets
nmap % %<Plug>Pulse
" Pulse after any jump motion. There is NO autocmd for jumping 'a to 'z, thus I must remap all:
nmap `a `a<Plug>Pulse
nmap `b `b<Plug>Pulse

And I'd love to hear from more ideas where to use it.

Also, in long term, it would be nice if the plug-in had an option to auto-remap any jump (if some plugin-boolean set), not only the search-jumps already implemented. Remaps 'a till 'Z, `a till `Z are like 26x2x2, also 10x2 for digits marks. A lot! Or even more: VIM-mark-help.

PD: Anyone willing to comment, careful: GitHub has no raw text block, it overrides backtick (`), but not apostrophe ('). Check solution here.

Missing argument `ctermbg` error

Hi there, I get the following error when using a minimal setup:

Error detected while processing function search_pulse#Pulse[13]..search_pulse#P
ulseCursorLine[44]..<SNR>71_SetCursorLineColor:                                
line    1:                                                                     
E417: missing argument: ctermbg=  

I can reproduce this with the following .vimrc (uses vim-plug, but that should not matter):

call plug#begin()
Plug 'inside/vim-search-pulse'
call plug#end()

Here is my system info (I run vim in the terminal):

NVIM 0.1.6
Build type: None
Compilation: /usr/bin/cc -g -O2 -fdebug-prefix-map=/build/neovim-iX7_MI/neovim-0.1.6=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DDISABLE_LOG -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1  -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -D_GNU_SOURCE -I/build/neovim-iX7_MI/neovim-0.1.6/build/config -I/build/neovim-iX7_MI/neovim-0.1.6/src -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/build/neovim-iX7_MI/neovim-0.1.6/build/src/nvim/auto -I/build/neovim-iX7_MI/neovim-0.1.6/build/include
Compiled by [email protected]

Optional features included (+) or not (-): +acl   +iconv    +jemalloc +tui
For differences from Vim, see :help vim-differences

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

The plugin works fine in my normal setup, but breaks once I tried to move to a different colorscheme (I use hybrid normally)

Thanks for the great plugin!

Does not work together with `incsearch` and `anzu`

I'm trying to make these 3 plugins to work together on n/N. I've added to my vimrc:

NeoBundle 'inside/vim-search-pulse'
let g:vim_search_pulse_disable_auto_mappings = 1

NeoBundle 'haya14busa/incsearch.vim'
let g:incsearch#auto_nohlsearch = 1

NeoBundle 'osyo-manga/vim-anzu' 
let g:anzu_enable_CursorMoved_AnzuUpdateSearchStatus = 0

nmap n <Plug>(incsearch-nohl-n)<Plug>Pulse<Plug>(anzu-update-search-status)
nmap N <Plug>(incsearch-nohl-N)<Plug>Pulse<Plug>(anzu-update-search-status)

In this case both vim-search-pulse and anzu are not triggered when I press n/N. If I remove one of them from the mapping, the other one works OK.

search_pulse#PulseFirst doesn't work correctly in operator-pending mode

Hello,

First of all thanks for your work on this plugin. It's been incredibly useful so far.

There's one tiny hitch. When using / and ? as motions in operator-pending mode (e.g. c/<text>), extra text gets inserted. I have a small video showing this on a fresh installation of vim with no other plugins:

GIF of behaviour

This can be traced to the cmap command:

cmap <silent> <expr> <enter> search_pulse#PulseFirst()

I don't know how to get this mapping to differentiate between command-line mode (e.g. /<text>) and operator-pending mode (e.g. c/<text>), but I figured out one way to fix this further downstream by modifying line 65 of

" Will pulse the cursor line on first search match using / or ?
func! search_pulse#PulseFirst()
let t = getcmdtype()
if t == '/' || t == '?'
return "\<cr>:call search_pulse#Pulse()\<cr>"
endif
return "\<cr>"
endf

to

if state() != 'o' && (t == '/' || t == '?')

I think the state() function was only added in vim 8.1.2047, though. And there's probably a better way to handle this which I don't know. :-)

Explicitly enable pulse-on-same-line

Hello! This is a very cool plugin; I like it a lot!

Reading through the code, I see you explicitly don't pulse when the next match is on the same line as the last match. I would prefer that the cursorline pulse regardless of where the next match is. Could you provide an option to do that? Or, would you be open to a pull request that implements it?

Also, there is a slight glitch with the current behavior. Currently, if I press /foo<cr> to start a search, then <C-F>n to scroll up a page and jump to the next "foo", then the found foo (the one I jumped away from) is not highlighted, because it's the same line as the previous pulse. More generally, I think that moving away from a match's line, then returning to it, should pulse the cursorline.

'c' + '?pattern' or 'c' + '/pattern'

Expected behaviour

With vim --clean (no loading any plugin or ~/.vimrc)
In next example line
testing line word1 word2
If I go to last char ($), press c? and in command line type word1 (and press CR) I end in insert mode before char 2 of:
testing line 2

With vim-search-pulse plugin

Instead I get (still ending in insert mode before char 2):

testing line :call search_pulse#Pulse()
2

Same problem with: 'c' + '/pattern'.

All fine with 'd' + '?pattern' or 'd' + '/pattern'

'c' + '?pattern' motion explained

As well as:

'c' + '/pattern'
'd' + '?pattern'
'd' + '/pattern'

See https://www.youtube.com/watch?v=ekjzz_LBbR0 or reddit post

plugin install + settings

Plug 'inside/vim-search-pulse'
let g:vim_search_pulse_duration = 250
let g:vim_search_pulse_color_list = [25, 26, 27, 27, 27]
augroup Pulse
        autocmd! User PrePulse
        autocmd! User PostPulse
        autocmd  User PrePulse  execute "normal zv"
augroup END

desktop

Ubuntu 20.04
Vim8.2

Thanks in advance!

Errors on macvim when using cursor_line mode

Error detected while processing function search_pulse#Pulse..search_pulse#PulseCursorLine..search_pulse#IsLineTooLong:
line 4:
E806: using Float as a String
E116: Invalid arguments for function ceil((cc * 1.0) / (ww * 1.0))
E15: Invalid expression: ceil((cc * 1.0) / (ww * 1.0))
line 6:
E121: Undefined variable: lc
E15: Invalid expression: lc >= 3.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.