sp3ctum / tshjkl.nvim

Tree-sitter hjkl movement for neovim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tshjkl.nvim 🌳

Tree-sitter hjkl mode

image

Usage

Toggle into tshjkl mode, then use hjkl to change scope or select a sibling node. Toggle is mapped to <M-v> (Alt-v) and nodes are visually selected by default. Toggle, movement keys, extmark highlights and select mode can be configured - check init.lua to see configuration and defaults.

Demo

tshjkl_intro.mp4

Example

Unwrapping a function

  • toggle with cursor over the inner body
  • change scope if you need to
  • d
  • toggle the node to replace
  • p
tshjkl_example_remove_wrap.mp4

Install

lazy.nvim:

{
  'gsuuon/tshjkl.nvim',
  config = true
}

packer.nvim:

use {
  'gsuuon/tshjkl.nvim',
  config = function()
    require('tshjkl').setup()
  end
}

Configure

You can override the default config with lazy opts:

{
  'gsuuon/tshjkl.nvim',
  opts = {
    keymaps = {
      toggle = '<leader>ct',
    },
    marks = {
      parent = {
        virt_text = { {'h', 'ModeMsg'} },
        virt_text_pos = 'overlay'
      },
      child = {
        virt_text = { {'l', 'ModeMsg'} },
        virt_text_pos = 'overlay'
      },
      prev = {
        virt_text = { {'k', 'ModeMsg'} },
        virt_text_pos = 'overlay'
      },
      next = {
        virt_text = { {'j', 'ModeMsg'} },
        virt_text_pos = 'overlay'
      }
    }
  }
}

Or packer in require('tshjkl').setup({}):

use {
  'gsuuon/tshjkl.nvim',
  config = function()
    require('tshjkl').setup({
      keymaps = {
        toggle = '<leader>N',
      }
    })
  end
}

Keymaps

Check binds for more

v β€” visual select the current node (if config.select_current_node is false)
b β€” visual select backwards

h β€” parent
j β€” next sibling
k β€” previous sibling
l β€” child

H β€” top-most parent
J β€” last sibling
K β€” first sibling
L β€” inner-most child

Motivation

This plugin makes it easier to work with tree-sitter nodes - I've found it often surprising which node is under the cursor so I want to make navigating nodes as easy as basic navigation in Neovim. Visual select by default lets you do normal operations without too much extra thought - this just helps you easily select the node you're interested in.

About

Tree-sitter hjkl movement for neovim


Languages

Language:Lua 100.0%