Comment.nvim icon indicating copy to clipboard operation
Comment.nvim copied to clipboard

`i_<C-\><C-o>gcc` prints `g@$`

Open Josiah-tan opened this issue 4 years ago • 4 comments

Thank you for this amazing plugin! (TJ brought me here) I found this strange bug that happens for your plugin, but doesn't occur with Tpope's. Write the following: (I used python for this example)

print("hello world")

When while still in insert mode write: <C-\><C-o>gcc (<C-\><C-o>) takes you into normal mode for a single command before returning to insert mode) expected behavior:

# print("hello world")

actual behavior:

print("hello world")g@$

setup (default):

lua require("Comment").setup()

nvim v0.7.0-dev

Let me know if you need any other information please!

Josiah-tan avatar Apr 17 '22 16:04 Josiah-tan

I am not sure about the <C-\><C-o> combination but AFAIK even <C-o> is enough to put you on normal mode from insert mode.

numToStr avatar Apr 17 '22 17:04 numToStr

for some strange reason even <C-o>gcc exhibits the same behavior as above (also it's not easy to find but the help menu is :help i_CTRL-\_CTRL-O in case you were having trouble [I did personally])

Josiah-tan avatar Apr 18 '22 00:04 Josiah-tan

I see, that both <C-\><C-o> and <C-o> are similar. Although, I am not sure how to fix this as of now. vim-commentary must be doing something to prevent this, might be a workaround or something trivial.

numToStr avatar Apr 18 '22 06:04 numToStr

Hmm, I found another bug that I fixed with might actually lead to some clues as to what the problem might be with this plugin. So let this be a motivating example:

nnoremap J mzJ`z

This map ensures the cursor stays where it is when joining lines together. So let this be a motivating example, with the cursor placed at the end of the first line:

print("hello world")
print("hello world")

Now, when I try joining the lines in insert mode using the <C-o> hack this happens:

print("hello world")J`z
print("hello world")

Essentially, it seems that the remap doesn't seem to completely work here as it makes a mark for the first command mz, but then returns to insert mode before the other commands are completed. I found that this solves the problem:

function! LineJoin()
norm! mzJ`z
end function
nnoremap J :call LineJoin()<cr>

It seems like a function call fixed the problem, but I can't be entirely sure without diving deeper into the code.

print("hello world") print("hello world")

Josiah-tan avatar Apr 18 '22 10:04 Josiah-tan

Hey @Josiah-tan, Sorry for coming on this so late. But would you mind trying #204 and let me know whether this fixes the issue?

numToStr avatar Aug 13 '22 11:08 numToStr