53

Multi targets (any block, any quote) and extensibility by wellle · Pull Request...

 5 years ago
source link: https://github.com/wellle/targets.vim/pull/217
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Lets kick this off with a bit of trivia: This is the biggest internal update/PR of targets.vim ever (ignoring test files). I've worked on this on and off for over a year. More than 50% of the code (excluding tests) has been changed.The main motivation here was to add support for any objects. So now if you type dab it deletes any block ((), [], {}) and daq deletes any quote ("", '', ``), whatever is closest to the cursor. You can of course disable that behaviour or set up your multi targets differently. Check the docs for how to customise it.Close #131Close #154Close #176The challenge was to make this work with counts (d2ab to select the second outer block, even if they are of different kinds) with the next and last modifiers (danb, d2alb etc.) and seeking (dab delete next block if cursor is not inside of a block). In short I wanted to implement them with full support of all the targets.vim features.The basic idea is to allow having multiple target generators, which can internally be combined into a generator which enumerates such multi targets.It is also built in a way that is extensible, so plugin authors can now implement their own plugins for targets.vim to add additional text objects with full support for all the targets.vim features mentioned above. And those external targets can be combined with built in targets as multi targets as well.For further details on how targets.vim works internally now and how to implement your own plugins, check the new plugins.md file added in this PR. And I just released a fully working example of an external targets.vim plugin here: https://github.com/wellle/line-targets.vimThere are also many minor improvements in handling certain edge cases. For example skipping has been improved a lot. So if you enter visual mode and skip from one target to another it should behave much more consistently. For example in a file with many different blocks try typing vanbanbanbanb. Every time you type another set of anb the selection will jump to the next block. (Spoiler: I have some ideas to make this actually useful in the future, stay tuned)Autoloading has been improved as well, so start up time and first invocations should be even quicker than before.Note: Some old settings have been deprecated. They still work, but it's recommended to use the new ways of customisation. At the same time the new settings (including multi targets) only take effect if you're using Vim version 7.3.338 or later or Neovim (because they rely on expression mappings introduced in #199). If you're stuck on an older version, only the legacy settings will be used. In that case please refer to the docs in this repo on a version before 0.5.0.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK