## 事象
[[undo-glow.nvim]]でコメントアウト系のkeymapを設定しても、コメントアウトした箇所にアニメーションが発生しない。コメントアウトには[[Comment.nvim]]を使っている。
`nvim/lua/plugins/undo-glow.lua`
```lua
return {
-- 中略
keys = {
-- 中略
{
"gc",
function()
-- This is an implementation to preserve the cursor position
local pos = vim.fn.getpos(".")
vim.schedule(function()
vim.fn.setpos(".", pos)
end)
return require("undo-glow").comment()
end,
mode = { "n", "x" },
desc = "Toggle comment with highlight",
expr = true,
noremap = true,
},
{
"gc",
function()
require("undo-glow").comment_textobject()
end,
mode = "o",
desc = "Comment textobject with highlight",
noremap = true,
},
{
"gcc",
function()
return require("undo-glow").comment_line()
end,
mode = "n",
desc = "Toggle comment line with highlight",
expr = true,
noremap = true,
},
},
init = function()
vim.api.nvim_create_autocmd("TextYankPost", {
desc = "Highlight when yanking (copying) text",
callback = function()
if vim.v.event.operator == "y" then
require("undo-glow").yank()
end
end,
})
end,
}
```
`nvim/lua/plugins/comment.lua`
```lua
return {
"numToStr/Comment.nvim",
cond = true,
event = { "BufNewFile", "BufRead" },
config = function()
require("Comment").setup({
toggler = {
block = "g<f20>", -- 実質未割り当て
},
})
require("Comment.ft").set("markdown", "> %s")
end,
}
```
### 環境
| 対象 | バージョン |
| ------------------ | --------- |
| [[macOS]] | 15.7.3 |
| [[Neovim]] | 0.11.5 |
| [[undo-glow.nvim]] | `25314a9` |
| [[Comment.nvim]] | `e30b7f2` |
## 原因
不明。ただ、[[Comment.nvim]]を経由すると[[undo-glow.nvim]]が動いてなさそうに見える。
## 解決方法
[[Comment.nvim]]の利用をやめる。[[Vue]]などの対応には[[nvim-ts-context-commentstring]]を使う。
[[nvim-ts-context-commentstring]]は元々、[[Comment.nvim]]のように別プラグインが必要だった(はず?)が、v0.10からはNativeのコメントアウトロジックが使えるため不要となっている。
`nvim/lua/plugins/nvim-ts-context-commentstring.lua`
```lua
return {
"JoosepAlviste/nvim-ts-context-commentstring",
event = { "LspAttach" },
config = function()
require("ts_context_commentstring").setup({
enable_autocmd = false,
})
-- ここの設定がポイント
local get_option = vim.filetype.get_option
vim.filetype.get_option = function(filetype, option)
return option == "commentstring" and require("ts_context_commentstring.internal").calculate_commentstring()
or get_option(filetype, option)
end
end,
}
```
> [Integrations · JoosepAlviste/nvim-ts-context-commentstring Wiki](https://github.com/JoosepAlviste/nvim-ts-context-commentstring/wiki/Integrations#native-commenting-in-neovim-010)