From 19515b8689d691043a9c4106c99fd843056d0a8a Mon Sep 17 00:00:00 2001 From: Aaron Sullivan Date: Tue, 31 Dec 2024 11:04:38 -0500 Subject: [PATCH] Update readme moar I came up with these updates in my dreams, man. --- README.md | 63 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index ad52c3a..58b65d2 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ Static Badge ![build status](https://github.com/aaronik/treewalker.nvim/actions/workflows/test.yml/badge.svg) +[![Github All Releases](https://img.shields.io/github/downloads/aaronik/treewalker.nvim/total.svg)]() # Treewalker.nvim @@ -22,6 +23,8 @@ The swap commands intelligently swap nodes, including comments and attributes/de --- +### More Examples +
Typing out the Move commands manually A demo of moving around some code slowly typing out each Treewalker move command @@ -36,14 +39,14 @@ The swap commands intelligently swap nodes, including comments and attributes/de ### Installation -#### [Lazy](https://github.com/folke/lazy.nvim): +#### [Lazy](https://github.com/folke/lazy.nvim) ```lua { - "aaronik/treewalker.nvim", + 'aaronik/treewalker.nvim', -- The following options are the defaults. -- Treewalker aims for sane defaults, so these are each individually optional, - -- and the whole opts block is optional as well. + -- and setup() does not need to be called, so the whole opts block is optional as well. opts = { -- Whether to briefly highlight the node after jumping to it highlight = true, @@ -53,17 +56,18 @@ The swap commands intelligently swap nodes, including comments and attributes/de -- The color of the above highlight. Must be a valid vim highlight group. -- (see :h highlight-group for options) - highlight_group = "ColorColumn", + highlight_group = 'ColorColumn', } } ``` -#### [Packer](https://github.com/wbthomason/packer.nvim): +#### [Packer](https://github.com/wbthomason/packer.nvim) ```lua use { - "aaronik/treewalker.nvim", + 'aaronik/treewalker.nvim', -- The setup function is optional, defaults are meant to be sane + -- and setup does not need to be called setup = function() require('treewalker').setup({ -- Whether to briefly highlight the node after jumping to it @@ -74,46 +78,53 @@ use { -- The color of the above highlight. Must be a valid vim highlight group. -- (see :h highlight-group for options) - highlight_group = "ColorColumn", + highlight_group = 'ColorColumn', }) end } ``` -#### [Vim-plug](https://github.com/junegunn/vim-plug): +#### [Vim-plug](https://github.com/junegunn/vim-plug) ```vimscript -Plug "aaronik/treewalker.nvim" +Plug 'aaronik/treewalker.nvim' -" The following is optional -:lua require("treewalker").setup({ highlight = true, highlight_duration = 250, highlight_group = "ColorColumn" }) +" This line is optional +:lua require('treewalker').setup({ highlight = true, highlight_duration = 250, highlight_group = 'ColorColumn' }) ``` --- -#### Mapping +### Mapping + +I've found Ctrl - h / j / k / l to be a really natural flow for this plugin, and adding +Shift to that for swapping just felt so clean. So here are the mappings I use: -This is how I have mine mapped; in `init.lua`: +In `init.lua`: ```lua -vim.keymap.set({ 'n', 'v' }, '', 'Treewalker Up', { noremap = true, silent = true }) -vim.keymap.set({ 'n', 'v' }, '', 'Treewalker Down', { noremap = true, silent = true }) -vim.keymap.set({ 'n', 'v' }, '', 'Treewalker Right', { noremap = true, silent = true }) -vim.keymap.set({ 'n', 'v' }, '', 'Treewalker Left', { noremap = true, silent = true }) -vim.keymap.set('n', '', 'Treewalker SwapDown', { noremap = true, silent = true }) -vim.keymap.set('n', '', 'Treewalker SwapUp', { noremap = true, silent = true }) +-- movement +vim.keymap.set({ 'n', 'v' }, '', 'Treewalker Up', { silent = true }) +vim.keymap.set({ 'n', 'v' }, '', 'Treewalker Down', { silent = true }) +vim.keymap.set({ 'n', 'v' }, '', 'Treewalker Right', { silent = true }) +vim.keymap.set({ 'n', 'v' }, '', 'Treewalker Left', { silent = true }) + +-- swapping up/down +vim.keymap.set('n', '', 'Treewalker SwapDown', { silent = true }) +vim.keymap.set('n', '', 'Treewalker SwapUp', { silent = true }) ``` -I also utilize some -[nvim-treesitter-textobjects](https://github.com/nvim-treesitter/nvim-treesitter-textobjects?tab=readme-ov-file#text-objects-swap) -commands to get lateral swapping (that way I get all four `` maps in a natural and intuitive feeling way): +Many other plugins do left/right swapping perfectly, so there's no need for Treewalker to implement those. +I use [nvim-treesitter-textobjects](https://github.com/nvim-treesitter/nvim-treesitter-textobjects?tab=readme-ov-file#text-objects-swap) +to complete all four `Ctrl-Shift-*` maps: ```lua -vim.keymap.set('n', '', 'TSTextobjectSwapNext @parameter.inner', { noremap = true, silent = true }) -vim.keymap.set('n', '', 'TSTextobjectSwapPrevious @parameter.inner', { noremap = true, silent = true }) +-- swapping left/right +vim.keymap.set('n', '', 'TSTextobjectSwapNext @parameter.inner', { silent = true }) +vim.keymap.set('n', '', 'TSTextobjectSwapPrevious @parameter.inner', { silent = true }) ``` The above can also be accomplished with [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) using [ts_utils](https://github.com/nvim-treesitter/nvim-treesitter?tab=readme-ov-file#utilities). -See [this PR](https://github.com/aaronik/treewalker.nvim/pull/10/files) for -an example of that! +See [this PR](https://github.com/aaronik/treewalker.nvim/pull/10/files#diff-1cedf17af3ebbcfeee2dfb1071445dcabfdb30f8e9f83ff0da95ea7e6e7ccde5R107-R130) +by @duqcyxwd for an example of how to implement that.