Code Monkey home page Code Monkey logo

argument-text-object's Introduction

Argument Text Object

Vim plugin for working with function arguments.

This plugin (kinda) provides a text-object a(argument).

  • via, vaa - select in/an arg
  • dia, daa - delete in/an arg
  • cia, caa - change in/an arg
  • yia, yaa - yank (copy) in/an arg
  • ]a, [a - jump to next/prev arg

This plugin does more than simply f,dT,, because it recognizes the inclusion relationship of parentheses.

โš  WARNING โš : this plugin is in experimental phase, so feature set and provided commands may vary a lot.

Examples

Here | denotes cursor position.

Explanation Text before Input Text after
Delete an argument foo(ba|r, baz) press daa foo(|baz)
Delete in argument foo(ba|r, baz) press dia foo(|, baz)
Change in argument foo(ba|r, baz) press cia, type abc, press <esc> foo(abc|, baz)
Select in argument foo(ba|r, baz) press via foo(|bar|, baz)
Jump to next argument foo(ba|r, baz) press ]a foo(bar, |baz)

Installation

Just enable it in your preferable plugin manager.

Using vim-plug:

Plug 'dmytruek/argument-text-object'

Using packer:

use 'dmytruek/argument-text-object'

Configuration

Change or disable keybinds:

If you don't like default keybinds, you can disable them:

let g:argtextobj_disable_remaps = 1

And set your own (be sure not to map functions meant for visual mode to normal mode and vice versa):

xnoremap  aa :<C-U>ArgtextobjXaa<CR>
nnoremap daa :<C-U>ArgtextobjNdaa<CR>
nnoremap caa :<C-U>ArgtextobjNcaa<CR>
nnoremap yaa :<C-U>ArgtextobjNyaa<CR>

xnoremap  ia :<C-U>ArgtextobjXia<CR>
nnoremap dia :<C-U>ArgtextobjNdia<CR>
nnoremap cia :<C-U>ArgtextobjNcia<CR>
nnoremap yia :<C-U>ArgtextobjNyia<CR>

nnoremap  [a :<C-U>ArgtextobjNpa<CR>
nnoremap  ]a :<C-U>ArgtextobjNna<CR>

Search limit:

Change search limit:

let g:argtextobj_search_limit = 1000

Todo

  • add options to disable certain brackets , e.g. triangle brackets (bc they are used as greater/less symbol) (and other?)
  • select even when cursor is on bracket character
  • select more if some selection already exists (vaaaa - select one more argument)
  • select even more if all inside parentheses already selected
  • make [a goto begin of prev arg, not end
  • make ia, aa really text-object, not just binds
  • ? make it a bit smarter, so that it works as expected even when any of <,>,<=,>= is in arg, e.g. func(arg1, x < y, arg2)

If you have some other suggestions, feel free to open an issue.

Ideas

  • shift args (<a - move current arg to left, >a - move current arg to right)

Alternatives

argument-text-object's People

Contributors

dmytruek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

tymof1j

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.