aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Vigouroux <tomvig38@gmail.com>2021-04-18 09:57:02 +0200
committerThomas Vigouroux <tomvig38@gmail.com>2021-08-16 15:09:53 +0200
commitf2076b267ef2d53c35a964a8752eef38d7040fd5 (patch)
tree01c38bbb969910c07da22299f3dbe605d6aa9fbb
parentLua: highlight uppercase variables as constants (#1690) (diff)
downloadnvim-treesitter-f2076b267ef2d53c35a964a8752eef38d7040fd5.tar
nvim-treesitter-f2076b267ef2d53c35a964a8752eef38d7040fd5.tar.gz
nvim-treesitter-f2076b267ef2d53c35a964a8752eef38d7040fd5.tar.bz2
nvim-treesitter-f2076b267ef2d53c35a964a8752eef38d7040fd5.tar.lz
nvim-treesitter-f2076b267ef2d53c35a964a8752eef38d7040fd5.tar.xz
nvim-treesitter-f2076b267ef2d53c35a964a8752eef38d7040fd5.tar.zst
nvim-treesitter-f2076b267ef2d53c35a964a8752eef38d7040fd5.zip
feat: add support for vim
-rw-r--r--README.md1
-rw-r--r--lua/nvim-treesitter/parsers.lua9
-rw-r--r--queries/vim/highlights.scm105
-rw-r--r--queries/vim/injections.scm9
4 files changed, 124 insertions, 0 deletions
diff --git a/README.md b/README.md
index 0447711fe..8a0a51c7f 100644
--- a/README.md
+++ b/README.md
@@ -210,6 +210,7 @@ We are looking for maintainers to add more parsers and to write query files for
- [x] [turtle](https://github.com/BonaBeavis/tree-sitter-turtle) (maintained by @bonabeavis)
- [x] [typescript](https://github.com/tree-sitter/tree-sitter-typescript) (maintained by @steelsojka)
- [x] [verilog](https://github.com/tree-sitter/tree-sitter-verilog) (maintained by @zegervdv)
+- [x] [vim](https://github.com/vigoux/tree-sitter-viml) (maintained by @vigoux)
- [x] [vue](https://github.com/ikatyang/tree-sitter-vue) (maintained by @WhyNotHugo)
- [x] [yaml](https://github.com/ikatyang/tree-sitter-yaml) (maintained by @stsewd)
- [x] [yang](https://github.com/Hubro/tree-sitter-yang) (maintained by @Hubro)
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index eef3262bb..9803f241e 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -656,6 +656,15 @@ list.cmake = {
maintainers = { "@uyha" },
}
+list.vim = {
+ install_info = {
+ url = "https://github.com/vigoux/tree-sitter-viml",
+ files = { "src/parser.c", "src/scanner.c" },
+ },
+ filetype = "vim",
+ maintainers = { "@vigoux" },
+}
+
local M = {
list = list,
}
diff --git a/queries/vim/highlights.scm b/queries/vim/highlights.scm
new file mode 100644
index 000000000..e10983d4f
--- /dev/null
+++ b/queries/vim/highlights.scm
@@ -0,0 +1,105 @@
+;; Keywords
+
+[
+ "if"
+ "else"
+ "elseif"
+ "endif"
+] @conditional
+
+[
+ "try"
+ "catch"
+ "finally"
+ "endtry"
+ "throw"
+] @exception
+
+[
+ "for"
+ "endfor"
+ "in"
+ "while"
+ "endwhile"
+] @repeat
+
+[
+ "function"
+ "endfunction"
+] @keyword.function
+
+;; Function related
+(function_declaration name: (_) @function)
+(call_expression function: (identifier) @function)
+
+[ (bang) (spread) ] @punctuation.special
+
+[ (no_option) (inv_option) (default_option) (option_name) ] @variable.builtin
+[ (scope) "a:" ] @namespace
+
+(ternary_expression ["?" ":"] @conditional)
+
+;; Commands and user defined commands
+
+[
+ "let"
+ "unlet"
+ "call"
+ "execute"
+ "normal"
+ "set"
+ "silent"
+ "echo"
+ "autocmd"
+ "return"
+ "lua"
+ "ruby"
+ "perl"
+ "python"
+] @keyword
+(command_name) @function.macro
+
+(au_event) @constant
+(normal_statement (commands) @constant)
+
+;; Literals
+
+(string_literal) @string
+(integer_literal) @number
+(float_literal) @float
+(comment) @comment
+(pattern) @string.special
+
+;; Operators
+
+[
+ "||"
+ "&&"
+ "+"
+ "-"
+ "*"
+ "/"
+ "%"
+ ".."
+ "is"
+ "isnot"
+ "=="
+ "!="
+ ">"
+ ">="
+ "<"
+ "<="
+ "=~"
+ "!~"
+ "="
+ "+="
+ "-="
+ "*="
+ "/="
+ "%="
+ ".="
+] @operator
+
+; Some characters have different meanings based on the context
+(unary_operation "!" @operator)
+(binary_operation "." @operator)
diff --git a/queries/vim/injections.scm b/queries/vim/injections.scm
new file mode 100644
index 000000000..de70ef169
--- /dev/null
+++ b/queries/vim/injections.scm
@@ -0,0 +1,9 @@
+(lua_statement . (_) @lua)
+(ruby_statement . (_) @ruby)
+(python_statement . (_) @python)
+;; If we support perl at some point...
+;; (perl_statement . (_) @perl)
+
+(autocmd_statement (pattern) @regex)
+
+(comment) @comment