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

https://github.com/hgiesel/vim-motion-sickness

Vim motions to the max
https://github.com/hgiesel/vim-motion-sickness

vim vim-motions

Last synced: about 1 year ago
JSON representation

Vim motions to the max

Awesome Lists containing this project

README

          

# motion-sickness.nvim ![Build Status](https://travis-ci.org/hgiesel/vim-motion-sickness.svg?branch=master) ![Build Status](https://travis-ci.org/hgiesel/vim-motion-sickness.svg?branch=devel)

This plugin adds a slew of new possible text objects. [Vader](https://github.com/junegunn/vader.vim)
ensures they all work as intended. Only Neovim is supported at the moment.

Each type of text object can be disabled with `let g:sickness#{type}_enabled = 0`, e.g.:

```vim
let g:sickness#symbol#enabled = 0
let g:sickness#view#enabled = 0
```

If you only want the `` metakeys and want to define the mappings yourself, set
`let g:sickness#{type}#use_default_maps = 0`, e.g.:

```vim
let g:sickness#symbol#use_default_maps = 0
let g:sickness#view#use_default_maps = 0
```

#### List of text objects

* **bracket text objects**:
* [alias text objects](#alias-text-objects)
* [expression text objects](#expression-text-objects)
* [field text objects](#field-text-objects)

* **other text objects**:
* [indentation text objects](#indent-text-objects)
* [line text objects](#line-text-objects)
* [view text objects](#view-text-objects)
* [symbol text objects](#symbol-text-objects)

## Alias text objects

* inspired by [Tim Pope's vim-surround](https://github.com/tpope/vim-surround)

| text object | effect |
|--------------|-----------------------|
| `ir`/`ar` | Aliases for `i[`/`a[` |
| `ia`/`aa` | Aliases for `i<`/`a<` |

* with these added, you have three full sets of text objects for the common brackets:

| | parentheses | braces | square brackets | angle brackets |
|--------------|--------------|-----------|-----------------|----------------|
| *char* | `ib`/`ab` | `iB`/`aB` | `ir`/`ar` | `ia`/`aa` |
| *opendelim* | `i(`/`a(` | `i{`/`a{` | `i[`/`a[` | `i<`/`a<` |
| *closedelim* | `i)`/`a)` | `i}`/`a}` | `i]`/`a]` | `i>`/`a>` |

* these text objects are exactly equal in functionality
* this fact is important for the upcoming [expression text objects](#expression-text-objects) and [field text objects](#field-text-objects)

## Expression text objects

* inspired by [vim-textobj-functioncall](https://github.com/machakann/vim-textobj-functioncall)

Expression text objects are a generalization of *function calls*, *function definitions*, *arrays*, *C++ templates*, and more.
The general expression of an expression text object is `[text][opendelim][text][closedelim]`.
All of the following follow this criteria:

```c
function_call(argument1, argument2, argument3)
let dict = { "key1": value1, "key2", value2 }
let a = ["hello", "world"]
Array val = new Array
```

**Expression text objects** have the structure "{`[ia]`}`e`{`[b()]`/`[B{}]`/`[r[\]]`/`[a<>]`}".

`ie*` selects the whole bracket (like "`a`") preceded by `[count]` [words](https://stackoverflow.com/questions/22931032/vim-word-vs-word).

`ae*` selects the whole bracket (like "`a`") preceded by `[count]` [WORDs](https://stackoverflow.com/questions/22931032/vim-word-vs-word).
However, if you don't supply a count, it will not default to "1 WORD" but rather it
will jump to the start of the line.

With both `ie*` and `ae*`, `motion-sickness` will be smart not to include partial brackets, etc.

The variable `g:sickness#expression#preferred_shortcut_map` can be set use an alternative set of mappings.
Utilizing the fact, that `ib`, `i(`, `i)` are [the same](#alias-text-objects), you can set
them to the shorter version. Just put either of the following into your vimrc.

```vim
let g:sickness#expression#preferred_shortcut_map = 'opendelim' " uses {i,a}{(,{,[,<} for expression text objects
let g:sickness#expression#preferred_shortcut_map = 'closedelim' " uses {i,a}{),},],>} for expression text objects
let g:sickness#expression#preferred_shortcut_map = 'char' " uses {i,a}{b,B,r,a} for expression text objects

" or if you want to set your own mappings
let g:sickness#expression#use_default_maps = 0

omap ieb (textobj-sickness-expression-parenthesis-i)
xmap ieb (textobj-sickness-expression-parenthesis-i)
omap aeb (textobj-sickness-expression-parenthesis-a)
xmap aeb (textobj-sickness-expression-parenthesis-a)

omap ieB (textobj-sickness-expression-brace-i)
xmap ieB (textobj-sickness-expression-brace-i)
omap aeB (textobj-sickness-expression-brace-a)
xmap aeB (textobj-sickness-expression-brace-a)

omap ier (textobj-sickness-expression-bracket-i)
xmap ier (textobj-sickness-expression-bracket-i)
omap aer (textobj-sickness-expression-bracket-a)
xmap aer (textobj-sickness-expression-bracket-a)

omap iea (textobj-sickness-expression-chevron-i)
xmap iea (textobj-sickness-expression-chevron-i)
omap aea (textobj-sickness-expression-chevron-a)
xmap aea (textobj-sickness-expression-chevron-a)
```

## Field text objects

* inspired by [vim-textobj-argument](https://github.com/gaving/vim-textobj-argument)

**Field text objects** have the structure "{`i`,`a`}`f`{`b`/`(`/`)`,`B`/`{`/`}`,`r`/`[`/`]`,`a`/`<`/`>`}".

An *inner field* selects the current field, enclosed in the specific brace. Think of
arguments in function, list elements, dictionary entries, etc.

An *all field* selects an inner field, together with the field delimiter (usually a comma)

The variable `g:sickness#expression#maps` can be set use an alternative set of mappings.
Utilizing the fact, that `ib`, `i(`, `i)` are [the same](#alias-text-objects), you can set
them to the shorter version. Just put either of the following into your vimrc.

```vim
let g:sickness#field#preferred_shortcut_map = 'opendelim' " uses {i,a}{(,{,[,<} for field motions
let g:sickness#field#preferred_shortcut_map = 'closedelim' " uses {i,a}{),},],>} for field motions
let g:sickness#field#preferred_shortcut_map = 'char' " uses {i,a}{b,B,r,a} for field motions

" or if you want to set it entirely yourself
let g:sickness#field#use_default_maps = 0

omap ifb (textobj-sickness-field-parenthesis-i)
vmap ifb (textobj-sickness-field-parenthesis-i)
omap afb (textobj-sickness-field-parenthesis-a)
vmap afb (textobj-sickness-field-parenthesis-a)

omap ifB (textobj-sickness-field-brace-i)
vmap ifB (textobj-sickness-field-brace-i)
omap afB (textobj-sickness-field-brace-a)
vmap afB (textobj-sickness-field-brace-a)

omap ifr (textobj-sickness-field-bracket-i)
vmap ifr (textobj-sickness-field-bracket-i)
omap afr (textobj-sickness-field-bracket-a)
vmap afr (textobj-sickness-field-bracket-a)

omap ifa (textobj-sickness-field-chevron-i)
vmap ifa (textobj-sickness-field-chevron-i)
omap afa (textobj-sickness-field-chevron-a)
vmap afa (textobj-sickness-field-chevron-a)
```

4 types of list styles are supported.
In other words, these are basis for the unit tests, and for the algorithm governing
these text objects.

#### short style

```c
foo(arg1, arg2, arg3)
```

#### opening delimiter-indented style

```c
foo_function(arg1, arg2,
arg3, another_arg)
```

#### trailing-symbol style

```c
foo_function(
arg1,
arg2,
arg3
)
```

#### leading-symbol style

```c
Foo ( arg1
, arg2
, arg2
, arg3
)
```

The following gif showcases some examples of expression and field text objects:

![expression text objects cast](https://media.giphy.com/media/dApCdA2gycwomwrIGO/giphy.gif)

## Indent text objects

* inspired by [vim-indent-object](https://github.com/michaeljsmith/vim-indent-object)

These text objects are meant to support the `ip` and `ap` text objects for selecting
paragraphs. `ip` and `ap` simply disregard indentation.

| text object | effect |
|--------------|-----------------------------------------------|
| `iip`/`aip` | Similar to `ip`/`ap`, except it does not exceed the current indentation level. Does accept counts. Mnemonic is "inner/all indentation paragraph"|
| `iil`/`ail` | Selects the entire current indentation level excluding / including leading and trailing empty lines. Does not accept counts. Mnemonic is "inner/all indentation level".|
| `iib`/`aib` | Like `ail` and it selects one line of lower indent before and after the section. Does accept counts. Mnemonic is "inner/all indentation block". |
| `iit`/`ait` | Like `ail` and it selects one line of lower indent before the section. Does accept counts. Mnemonic is "inner/all indentation top". |

![Indent text objects cast](https://media.giphy.com/media/hSEh6Plw8e40MhPf2e/giphy.gif)

In a text like like the following, if you execute `iil` on any line within the
function definition, the line featuring `argument3` will not be selected, but will
be detected as probably belonging to the preceding line. This behavior is governed by
the `g:sickness#indentation#exclude_leading_indents` variable.

```c
int my_function(int argument1, int argument2,
int argument3) { // <- will not be included in `iil` or `ail` text object
// if you set g:sickness#indentation#excluse_leading_indents to 0
line1();
line2();
line3();
...
lineN();
}
```

If you wish to set the indent mappings yourself, you can do so:

```vim
let g:sickness#indentation#use_default_maps = 0

omap iip (textobj-sickness-indentation-paragraph-i)
vmap iip (textobj-sickness-indentation-paragraph-i)
omap aip (textobj-sickness-indentation-paragraph-a)
vmap aip (textobj-sickness-indentation-paragraph-a)

omap iil (textobj-sickness-indentation-level-i)
vmap iil (textobj-sickness-indentation-level-i)
omap ail (textobj-sickness-indentation-level-a)
vmap ail (textobj-sickness-indentation-level-a)

omap iib (textobj-sickness-indentation-block-i)
vmap iib (textobj-sickness-indentation-block-i)
omap aib (textobj-sickness-indentation-block-a)
vmap aib (textobj-sickness-indentation-block-a)

omap iit (textobj-sickness-indentation-top-i)
vmap iit (textobj-sickness-indentation-top-i)
omap ait (textobj-sickness-indentation-top-a)
vmap ait (textobj-sickness-indentation-top-a)
```

## Line text objects

* inspired by [vim-textobj-line](https://github.com/kana/vim-textobj-line)

| text object | effect |
|--------------|------------------------------------|
| `il` | Select the current line excluding leading/trailing blank characters (from `^` to `g_`). Does not accept a count. |
| `al` | Select the current line including leading/trailing blank characters (from `0` to `$`). Does not accept a count. |

If you wish to set the mappings yourself, you can do so:

```vim
let g:sickness#line#use_default_maps = 0

omap il (textobj-sickness-line-i)
xmap il (textobj-sickness-line-i)
omap al (textobj-sickness-line-a)
xmap al (textobj-sickness-line-a)
```

## View text objects

| text object | effect |
|--------------|------------------------------------|
| `iv` | Selects the currently visible window (from `H` to `L`). Does not accept a count. Saves the current position in the [jump list](http://vimdoc.sourceforge.net/htmldoc/motion.html#jumplist).|
| `av` | Selects the entire buffer (from `gg` to `G`). Does not accept a count. Saves the current position in the [jump list](http://vimdoc.sourceforge.net/htmldoc/motion.html#jumplist).|

If you wish to set the mappings yourself, you can do so:

```vim
let g:sickness#view#use_default_maps = 0

omap iv (textobj-sickness-view-i)
xmap iv (textobj-sickness-view-i)
omap av (textobj-sickness-view-a)
xmap av (textobj-sickness-view-a)
```

## Symbol text objects

| text object | effect |
|--------------|------------------------------------|
| `i*`/`a*` | Similar to `i"`/`a"`, but for `*` |
| `i_`/`a_` | Similar to `i"`/`a"`, but for `_` |
| `i-`/`a-` | Similar to `i"`/`a"`, but for `-` |
| `i:`/`a:` | Similar to `i"`/`a"`, but for `:` |
| `i@`/`a@` | Similar to `i"`/`a"`, but for `@` |
| `i!`/`a!` | Similar to `i"`/`a"`, but for `!` |
| `i?`/`a?` | Similar to `i"`/`a"`, but for `?` |
| `i/`/`a/` | Similar to `i"`/`a"`, but for `/` |
| `i%`/`a%` | Similar to `i"`/`a"`, but for `%` |
| `i\|`/`a\|` | Similar to `i"`/`a"`, but for `\|` |