Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use [ and ] to enhance all of your Neovim text-objects and text-operators!

License

NotificationsYou must be signed in to change notification settings

ColinKennedy/cursor-text-objects.nvim

Repository files navigation

Build Statusunittestsdocumentationluacheckllscheckstyluaurlchecker
LicenseLicense-MIT
SocialRSS

How To Use

Summary

In short, mappings likedap, which delete a whole paragraph, now can used[ap which means "delete from the start of the paragraph to your currentcursor position" andd]ap means "delete from the current cursor position tothe end of the paragraph".

It works with any text operator or text object pair and integrates with existing plugins.

Details

For every text object and text operator that Vim has, you can now "include"your cursor as a part of the command.

Here's a practical example. Have you ever had a paragraph of text like this.

Some text with many lines. And somethingthat wraps multiple|cursor here| lines in a single sentence.Lorem ipsum and all that.More paragraph text

And you'd like delete just from your current|cursor| to the bottom of theparagraph? You can't usedap, that deletes the whole paragraph. Withcursor-text-objects.nvim, you can used]ap which means "delete from thecurrent cursor position around the end of the paragraph". And you can delete tothe start of the paragraph withd[ap. If you want to delete to the start ofthe sentence, used[is.

Again,any text operator or text object command that you can think of nowworks with your cursor. Here's more examples.

  • d[a} - Delete around the start of a {}-pair to the cursor.
  • d]a} - Delete around the cursor to the end of a {}-pair.
  • gc[ip - Comment from the start of the paragraph to the cursor.
  • gc]ip - Comment from the cursor to the end of the paragraph.
  • gw[ip - Format from the start of the paragraph to the cursor.
  • gw]ip - Format from the cursor to the end of the paragraph.
  • v[ip - Select from the start of the paragraph to the cursor.
  • v]ip - Select from the cursor to the end of the paragraph.
  • y[ib - Yank inside start of a ()-pair to the cursor.
  • y]ib - Yank inside the cursor to the end of a ()-pair.

It works with custom operators and objects too!

Usingnvim-treesitter-textobjects

  • v]ic - Select lines from the cursor to the end of a class.
  • v[ic - Select lines from the start of a class to the cursor.
  • v]if - Select lines from the cursor to the end of a function.
  • v[if - Select lines from the start of a function to the cursor.

Usingvim-textobj-indent

  • c[ii - Change from start of the indented-lines to the cursor.
  • c]ii - Change from the cursor to the end of the indented-lines.

etc. etc. etc.

Give your right-pinky a workout and installcursor-text-objects.nvim today!

Installation

{"ColinKennedy/cursor-text-objects.nvim",config=function()vim.keymap.set(            {"o","x"},"[","<Plug>(cursor-text-objects-up)",            {desc="Run from your current cursor to the end of the text-object."}        )vim.keymap.set(            {"o","x"},"]","<Plug>(cursor-text-objects-down)",            {desc="Run from your current cursor to the end of the text-object."}        )end,version="v2.*",}

Disclaimer

The default recommended mappings,[ and], will not conflict with existingmappings. There'sa testscriptthat verifies this.

However if you have another mapping like this:

vim.keymap.set({'n', 'x', 'o'}, '[i', function() return "dd" end, {expr=true})

then you may be surprised thatd[ip does not work.

In short while actually this is not a conflict, it can still be confusing fora you and you'll want to remapcursor-text-objects or that other mapping/ plug-in to avoid the issue.

More details on what is going on in this case

cursor-text-objects is a pending operator but the mapping above is a regularoperator. A pending operator is a mapping that "waits for the user to keeptyping more keys" but a regular operator executes immediately. So if you onlyhavecursor-text-objects applied,ip is interpreted as "[i]nside[p]aragraph". But with the mapping above,d[i executes immediately and thentreatsp as the start of a new command. Andp as a standalone keymap means[p]ut. (See:help put for details).

So again this is all expected behavior but if you don't want that to happen,you're better off remapping[i to something else.

Tests

Initialization

Run this line once before calling anybusted command

eval$(luarocks path --lua-version 5.1 --bin)

Running

Run all tests

luarockstest --test-type busted# Or manuallybusted --helper spec/minimal_init.lua.# Or with Makemaketest

Run test based on tags

busted --helper spec/minimal_init.lua. --tags=simple

Tracking Updates

Seedoc/news.txt for updates.

You can watch this plugin for changes by adding this URL to your RSS feed:

https://github.com/ColinKennedy/cursor-text-objects.nvim/commits/main/doc/news.txt.atom

Other Plugins

This plugin is a sort-of successor tovim-ninja-feet with some notable differences

  • visual mode support
  • better edge-case handling
  • (IMO) better documenting what the code does / how it works

About

Use [ and ] to enhance all of your Neovim text-objects and text-operators!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp