init.lua 1.3 KB

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