An open API service indexing awesome lists of open source software.

https://github.com/trapd00r/yankmatches.vim

A Vim plugin that allows for yanking or deleting the results of a previously performed search action
https://github.com/trapd00r/yankmatches.vim

vim vim-plugin

Last synced: about 1 year ago
JSON representation

A Vim plugin that allows for yanking or deleting the results of a previously performed search action

Awesome Lists containing this project

README

          

## yankmatches.vim

This plugin was originally made by Damian Conway.

It allows you to perform various magic operations on the result of a previous
`/search` (or any other search operation, like `*`).

I have added a few things:

* A `YankMatches` highlight group that you can use to visualize what lines you've
just yanked
* Added ability to configure what register to use for yanking/deleting `YankMatches#ClipboardRegister`; thank you [joshukraine](https://github.com/joshukraine/yankmatches/blob/e88fa4e21ac12059f3a6c51709baebb3dbec454d/plugin/yankmatches.vim#L83)
* Tweaked so that `hlsearch` can still be active

Examples:

Extract all lines matching a `/cats` search operation for pasting somewhere else for further investigation:

```vim
/cats
ym
Gp
```

Now you will find all cats copied to the bottom of the buffer.

Open a `vim` file, like your `.vimrc`:

```vim
/^\s*".*$
DM
```

Now you will find that everything but the comments in your file is deleted.

If you wanted to delete only the comments, the operation would be:

```vim
/^\s*".*$
dm
```

### Installation

Throw the plugin into your `$VIMRUNTIME/plugin` directory, i.e `~/.vim/plugin/`.

### Configuration

#### Mappings

##### Normal mode mappings

```vim
dm " delete all matches
DM " delete everything that does NOT match
ym " yank all matches
YM " yank everything that does NOT match
```

##### Visual mode mappings

```vim
dm " delete matches, but limited to matches inside a visual selection
DM " delete everything that does NOT match, but limited to (not) matches
" inside a visual selection
ym " yank matches, but limited to matches inside a visual selection
YM " yank everything that does NOT match, but limited to (not) matches
" inside a visual selection

```
##### Yanking register
By default, the value of `&clipboard` is used for the yanking/deleting
operations. This can however be overridden:

```vim
let g:YankMatches#ClipboardRegister = '*'

```

##### Additional mappings

Though not provided by default, you are suggested to modify your current
`:nohlsearch` mapping to account for the `YankMatches` as well.

The author uses this mapping:

```vim
" remove hlsearch, hlnext, matches, highlighted yanks, highlighted lines and redraw screen
nnoremap :call HLNextOff() :nohlsearch :hi clear YankedMatches :call HighlightCurrentLine('clear')

```

#### Colors

These are the default colors defined for the `YankMatches` highlight group, but
you are free to override as you see fit.

```vim
highlight YankedMatches
\ ctermfg=bg ctermbg=214 cterm=bolditalic
\ guifg=bg guibg=#ffaf00 gui=none
```

### Screenshot

![screenshot](./extra/screenshot.png?raw=true)

What you see in the screenshot above:

* A search has been performed, `/line_\S\+`
* `ym` has been executed
* The statusline displays the number of lines yanked, in this case 10