15_[nvim0.5+从0单排]_通用高性能语法高亮插件nvim-treesitter

视频与目录

项目
教程目录 https://blog.csdn.net/lxyoucan/article/details/120641546
视频全屏 https://www.bilibili.com/video/BV1Gv411u7d7/
视频

15通用高性能语法高亮插件nvim-treesitter

15_[nvim0.5+从0单排]_通用高性能语法高亮插件nvim-treesitter

安装插件

这里以packer为例,packer插件管理器安装方法:
修改~/.config/nvim/lua/plugins.lua文件,并增加如下内容:

--语法高亮
  use {
    
    
        'nvim-treesitter/nvim-treesitter',
        run = ':TSUpdate'
    }

:wq退出重新打开nvim后,执行:PackerInstall 安装。

如果初次安装没downloading完就退出了,下次进入nvim 可以执行:TSUpdate进行下载。

配置

新增配置文件如下:

~/.config/nvim/after/plugin/nvim-treesitter.lua

配置文件内容如下:

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"
  }
}

local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.tsx.used_by = {
    
    "javascript", "typescript.tsx"}

使用

Treesitter使用不同的解析器用于每一种语言。

:TSInstall <language_to_install>

您还可以使用 获取所有可用语言及其安装状态的列表:TSInstallInfo

相关链接

https://github.com/nvim-treesitter/nvim-treesitter

猜你喜欢

转载自blog.csdn.net/lxyoucan/article/details/120952945