Code Monkey home page Code Monkey logo

line-targets.vim's Introduction

This is a simple example plugin which extends the 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:

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:

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:

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.

line-targets.vim's People

Contributors

rafaeln avatar wellle avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

rafaeln

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.