-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[gc
/]gc
and [gb
/]gb
to navigate to the next/previous line/block comments
#169
Comments
[gc
/]gc
and [gb
/[gc
to navigate to the next/previous code blocks [gc
/]gc
and [gb
/[gb
to navigate to the next/previous line/block comments
[gc
/]gc
and [gb
/[gb
to navigate to the next/previous line/block comments [gc
/]gc
and [gb
/]gb
to navigate to the next/previous line/block comments
I'm just seeing that there is a lot of talk surrounding "text objects" implementation(s). I think the feature is in the same vein. So let me know if you prefer this subject be merged with another issue, or simply closed since it not really feasible, etc. |
I am open to ideas, but I am still not sure whether we should add text-objects of any kind inside the plugin. My concern stems from couple of reasons
I am hoping for other plugins which provides text-objects, to provide robust text-objects for comments so that we could leverage them after neovim supports
I'll let it sit open, so we can reference it in the future. |
All that sounds good.
I do know that nvim-treesitter-textobjects does offer an @comment textobject for a number of mainstream languages. Instead of creating the queries within |
Yes, that's the idea. And we also have https://github.com/RRethy/nvim-treesitter-textsubjects But nothing will work properly until |
gotcha - and is there an issue or pull-request to track the conversation and subsequent work on adding Separately, in preparation for getting more involved on such work, is there any content you'd recommend outside of the treesitter website and tree-sitter playground to get up-to-speed? |
Follow #133, i already linked couple of PR there.
There isn't much, maybe read other TS based plugins and neovim's core TS api (this is marked as experimental so there is much to improve) |
Let me jump in with my two cents: the idea of vi/vim/nvim is to have composable commands. Introducing text-objects mappings would impose an unnecessary maintainability burden. You can just map the toggles to single keys instead of default mappings, and compose whatever movement mapping Neovim already offers with visual mode and your mapped keys. For example, I can comment the following Javascript code: for (let i = 0; i < 10; i++) {
count += 2
console.log(count)
} with The thing is we have more than enough for whatever needs you may have. Below I share my -- Setup https://github.com/numToStr/Comment.nvim
-- See `:h comment-nvim`
require('Comment').setup({
-- Ignore empty lines
ignore = '^$',
mappings = {
-- Disable basic mappings. I'm gonna do my own, see below
basic = false,
-- Disable extra mappings, they are unnecessary
extra = false,
},
})
-- Toggle current line or with count
vim.keymap.set('n', '<F1>', function()
local toggle_current_line = '<Plug>(comment_toggle_linewise_current)j'
local toggle_count_lines = '<Plug>(comment_toggle_linewise_count)' .. vim.v.count .. 'j'
return vim.v.count == 0 and toggle_current_line
or toggle_count_lines
end, { expr = true })
-- Toggle visual, line comment
vim.keymap.set('x', '<F1>', '<Plug>(comment_toggle_linewise_visual)')
-- Toggle count, block comment
vim.keymap.set('n', '<F2>', function()
local toggle_count_block = '<Plug>(comment_toggle_blockwise_count)' .. vim.v.count .. 'j'
return toggle_count_block
end, { expr = true })
-- Toggle visual, block comment
vim.keymap.set('x', '<F2>', '<Plug>(comment_toggle_blockwise_visual)') Hope you find them useful. |
Thanks for the awesome plugin!
Given
Comment.nvim
already uses treesitter, and ships with a number of optional mappings. I love to see this one as an option as well. I tried adding[gc
and]gc
to mytreesitter.textobjects
config, but the 3 character plugins don't work all that well. Perhaps that's different here?If you're swamped, I can take a stab at it! Just would most likely need some help implementing/understanding the code base.
I look forward to your thoughts.
The text was updated successfully, but these errors were encountered: