Git Product home page Git Product logo

vim-motion-sickness's Introduction

motion-sickness.nvim Build Status Build Status

This plugin adds a slew of new possible text objects. Vader 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.:

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

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

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

List of text objects

Alias text objects

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>

Expression text objects

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:

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

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

ie* selects the whole bracket (like "a<bracket>") preceded by [count] words.

ae* selects the whole bracket (like "a<bracket>") preceded by [count] WORDs. 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, you can set them to the shorter version. Just put either of the following into your vimrc.

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 <plug>(textobj-sickness-expression-parenthesis-i)
xmap ieb <plug>(textobj-sickness-expression-parenthesis-i)
omap aeb <plug>(textobj-sickness-expression-parenthesis-a)
xmap aeb <plug>(textobj-sickness-expression-parenthesis-a)

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

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

omap iea <plug>(textobj-sickness-expression-chevron-i)
xmap iea <plug>(textobj-sickness-expression-chevron-i)
omap aea <plug>(textobj-sickness-expression-chevron-a)
xmap aea <plug>(textobj-sickness-expression-chevron-a)

Field text objects

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, you can set them to the shorter version. Just put either of the following into your vimrc.

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 <plug>(textobj-sickness-field-parenthesis-i)
vmap ifb <plug>(textobj-sickness-field-parenthesis-i)
omap afb <plug>(textobj-sickness-field-parenthesis-a)
vmap afb <plug>(textobj-sickness-field-parenthesis-a)

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

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

omap ifa <plug>(textobj-sickness-field-chevron-i)
vmap ifa <plug>(textobj-sickness-field-chevron-i)
omap afa <plug>(textobj-sickness-field-chevron-a)
vmap afa <plug>(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

foo(arg1, arg2, arg3)

opening delimiter-indented style

foo_function(arg1, arg2,
             arg3, another_arg)

trailing-symbol style

foo_function(
    arg1,
    arg2,
    arg3
)

leading-symbol style

Foo ( arg1
    , arg2
    , arg2
    , arg3
    )

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

expression text objects cast

Indent text objects

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

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.

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:

let g:sickness#indentation#use_default_maps = 0

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

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

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

omap iit <plug>(textobj-sickness-indentation-top-i)
vmap iit <plug>(textobj-sickness-indentation-top-i)
omap ait <plug>(textobj-sickness-indentation-top-a)
vmap ait <plug>(textobj-sickness-indentation-top-a)

Line text objects

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:

let g:sickness#line#use_default_maps = 0

omap il <plug>(textobj-sickness-line-i)
xmap il <plug>(textobj-sickness-line-i)
omap al <plug>(textobj-sickness-line-a)
xmap al <plug>(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.
av Selects the entire buffer (from gg to G). Does not accept a count. Saves the current position in the jump list.

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

let g:sickness#view#use_default_maps = 0

omap iv <plug>(textobj-sickness-view-i)
xmap iv <plug>(textobj-sickness-view-i)
omap av <plug>(textobj-sickness-view-a)
xmap av <plug>(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 |

vim-motion-sickness's People

Contributors

hgiesel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vim-motion-sickness's Issues

Idea for behavior of repeat expression motions

The way repeated ab, ibs behavior is basically:
omap: normal behavior
vmap: save current selection, try from current spot, if the same as previous selection, go l and try again. If it doesn't change the selection, go back.

Make `ii`/`ai` more similar to `ip`/`ap`

And make iI and aI more like "special commands":

  • iI:
    ** at the current indent level, expand into (both/one?) directions as far as possible
    ** maybe allow at zero indent level...

  • aI:
    ** at the current indent level, expand into (both/one?) direction as far as possible
    ** after that, include the first line of lower indent and generally decrease the current indent level

  • also means that all at least ii and ai should accept counts

ii ai naming scheme

Make them 6

  • Indentation paragraph: iip / aip for current ii/ai
  • Indentation Level: iil / ail for current iI without enclosing whitespace / iI for with enclosing whitespace
  • Indentation Block: iib / aib for current aI with only top / aI with top and bottom

Make qmotions handle assignments

At the moment qb/Qb on parentheses which don't have a prefix is redundant. I want to make both more powerful:

  • qb should take WORD instead word, thus replacing Qb. For word functionality oww... is way more functional, because it allows for more granuity which I could never achieve with qb.
  • Qb should take everything, excluding opening delimiters ({[<, thus allowing it to select statements, like so:
foo = [
  "hello",
  "world",
]

Make `ieb` stand out a bit more

ieb on the below case could skip a space and capture the WORD. aeb would keep selecting the whole line ^

let foo = function() {
   foobar();
}

exception on ieb

"~/vimpy3/plugged/vim-netranger/pythonx/netranger/Vim.py" 197L, 5237C
Error detected while processing function sickness#textobj#expression#motion[45]..141_MatchOpenCloseDelims:
line 6:
E712: Argument of count() must be a List or Dictionary
E712: Argument of count() must be a List or Dictionary
E712: Argument of count() must be a List or Dictionary
E712: Argument of count() must be a List or Dictionary
E712: Argument of count() must be a List or Dictionary
E712: Argument of count() must be a List or Dictionary
E712: Argument of count() must be a List or Dictionary
E712: Argument of count() must be a List or Dictionary

I am on neovim v0.3.1.1 with Oni

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.