Skip to content

Zhuxy/kontur.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

kontur.nvim

Intro

kontur.nvim provides powerful and intuitive text objects to select and operate on blocks of text based on their structure. It understands code indentation, Markdown-style headings, repeatable prefix patterns, and Markdown tables, allowing you to work with logical blocks seamlessly.

The basic concept is to select neighboring lines of text base on the indent level under the cursor.

When searching the lines, the operation means all the neighboring lines whose indent level is equal or lower than the line under the cursor.

Including any empty line when searching.

UPDATE:

Now we can select content by Markdown heading level.

Using vih to select all lines under the nearest Markdown heading, and vah to include the heading line itself.

UPDATE 2:

Now we can select lines which share the same repeatable prefix pattern, meaning the same leftmost non-whitespace marker. r stands for repeatable prefix pattern. For example, all lines with a comment prefix // can be selected by vir. It also supports numbered lists such as 1. , 2. , ..., 10. , 11. .

UPDATE 3:

Now we can select a Markdown pipe table with vit. The selector works from the header row, delimiter row, or any body row.

Config

The default keystroke for indent line is i. If you want to use another character, you can set the config object:

require("kontur").setup({
    indent_object_char = 'i', -- now use `ii` to select by indent
    heading_object_char = 'h', -- now use `ih` to select by markdown heading
    prefix_object_char = 'r', -- now use `ir` to select by repeatable prefix pattern
    table_object_char = 't', -- now use `it` to select by markdown table
})

Usage

Select by indent

Here is a function:

 local function test()
   print(1)
   print(2)     <-- cursor here
   print(3)
 end

use vii to select function body (They all have the same indent level):

 local function test()
β–ˆ  print(1)
β–ˆ  print(2)
β–ˆ  print(3)
 end

Here are some markdown texts:

 # Header 1
 - List 1
   - Sub list 1
   - Sub list 2     <-- cursor here
   - Sub list 3
 
 # Header 2

use vii to select sub lists (without the empty line):

 # Header 1
 - List 1
β–ˆ  - Sub list 1
β–ˆ  - Sub list 2
β–ˆ  - Sub list 3
 
 # Header 2

Select by Markdown headings

Here are some markdown texts:

 # Header 1
 - List 1
   - Sub list 1
   - Sub list 2     <-- cursor here
   - Sub list 3
 
 # Header 2

use vih to select all lines under the nearest Markdown heading:

 # Header 1
β–ˆ- List 1
β–ˆ  - Sub list 1
β–ˆ  - Sub list 2
β–ˆ  - Sub list 3

 # Header 2

use vah to select the heading and all its content, trimming trailing blank lines:

β–ˆ# Header 1
β–ˆ- List 1
β–ˆ  - Sub list 1
β–ˆ  - Sub list 2
β–ˆ  - Sub list 3

 # Header 2

Select by repeatable prefix pattern

Here is some code with comments that share the same repeatable prefix pattern, // :

 let a = 42;
 // This is a comment
 // This is another comment      <-- cursor here
 // And one more
 print(a);

use vir to select the comment block:

 let a = 42;
β–ˆ// This is a comment
β–ˆ// This is another comment      <-- cursor here
β–ˆ// And one more
 print(a);

Or you can select the numbered list:

 1. First item
 2. Second item
 3. Third item             <-- cursor here
 ...
 11. Eleventh item

use vir to select the numbered list:

β–ˆ1. First item
β–ˆ2. Second item
β–ˆ3. Third item
β–ˆ...
β–ˆ11. Eleventh item 

Select by Markdown table

Here is a Markdown pipe table:

Before

| Name | Align | Count |
| --- | :---: | ---: |
| Ada | mid | 1 |       <-- cursor here
| Linus | low | 2 |

After

use vit to select the whole table:

Before

β–ˆ| Name | Align | Count |
β–ˆ| --- | :---: | ---: |
β–ˆ| Ada | mid | 1 |
β–ˆ| Linus | low | 2 |

After

About

Kontur.nvim is a Neovim plugin that provides intuitive text objects to select and operate on blocks of text based on their indent level or under a markdown heading.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages