mfussenegger / nvim-treehopper

Region selection with hints on the AST nodes of a document powered by treesitter
GNU General Public License v3.0
426 stars 17 forks source link

Recommended keymaps feel unnecessarily complex #38

Closed SirWrexes closed 7 months ago

SirWrexes commented 7 months ago

I was trying out the plugin and couldn't get it to work with either

local tsht = require('tsht')
vim.keymap.set("o", "<Space>", tsht.nodes)
vim.keymap.set("x", "<Space>", tsht.nodes, { noremap = true })

or

vim.cmd([[ omap     <silent> <Space> :<C-U>lua require('tsht').nodes()<Cr> ]])
vim.cmd([[ xnoremap <silent> <Space> :     lua require('tsht').nodes()<Cr> ]])

However, simply doing this works just fine:

vim.keymap.set('n', '<Space>', tsht.nodes, { noremap = true })

Which leaves me with the following questions: What's the point of all this fuss about Visual/Select (mapmode-x) modes ? By extension, why use Operator-pending (mapmode-o) ? Finally, why all this ceremony while simply just calling tsht.nodes() in Normal Just Works™ ?

Side note: Despite years of daily (Neo)Vim and constant ricing of it, I never knew Operator-pending existed; or seen it in a config for that matter. This by itself could end up being very confusing to a lot of users, as it feels highly unconventional. :thinking:

mfussenegger commented 7 months ago

I don't see what's highly unconventional about operator pending mode. It's what powers functionality like dw or cw, which to me are vi basics. The operator keymap allows you to do things like d<tsht-trigger> to delete a node.

The visual mode mapping creates some kind symmetry for that. Similar to how d<tsht-trigger> will delete a node, v<tsht-trigger> will select a node. Granted, explicit visual mode trigger is a bit redundant in this case as you'd end up with a visual selection anyway, but I like the explicitness and that it allows to use a key that has a different function in normal mode.

And they're just recommendations anyway. Part of the vi culture is to customize things to your own preferences.

SirWrexes commented 6 months ago

The operator keymap allows you to do things like d<tsht-trigger> to delete a node.

brainsplode like a revelation My bad then. I simply never saw a plugin that required this type of setup before, but you just opened my eyes to a whole new world of possibilities, thanks !

The visual mode mapping creates some kind symmetry for that. Similar to how d<tsht-trigger> will delete a node, v<tsht-trigger> will select a node. Granted, explicit visual mode trigger is a bit redundant in this case as you'd end up with a visual selection anyway, but I like the explicitness and that it allows to use a key that has a different function in normal mode.

Right, I understand now. Though it's weird: It just doesn't work for me, like at all. Tried setting it up in lua then vimscript. Tried using <Space> then m (thinking mabe <Space> is being weird). Tried using :<C-U> ... then <Cmd>.... It jumps to the end of the node, and nothing is selected. However, if I do v:lua require 'tsht' .nodes() manually it works as expected. Any idea ?

Thank you for your time. :pray: