Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/boltlessengineer/smart-tab.nvim

Easily jump to the end of current node.
https://github.com/boltlessengineer/smart-tab.nvim

neovim neovim-plugin nvim nvim-plugin

Last synced: 3 months ago
JSON representation

Easily jump to the end of current node.

Lists

README

        

# smart-tab.nvim

simple plugin implements smart-tab feature from [Helix
23.10](https://helix-editor.com/news/release-23-10-highlights/#smart-tab).

> Smart Tab is a new feature bound to the tab key in the default keymap.
> When you press tab and the line to the left of the cursor isn't all
> whitespace, the cursor will jump to the end of the syntax tree's
> parent node.

> This is useful in languages like Nix for adding semicolons at the end
> of an attribute set or jumping to the end of a block in a C-like
> language

## Note for differences

I haven't used or looked inside helix's implementation. I just borrowed
the idea, so behavior might differ from Helix's. Let me know if you have
any suggestions for improvement.

## Setup

```lua
require('smart-tab').setup({
-- default options:
-- list of tree-sitter node types to filter
skips = { "string_content" },
-- default mapping, set `false` if you don't want automatic mapping
mapping = "",
-- filetypes to exclude
exclude_filetypes = {}
})
```

### Manual Keymap

```lua
vim.keymap.set("i", "", require('smart-tab').smart_tab)
```

> NOTE: this won't fallback to ``

## Usage

1. Press `` on insert mode.

2. If cursor is at non-blank line, cursor jumps to end of the current
node

- If current node type is in `skips`, cursor jumps to end of it's
parrent node

- If cursor is at blank line, literal `` is inserted

### Examples

Normal smart-tab.

```javascript
let obj = {
key = 1,| // <- press here
}
let obj = {
key = 1,
}| // <- cursor moves to here
```

Smart tab with skipping some node types.

```javascript
let str = "abc|de"
// ^ press here
let str = "abcde"|
// ^ cursor moves to here (skipping `string_content` node)
```

You can still insert `` on blank line.

```javascript
let example3 = {
| // <- press in blank line
}
let example3 = {
| // literal `` is inserted
}
```