Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wincent/loupe
🔍 Enhanced in-file search for Vim
https://github.com/wincent/loupe
vim
Last synced: 10 days ago
JSON representation
🔍 Enhanced in-file search for Vim
- Host: GitHub
- URL: https://github.com/wincent/loupe
- Owner: wincent
- License: bsd-2-clause
- Created: 2015-07-05T22:14:34.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2023-10-24T22:25:05.000Z (about 1 year ago)
- Last Synced: 2024-10-12T06:09:55.670Z (25 days ago)
- Topics: vim
- Language: Vim Script
- Homepage:
- Size: 132 KB
- Stars: 144
- Watchers: 7
- Forks: 6
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
> "loupe (noun)
a small magnifying glass used by jewelers and watchmakers."Loupe enhances Vim's `search-commands` in four ways:
### 1. Makes the currently selected match easier to see
When searching using `/`, `?`, `star`, `#`, `n`, `N` or similar, it can be hard to see the "current" match from among all the matches that 'hlsearch' highlights. Loupe makes the currently selected match easier to see by:
- Applying a different `:highlight` group (by default, `hl-IncSearch`) to the match under the cursor.
- Keeping the matching line centered within the window when jumping between matches with `n` and `N`.### 2. Applies sane pattern syntax by default
Loupe makes "very magic" (`/\v`) syntax apply by default when searching. This is true even if you initiate a search via a novel means, such as from a visual selection or with a complicated `:range` prefix.
This means that you can use a pattern syntax closer to the familiar regular expression syntax from languages such as Perl, Ruby, JavaScript (indeed, most other modern languages that support regular expressions).
### 3. Provides a shortcut to remove search highlighting
Loupe maps <leader>n to quickly remove all 'hlsearch' highlighting (although you can provide an alternative mapping of your choosing or suppress the feature entirely).
### 4. Sensible defaults for search-related features
Loupe provides reasonable defaults for most search-related Vim settings to provide a good "out of the box" experience. For more details, or to see how to override Loupe's settings, see [`loupe-overrides`](#user-content-loupe-overrides).
To install Loupe, use your plug-in management system of choice.
If you don't have a "plug-in management system of choice", I recommend Pathogen (https://github.com/tpope/vim-pathogen) due to its simplicity and robustness. Assuming that you have Pathogen installed and configured, and that you want to install Loupe into `~/.vim/bundle`, you can do so with:
```
git clone https://github.com/wincent/loupe.git ~/.vim/bundle/loupe
```Alternatively, if you use a Git submodule for each Vim plug-in, you could do the following after `cd`-ing into the top-level of your Git superproject:
```
git submodule add https://github.com/wincent/loupe.git ~/vim/bundle/loupe
git submodule init
```To generate help tags under Pathogen, you can do so from inside Vim with:
```
:call pathogen#helptags()
```Loupe maps <leader>n to [`(LoupeClearHighlight)`](#user-content-plugloupeclearhighlight), which clears all visible highlights (like `:nohighlight` does). To use an alternative mapping instead, create a different one in your `.vimrc` instead using `:nmap`:
```
" Instead of n, use x.
nmap x (LoupeClearHighlight)
```Note that Loupe will not try to set up its <leader>n mapping if any of the following are true:
- A mapping for <leader>n already exists.
- An alternative mapping for [`(LoupeClearHighlight)`](#user-content-plugloupeclearhighlight) has already been set up from a `.vimrc`.
- The mapping has been suppressed by setting [`g:LoupeClearHighlightMap`](#user-content-gloupeclearhighlightmap) to 1 in your `.vimrc`.Loupe maps `#` to [`(LoupeOctothorpe)`](#user-content-plugloupeoctothorpe) in order to implement custom highlighting and line-centering for the current match.
To prevent this from happening, create an alternate mapping in your `.vimrc`:
```
nmap (LoupeOctothorpe)
```Loupe maps `star` to [`(LoupeStar)`](#user-content-plugloupestar) in order to implement custom highlighting and line-centering for the current match.
To prevent this from happening, create an alternate mapping in your `.vimrc`:
```
nmap (LoupeStar)
```Loupe maps `N` to [`(LoupeN)`](#user-content-plugloupen) in order to implement custom highlighting and line-centering for the current match.
To prevent this from happening, create an alternate mapping in your `.vimrc`:
```
nmap (LoupeN)
```Loupe maps `g#` to [`(LoupeGOctothorpe)`](#user-content-plugloupegoctothorpe) in order to implement custom highlighting and line-centering for the current match.
To prevent this from happening, create an alternate mapping in your `.vimrc`:
```
nmap (LoupeGOctothorpe)
```Loupe maps `gstar` to [`(LoupeGStar)`](#user-content-plugloupegstar) in order to implement custom highlighting and line-centering for the current match.
To prevent this from happening, create an alternate mapping in your `.vimrc`:
```
nmap (LoupeGStar)
```Loupe maps `n` to [`(Loupen)`](#user-content-plugloupen) in order to implement custom highlighting and line-centering for the current match.
To prevent this from happening, create an alternate mapping in your `.vimrc`:
```
nmap (Loupen)
```### `g:LoupeHighlightGroup` (string, default: IncSearch)
Specifies the `:highlight` group used to emphasize the match currently under the cursor for the current search pattern. Defaults to "IncSearch" (ie. `hl-IncSearch`). For example:
```
let g:LoupeHighlightGroup='Error'
```To prevent any special highlighting from being applied, set this option to "" (ie. the empty string).
### `g:LoupeLoaded` (any, default: none)
To prevent Loupe from being loaded, set [`g:LoupeLoaded`](#user-content-gloupeloaded) to any value in your `.vimrc`. For example:
```
let g:LoupeLoaded=1
```### `g:LoupeClearHighlightMap` (boolean, default: 1)
Controls whether to set up the [`(LoupeClearHighlight)`](#user-content-plugloupeclearhighlight) mapping. To prevent any mapping from being configured, set to 0:
```
let g:LoupeClearHighlightMap=0
```### `g:LoupeVeryMagic` (boolean, default: 1)
Controls whether "very magic" pattern syntax (`/\v`) is applied by default. To disable, set to 0:
```
let g:LoupeVeryMagic=0
```### `g:LoupeCenterResults` (boolean, default: 1)
Controls whether the match's line is vertically centered within the window when jumping (via `n`, `N` etc). To disable, set to 0:
```
let g:LoupeCenterResults=0
```### `g:LoupeCaseSettingsAlways` (boolean, default: 1)
Normally Vim will respect your `'smartcase'` and `'ignorecase'` settings when searching with `/`, or `?`, but it ignores them when using `star`, `#`, `gstar` or `g#`.
This setting forces Vim to respect your `'smartcase'` and `'ignorecase'` settings in all cases. To disable, set to 0:
```
let g:LoupeCaseSettingsAlways=0
```Apply highlighting to the current search match.
Loupe sets a number of search-related Vim settings to reasonable defaults in order to provide a good "out of the box" experience. The following overrides will be set unless suppressed or overridden (see [`loupe-suppress-overrides`](#user-content-loupe-suppress-overrides)):
`'history'`
Increased to 1000, to increase the number of previous searches remembered. Note that Loupe only applies this setting if the current value of 'history' is less than 1000.
`'hlsearch'`
Turned on (when there is a previous search pattern, highlight all its matches).
`'incsearch'`
Turned on (while typing a search command, show where the pattern matches, as it was typed so far).
`'ignorecase'`
Turned on (to ignore case in search patterns).
`'shortmess'`
Adds "s", which suppresses the display of "search hit BOTTOM, continuing at TOP" and "search hit TOP, continuing at BOTTOM" messages.
`'smartcase'`
Turned on (overrides `'ignorecase'`, making the search pattern case-sensitive whenever it containers uppercase characters).
### Preventing Loupe overrides from taking effect
To override any of these choices, you can place overrides in an `after-directory` (ie. `~/.vim/after/plugin/loupe.vim`). For example:
```
" Override Loupe's 'history' setting from 1000 to 10000.
set history=10000" Reset Loupe's 'incsearch' back to Vim default.
set incsearch&vim" Remove unwanted 's' from 'shortmess'.
set shortmess-=s
```Just as Loupe aims to improve the within-file search experience, Ferret does the same for multi-file searching and replacing:
- https://github.com/wincent/ferret
Source code:
- https://github.com/wincent/loupe
Official releases are listed at:
- http://www.vim.org/scripts/script.php?script_id=5215
Copyright 2015-present Greg Hurrell. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Patches can be sent via mail to [email protected], or as GitHub pull requests at: https://github.com/wincent/loupe/pulls
At the moment the release process is manual:
- Perform final sanity checks and manual testing
- Update the [`loupe-history`](#user-content-loupe-history) section of the documentation
- Verify clean work tree:```
git status
```- Tag the release:
```
git tag -s -m "$VERSION release" $VERSION
```- Publish the code:
```
git push origin main --follow-tags
git push github main --follow-tags
```- Produce the release archive:
```
git archive -o loupe-$VERSION.zip HEAD -- .
```- Upload to http://www.vim.org/scripts/script.php?script_id=5215
Loupe is written and maintained by Greg Hurrell <[email protected]>.
The original idea for the [`g:LoupeHighlightGroup`](#user-content-gloupehighlightgroup) feature was taken from Damian Conway's Vim set-up:
- https://github.com/thoughtstream/Damian-Conway-s-Vim-Setup/blob/master/plugin/hlnext.vim
Which he discussed in his "More Instantly Better Vim" presentation at OSCON 2013:
- https://www.youtube.com/watch?v=aHm36-na4-4
- Add [`g:LoupeCaseSettingsAlways`](#user-content-gloupecasesettingsalways) to make Vim respect `'ignorecase'` and `'smartcase'` settings while using `star`, `gstar`, `#` and `g#`.
- Ensure that [`g:LoupeVeryMagic`](#user-content-gloupeverymagic) takes effect with longer-forms of the `:global`, `:substitute` and `:vglobal` commands.
- Treat `:g!` as equivalent to `:v` (https://github.com/wincent/loupe/issues/20).- Fix error-handling to work regardless of `'iskeyword'` setting (https://github.com/wincent/loupe/pull/14).
- Match default Vim behavior of opening folds when jumping to a match.
- Suppress unwanted cursor movement after [`(LoupeClearHighlight)`](#user-content-plugloupeclearhighlight) and when using `:nohighlight`.
- Expose [`loupe#hlmatch()`](#user-content-loupehlmatch) (previously was a private function) for users who wish to do low-level intergration with other plug-ins.
- Provide `` mappings for `star`, `#`, `n`, `N`, `gstar`, `g#` (see [`(LoupeStar)`](#user-content-plugloupestar), [`(LoupeOctothorpe)`](#user-content-plugloupeoctothorpe), [`(Loupen)`](#user-content-plugloupen), [`(LoupeN)`](#user-content-plugloupen), [`(LoupeGStar)`](#user-content-plugloupegstar), [`(LoupeGOctothorpe)`](#user-content-plugloupegoctothorpe)).- Make compatible with older versions of Vim that do not have `v:hlsearch`.
- Add support for special delimiters with `:substitute` command.- Renamed the `LoupeClearHighlight` mapping to [`(LoupeClearHighlight)`](#user-content-plugloupeclearhighlight).
- Initial release, extracted from my dotfiles (https://github.com/wincent/wincent).