tomtom / tcomment_vim

An extensible & universal comment vim-plugin that also handles embedded filetypes
http://www.vim.org/scripts/script.php?script_id=1173
GNU General Public License v3.0
1.4k stars 103 forks source link

map TComment_gcc get `E354: Invalid register name: '$'` #306

Open ruinb0w opened 1 year ago

ruinb0w commented 1 year ago

I maped tcomment like below

vim.keymap.set('n', "<leader>c", '<plug>TComment_gcc')
vim.keymap.set('v', "<leader>c", '<plug>TComment_gc')

The second line works great, but the first one throws the error E354: Invalid register name: '$'

tomtom commented 1 year ago

Which version of vim do you use? I still use vim 8.2.

TComment_gcc should be something like nnoremap TComment_gcc :call tcomment#ResetOption() \| if v:count > 0 \| call tcomment#SetOption("count", v:count) \| endif \| let w:tcommentPos = getpos(".") \| set opfunc=TCommentOpFunc_gccg@$ Does this work when defined manually? (You might want to check if the TCommentOpFunc_gcc function exists since I'm not 100% sure.)
ruinb0w commented 1 year ago

I tried your code, but still same as before E354: Invalid register name: '$'. My vim is nvim 0.9 by the way, I'm using vim.g.tcomment_opleader1 = '<leader>c'" instead, and it works great.

Screenshot 2023-05-10 at 09 19 54 Screenshot 2023-05-10 at 09 20 36
tomtom commented 1 year ago

I don't know nvim so I cannot really help you with that.

Do you really have to escape the pipe character when using the vim.keymap.set() function? I could imagine just the bar "|" with not backslash should work. The backslash is there as a work-around for vim's :map command.