autopairs.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. -- if not package.loaded['nvim-autopairs'] then
  2. -- return
  3. -- end
  4. local status_ok, _ = pcall(require, "nvim-autopairs")
  5. if not status_ok then
  6. return
  7. end
  8. local npairs = require "nvim-autopairs"
  9. local Rule = require "nvim-autopairs.rule"
  10. -- skip it, if you use another global object
  11. _G.MUtils = {}
  12. vim.g.completion_confirm_key = ""
  13. MUtils.completion_confirm = function()
  14. if vim.fn.pumvisible() ~= 0 then
  15. if vim.fn.complete_info()["selected"] ~= -1 then
  16. return vim.fn["compe#confirm"](npairs.esc "<cr>")
  17. else
  18. return npairs.esc "<cr>"
  19. end
  20. else
  21. return npairs.autopairs_cr()
  22. end
  23. end
  24. if package.loaded["compe"] then
  25. local map_complete_optional = vim.bo.filetype ~= "tex"
  26. require("nvim-autopairs.completion.compe").setup {
  27. map_cr = true, -- map <CR> on insert mode
  28. map_complete = map_complete_optional, -- it will auto insert `(` after select function or method item
  29. }
  30. end
  31. npairs.setup {
  32. check_ts = true,
  33. ts_config = {
  34. lua = { "string" }, -- it will not add pair on that treesitter node
  35. javascript = { "template_string" },
  36. java = false, -- don't check treesitter on java
  37. },
  38. }
  39. require("nvim-treesitter.configs").setup { autopairs = { enable = true } }
  40. local ts_conds = require "nvim-autopairs.ts-conds"
  41. -- press % => %% is only inside comment or string
  42. npairs.add_rules {
  43. Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }),
  44. Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }),
  45. }