https://github.com/wellle/line-targets.vim
A simple (example) plugin for targets.vim
https://github.com/wellle/line-targets.vim
Last synced: 2 months ago
JSON representation
A simple (example) plugin for targets.vim
- Host: GitHub
- URL: https://github.com/wellle/line-targets.vim
- Owner: wellle
- Created: 2018-11-01T23:11:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-02T13:56:33.000Z (over 6 years ago)
- Last Synced: 2025-01-04T21:31:14.748Z (4 months ago)
- Language: Vim script
- Size: 6.84 KB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This is a simple example plugin which extends the [targets.vim][targets.vim]
plugin by adding a new source with a default mapping.Effectively this adds line text objects. Type `da-` to delete a line (including
leading and trailing whitespace) or `ci-` to change the inner line (excluding
leading and trailing whitespace). As for all other text objects provided by
targets.vim, you can use `n` and `l` to operate on distant lines below and
above the current line respectively. For example `d2an-` deletes the line two
lines below the cursor.You can customize this behavior by putting something like this in your vimrc:
```vim
autocmd User targets#mappings#user call targets#mappings#extend({
\ '-': {'separator': [{'d': '-'}]},
\ 'x': {'line': [{'c': 1}]},
\ })
```The `'-'` line restores the default mapping for `'-'` as a separator text
object. The `'x'` line maps `'x'` to the line source. So now you can delete the
next line with `danx` and still delete between - with `di-`.If you want to map `'l'`, you'll need to free it from the default meaning of
last target, as in `dilb` (delete in last block), for example by using `N` for
that instead:```vim
let g:targets_nl = 'nN'
```Now you can delete in last block with `diNb` and use this settings to make
`ciNl` change the last/previous line:```vim
autocmd User targets#mappings#user call targets#mappings#extend({
\ '-': {'separator': [{'d': '-'}]},
\ 'l': {'line': [{'c': 1}]},
\ })
```To see how such an extension for targets.vim can be implemented, please have a
look at the code and comments within the code in this repository.[targets.vim]: https://github.com/wellle/targets.vim