├── .gitignore ├── LICENSE.txt ├── README.md ├── doc └── searchant.txt └── plugin └── searchant.vim /.gitignore: -------------------------------------------------------------------------------- 1 | /doc/tags 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Tim Schumacher 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SEARCHANT.VIM IS OBSOLETED BY VIM-SEARCHHI 2 | 3 | You should use [vim-searchhi](https://github.com/qxxxb/vim-searchhi) instead of searchant.vim. It fixes a bunch of longstanding bugs of searchant.vim and is overall more polished. 4 | 5 | # searchant.vim 6 | 7 | Vim plugin for improved search highlighting 8 | 9 | ## Overview 10 | 11 | When it comes to searching Vim is one of the editors which lacks the feature 12 | of highlighting the current search result. Searchant wraps the hacky way to 13 | achieve this in Vim into a plugin with a clean interface. Additionally it 14 | provides a key mapping to stop the search highlighting. 15 | 16 | View the documentation in Vim with `:help searchant` or [on the web](https://raw.githubusercontent.com/timakro/vim-searchant/master/doc/searchant.txt). 17 | 18 | ![vim-searchant demo](https://files.timakro.de/vim-searchant.png) 19 | 20 | ## Requirements 21 | 22 | * Vim 7.0+ 23 | 24 | ## Installation 25 | 26 | It is recommended to install this plugin using a plugin manager like 27 | [pathogen.vim](http://github.com/tpope/vim-pathogen), 28 | [Vundle.vim](https://github.com/VundleVim/Vundle.vim) or 29 | [vim-plug](https://github.com/junegunn/vim-plug). 30 | 31 | Alternatively you can just drop the `plugin` and `doc` folders into your 32 | `~/.vim` directory. Don't forget to run `:helptags ~/.vim/doc` to generate the 33 | help tags after a manual installation. 34 | 35 | If you are using [incsearch.vim](https://github.com/haya14busa/incsearch.vim) 36 | and you'd like `vim-searchant` to play-nicely, you can add the following snippet 37 | to hide the searchant highlight: 38 | 39 | ```vim 40 | " Disable Searchant highlight when incsearch.vim highlights also disable 41 | autocmd CursorMoved * call SearchantStop() 42 | function SearchantStop() 43 | :execute "normal \SearchantStop" 44 | endfunction 45 | ``` 46 | 47 | This assumes that you have `let g:incsearch#auto_nohlsearch = 1` in your config. 48 | -------------------------------------------------------------------------------- /doc/searchant.txt: -------------------------------------------------------------------------------- 1 | *searchant.txt* Vim plugin for improved search highlighting 2 | 3 | Author: Tim Schumacher 4 | License: MIT 5 | Version: 1.1.0 6 | 7 | ============================================================================== 8 | CONTENTS *searchant-contents* 9 | 10 | 1. Features ..................................... |searchant-features| 11 | 1.1 Highlight current result ................ |searchant-hl-current| 12 | 1.2 Stop highlighting ....................... |searchant-hl-stop| 13 | 1.3 Toggle highlighting ..................... |searchant-hl-toggle| 14 | 1.4 Standard highlighting ................... |searchant-hl-standard| 15 | 2. License ...................................... |searchant-license| 16 | 3. Bugs ......................................... |searchant-bugs| 17 | 4. Contributing ................................. |searchant-contributing| 18 | 5. Changelog .................................... |searchant-changelog| 19 | 20 | ============================================================================== 21 | 1. Features *searchant-features* 22 | 23 | When it comes to searching vim is one of the editors which lacks the feature 24 | of highlighting the current search result. Searchant wraps the hacky way to 25 | achieve this in vim into a plugin with a clean interface. Additionally it 26 | provides a key mapping to stop the search highlighting. 27 | 28 | ------------------------------------------------------------------------------ 29 | 1.1 Highlight current result *searchant-hl-current* 30 | 31 | Searchant highlights the last search result jumped to using a new highlighting 32 | group called `SearchCurrent`. By default the background color is set to red, 33 | to set it for example to cyan use: 34 | 35 | highlight SearchCurrent ctermbg=cyan 36 | 37 | ------------------------------------------------------------------------------ 38 | 1.2 Stop highlighting *searchant-hl-stop* 39 | 40 | Additionally a new key mapping is added to stop the normal search highlighting 41 | as well as the new one added by this plugin. By default is used 42 | because it already cancels the current search in command-line mode which makes 43 | it fit nicely. Nevertheless you can use another key, for example t: 44 | 45 | let g:searchant_map_stop = 0 46 | nmap t SearchantStop 47 | 48 | ------------------------------------------------------------------------------ 49 | 1.3 Toggle highlighting *searchant-hl-toggle* 50 | 51 | You can map a key to toggle search highlighting of the current result on and 52 | off. This works similar to the stop binding and does not turn off highlighting 53 | permantently, the next search will be highlighted again. This will turn on 54 | highlighting again after the stop binding was used. There is no default 55 | mapping, this is how you would map it to t: 56 | 57 | nmap t SearchantToggle 58 | 59 | ------------------------------------------------------------------------------ 60 | 1.4 Standard highlighting *searchant-hl-standard* 61 | 62 | Searchant enables the standard search highlighting by default, if you only 63 | want to see the highlighting of the current result turn the standard 64 | highlighting off like this: 65 | 66 | let g:searchant_all = 0 67 | 68 | You can still change the way the standard highlighting looks like normal, for 69 | example to change the background color to blue use: 70 | 71 | highlight Search ctermbg=blue 72 | 73 | ============================================================================== 74 | 2. License *searchant-license* 75 | 76 | MIT 77 | 78 | ============================================================================== 79 | 3. Bugs *searchant-bugs* 80 | 81 | Please report bugs on the GitHub issue tracker: 82 | http://github.com/timakro/vim-searchant/issues 83 | 84 | ============================================================================== 85 | 4. Contributing *searchant-contributing* 86 | 87 | If you want to contribute feel free to fork the Searchant repository on GitHub 88 | and send a pull request: 89 | http://github.com/timakro/vim-searchant 90 | 91 | ============================================================================== 92 | 5. Changelog *searchant-changelog* 93 | 94 | v1.1.0 95 | * Removed g:searchant_current setting 96 | * Added toggle functionality (thanks to andykais) 97 | v1.0.7 98 | * Better compatibility with other enhanced search plugins 99 | (namely vim-anzu and vim-asterisk, thanks to qxxxb) 100 | v1.0.6 101 | * Fixed folds not opening automatically 102 | v1.0.5 103 | * Keep user-defined search mappings 104 | v1.0.4 105 | * Fixed handling of multiple windows 106 | * Fixed highlighting staying when searching for non existing pattern 107 | v1.0.3 108 | * Added support for the ignorecase option 109 | * Fixed highlighting for patterns using branches 110 | * Fixed highlighting for non-GUI (broke with GUI fix) 111 | v1.0.2 112 | * Fixed current result highlighting for GUI 113 | v1.0.1 114 | * Added requirements to readme 115 | v1.0.0 116 | * Initial stable release 117 | -------------------------------------------------------------------------------- /plugin/searchant.vim: -------------------------------------------------------------------------------- 1 | " searchant.vim - Vim plugin for improved search highlighting 2 | " Author: Tim Schumacher 3 | " License: MIT 4 | " Version: 1.1.0 5 | 6 | if exists("g:loaded_searchant") 7 | finish 8 | endif 9 | let g:loaded_searchant = 1 10 | 11 | " Default variables 12 | let g:searchant_all = get(g:, 'searchant_all', 1) 13 | let g:searchant_map_stop = get(g:, 'searchant_map_stop', 1) 14 | 15 | " Default highlight current style 16 | if !hlexists("SearchCurrent") 17 | highlight SearchCurrent ctermbg=red ctermfg=0 guibg=#ff0000 guifg=#000000 18 | endif 19 | 20 | function s:SID() 21 | return matchstr(expand(''), '\m\zs\d\+\ze_SID$') 22 | endfun 23 | 24 | function s:Start() 25 | if g:searchant_all 26 | set hlsearch 27 | endif 28 | let pattern = '\m\%'.line('.').'l\%'.col('.').'c' 29 | \ . '\%('.(!&magic?'\M':'').@/.'\m\)' 30 | if &ignorecase 31 | let pattern .= '\c' 32 | endif 33 | let w:current_match_id = matchadd("SearchCurrent", pattern, 2) 34 | " Open fold 35 | try 36 | normal! zo 37 | catch /^Vim\%((\a\+)\)\=:E490/ 38 | endtry 39 | endfunction 40 | 41 | function s:Stop() 42 | if exists("w:current_match_id") 43 | set nohlsearch 44 | call matchdelete(w:current_match_id) 45 | unlet w:current_match_id 46 | endif 47 | endfunction 48 | 49 | function s:Update() 50 | call s:Stop() 51 | call s:Start() 52 | endfunction 53 | 54 | function s:Toggle() 55 | if exists("w:current_match_id") 56 | call s:Stop() 57 | else 58 | call s:Start() 59 | endif 60 | endfunction 61 | 62 | " Update highlighting after search commands 63 | function s:OnCommand() 64 | if getcmdtype() == "/" || getcmdtype() == "?" 65 | call s:Stop() 66 | return "\:call ".s:SID()."_Start()\" 67 | else 68 | return "\" 69 | endif 70 | endfunction 71 | cnoremap OnCommand() 72 | 73 | " Update highlighting after search mappings 74 | function s:MapUpdate(name) 75 | let recall = maparg(a:name, "n") 76 | if !len(recall) 77 | let recall = a:name 78 | endif 79 | execute "nmap ".a:name." ".recall.":call Update()" 80 | endfunction 81 | call s:MapUpdate("*") 82 | call s:MapUpdate("#") 83 | call s:MapUpdate("g*") 84 | call s:MapUpdate("g#") 85 | call s:MapUpdate("n") 86 | call s:MapUpdate("N") 87 | 88 | " Define mapping to stop/toggle highlighting 89 | nnoremap SearchantStop :call Stop() 90 | nnoremap SearchantToggle :call Toggle() 91 | 92 | if g:searchant_map_stop 93 | nmap SearchantStop 94 | endif 95 | --------------------------------------------------------------------------------