视频与目录
项目值教程目录https://blog.csdn.net/lxyoucan/article/details/120641546视频全屏https://www.bilibili.com/video/BV1Vr4y117uy/视频
17_[nvim0.5+从0单排]_注释插件
插件
17注释插件
以下两个插件配合完成。 https://github.com/b3nj5m1n/kommentary https://github.com/JoosepAlviste/nvim-ts-context-commentstring
插件安装这里以packer为例,packer插件管理器安装方法: 修改~/.config/nvim/lua/plugins.lua
文件,并增加如下内容:
--注释插件
use "b3nj5m1n/kommentary"
--jsx注释
use "JoosepAlviste/nvim-ts-context-commentstring"
:wq
退出重新打开nvim后,执行:PackerInstall
安装。
~/.config/nvim/after/plugin/kommentary.lua
内容如下:
--插件名kommentary
--项目主页https://github.com/b3nj5m1n/kommentary
require("kommentary.config").configure_language(
"typescriptreact",
{
single_line_comment_string = "auto",
multi_line_comment_strings = "auto",
hook_function = function()
require("ts_context_commentstring.internal").update_commentstring()
end
}
)
nvim-ts-context-commentstring插件依赖nvim-treesitter,配置文件如下:
~/.config/nvim/after/plugin/nvim-treesitter.lua
关键内容:
treesitter.setup {
context_commentstring = {
enable = true,
enable_autocmd = false,
context_commentstring = {
enable = true,
config = {
javascript = {
__default = "// %s",
jsx_element = "{/* %s */}",
jsx_fragment = "{/* %s */}",
jsx_attribute = "// %s",
comment = "// %s"
}
}
}
}
}
全部内容:
local status, treesitter = pcall(require, "nvim-treesitter.configs")
if (not status) then
return
end
treesitter.setup {
highlight = {
enable = true,
disable = {}
},
indent = {
enable = false,
disable = {}
},
ensure_installed = {
"tsx",
"toml",
"fish",
"php",
"json",
"yaml",
"swift",
"html",
"scss"
},
context_commentstring = {
enable = true,
enable_autocmd = false,
context_commentstring = {
enable = true,
config = {
javascript = {
__default = "// %s",
jsx_element = "{/* %s */}",
jsx_fragment = "{/* %s */}",
jsx_attribute = "// %s",
comment = "// %s"
}
}
}
}
}
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.tsx.used_by = {"javascript", "typescript.tsx"}