You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it be possible to add in a motion for "duplicating" text? I often (hopefully I'm not the only one) will yank and paste and a line/paragraph of code and then comment out the original so I can look at it for reference while I rework it. For example:
defcool_function(hello)putshelloend
Typing something like gcd{motion} (ip here for a paragraph) would give us:
To be clear I won't support this inside the plugin. Currently, I am working on #62 which will give you the selected region in the pre_hook as an argument and you can use pre_hook in a way that is similar to your use case.
I am just dumping my brain here and assuming that the PR is merged. IMO following will be steps
Hello! It looks like the new refactor broke this function...
E5108: Error executing lua ...ite/pack/packer/start/Comment.nvim/lua/Comment/utils.lua:63: attempt to get length of local 'iter' (a nil
value)
stack traceback:
...ite/pack/packer/start/Comment.nvim/lua/Comment/utils.lua:63: in function 'is_empty'
...ite/pack/packer/start/Comment.nvim/lua/Comment/utils.lua:305: in function 'uncomment'
...te/pack/packer/start/Comment.nvim/lua/Comment/opfunc.lua:135: in function 'linewise'
...te/pack/packer/start/Comment.nvim/lua/Comment/opfunc.lua:76: in function 'opfunc'
.../site/pack/packer/start/Comment.nvim/lua/Comment/api.lua:152: in function 'comment_linewise_op'
/Users/gary/.config/nvim/lua/config/comment.lua:22: in function </Users/gary/.config/nvim/lua/config/comment.lua:12>
Should I just stick to 0.6.1? I'm afraid my Lua isn't good enough to fix it 😞
sharing my config that not disturb clipboard and cursor position.
Nice! But it does not support [count] and INSERT mode, so here is my version. It's not that good in keeping clipboard and cursor position (maybe someone helps inproving it with this). It's in Lazy keys = format:
{
'<C-C>',
function() -- Support for a count makes implementation a bit complicated.localcount=vim.v.count1localapi=require'Comment.api'vim.api.nvim_feedkeys('V', 'n', false)
ifcount>1thenvim.api.nvim_feedkeys((count-1) ..'j', 'n', false)
endvim.api.nvim_feedkeys('yP', 'nx', false)
api.comment.linewise.count(count)
vim.api.nvim_feedkeys('`<^i', 'n', false)
end,
mode='n',
desc='Backup (count) line(s) as a comment, then edit',
},
{
'<C-C>',
'V<Esc>gvy`>pgv<Esc>`>:lua require"Comment.api".comment.linewise("V")<CR><Down>^i',
mode='v',
silent=true,
desc='Backup selected lines as a comment, then edit',
},
{
'<C-C>',
'<C-O>yy<C-O>P<C-O>:lua require"Comment.api".comment.linewise.current()<CR><Down>',
mode='i',
silent=true,
desc='Backup current line as a comment',
},
Activity
numToStr commentedon Nov 18, 2021
To be clear I won't support this inside the plugin. Currently, I am working on #62 which will give you the selected region in the
pre_hookas an argument and you can usepre_hookin a way that is similar to your use case.I am just dumping my brain here and assuming that the PR is merged. IMO following will be steps
What do you say?
garymh commentedon Nov 18, 2021
@numToStr Sounds great! I appreciate it!
numToStr commentedon Nov 20, 2021
For future somebody, this is what you'll need
NOTE: The only downside is this duplication will happen every time. But you can determine when to do this by using
ctxargumentgarymh commentedon Dec 20, 2021
Hi @numToStr ! Has this changed recently because of the API? It seems to have stopped working...
numToStr commentedon Dec 21, 2021
@garymh Yes, because of the recent (breaking) changes I made to the lua APIs. Following is the updated version:
garymh commentedon Dec 22, 2021
Awesome!! Thank you so much!!
paopaol commentedon Apr 24, 2022
how do i use the function ___gdc, :lua _G.__gdc('n') ?
numToStr commentedon Apr 25, 2022
@paopaol See #73 (comment)
garymh commentedon Aug 1, 2022
Hello! It looks like the new refactor broke this function...
Should I just stick to 0.6.1? I'm afraid my Lua isn't good enough to fix it 😞
numToStr commentedon Aug 2, 2022
@garymh This should do it
(Also make sure to update the plugin, as I discovered a bug while testing this function)
garymh commentedon Aug 2, 2022
Perfect! Thank you so much, again! 😄
AniAggarwal commentedon Oct 8, 2022
Doesn't seem to work on Neovim v8.
When calling from visual mode:
From normal mode:
My mappings/config:
hexh250786313 commentedon Oct 21, 2022
My case:
@AniAggarwal
AniAggarwal commentedon Oct 29, 2022
I am not able to make that work. Unfortunately I am using a lua config. I translated it but don't seem to be able to get it working.
@hexh250786313
joncol commentedon Apr 4, 2023
The solution I went with:
I didn't thoroughly test it yet, but this seems to work with the cursor being at either end of a selection.
AniAggarwal commentedon Apr 4, 2023
Works perfectly for me, thanks!
joncol commentedon Apr 4, 2023
Simplified the binding a little bit.
tkkcc commentedon Mar 5, 2024
sharing my config that not disturb clipboard and cursor position.
Also,
which-keycan slow down recursive keymap noticeably.powerman commentedon Jul 8, 2024
Nice! But it does not support
[count]and INSERT mode, so here is my version. It's not that good in keeping clipboard and cursor position (maybe someone helps inproving it with this). It's in Lazykeys =format:{ '<C-C>', function() -- Support for a count makes implementation a bit complicated. local count = vim.v.count1 local api = require 'Comment.api' vim.api.nvim_feedkeys('V', 'n', false) if count > 1 then vim.api.nvim_feedkeys((count - 1) .. 'j', 'n', false) end vim.api.nvim_feedkeys('yP', 'nx', false) api.comment.linewise.count(count) vim.api.nvim_feedkeys('`<^i', 'n', false) end, mode = 'n', desc = 'Backup (count) line(s) as a comment, then edit', }, { '<C-C>', 'V<Esc>gvy`>pgv<Esc>`>:lua require"Comment.api".comment.linewise("V")<CR><Down>^i', mode = 'v', silent = true, desc = 'Backup selected lines as a comment, then edit', }, { '<C-C>', '<C-O>yy<C-O>P<C-O>:lua require"Comment.api".comment.linewise.current()<CR><Down>', mode = 'i', silent = true, desc = 'Backup current line as a comment', },