init.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. -- require('nvim-autopairs').setup()
  2. -- local npairs = require('nvim-autopairs')
  3. -- local function imap(lhs, rhs, opts)
  4. -- local options = {noremap = false}
  5. -- if opts then options = vim.tbl_extend('force', options, opts) end
  6. -- vim.api.nvim_set_keymap('i', lhs, rhs, options)
  7. -- end
  8. -- _G.MUtils = {}
  9. -- -- TEST
  10. -- vim.g.completion_confirm_key = ""
  11. -- MUtils.completion_confirm = function()
  12. -- if vim.fn.pumvisible() ~= 0 then
  13. -- if vim.fn.complete_info()["selected"] ~= -1 then
  14. -- vim.fn["compe#confirm"]()
  15. -- -- return npairs.esc("<c-y>")
  16. -- return npairs.esc("")
  17. -- else
  18. -- vim.defer_fn(function()
  19. -- vim.fn["compe#confirm"]("<cr>")
  20. -- end, 20)
  21. -- return npairs.esc("<c-n>")
  22. -- end
  23. -- else
  24. -- return npairs.check_break_line_char()
  25. -- end
  26. -- end
  27. -- -- TEST
  28. -- MUtils.completion_confirm = function()
  29. -- if vim.fn.pumvisible() ~= 0 then
  30. -- if vim.fn.complete_info()["selected"] ~= -1 then
  31. -- vim.fn["compe#confirm"]()
  32. -- return npairs.esc("")
  33. -- else
  34. -- vim.api.nvim_select_popupmenu_item(0, false, false, {})
  35. -- vim.fn["compe#confirm"]()
  36. -- return npairs.esc("<c-n>")
  37. -- end
  38. -- else
  39. -- return npairs.check_break_line_char()
  40. -- end
  41. -- end
  42. -- MUtils.tab = function()
  43. -- if vim.fn.pumvisible() ~= 0 then
  44. -- return npairs.esc("<C-n>")
  45. -- else
  46. -- if vim.fn["vsnip#available"](1) ~= 0 then
  47. -- vim.fn.feedkeys(string.format('%c%c%c(vsnip-expand-or-jump)', 0x80, 253, 83))
  48. -- return npairs.esc("")
  49. -- else
  50. -- return npairs.esc("<Tab>")
  51. -- end
  52. -- end
  53. -- end
  54. -- MUtils.s_tab = function()
  55. -- if vim.fn.pumvisible() ~= 0 then
  56. -- return npairs.esc("<C-p>")
  57. -- else
  58. -- if vim.fn["vsnip#jumpable"](-1) ~= 0 then
  59. -- vim.fn.feedkeys(string.format('%c%c%c(vsnip-jump-prev)', 0x80, 253, 83))
  60. -- return npairs.esc("")
  61. -- else
  62. -- return npairs.esc("<C-h>")
  63. -- end
  64. -- end
  65. -- end
  66. -- -- Autocompletion and snippets
  67. -- vim.api.nvim_set_keymap('i', '<CR>', 'v:lua.MUtils.completion_confirm()', {expr = true, noremap = true})
  68. -- -- imap("<CR>", "v:lua.MUtils.completion_confirm()", {expr = true, noremap = true})
  69. -- imap("<Tab>", "v:lua.MUtils.tab()", {expr = true, noremap = true})
  70. -- imap("<S-Tab>", "v:lua.MUtils.s_tab()", {expr = true, noremap = true})
  71. local remap = vim.api.nvim_set_keymap
  72. local npairs = require('nvim-autopairs')
  73. local Rule = require('nvim-autopairs.rule')
  74. -- skip it, if you use another global object
  75. _G.MUtils= {}
  76. vim.g.completion_confirm_key = ""
  77. MUtils.completion_confirm=function()
  78. if vim.fn.pumvisible() ~= 0 then
  79. if vim.fn.complete_info()["selected"] ~= -1 then
  80. return vim.fn["compe#confirm"](npairs.esc("<cr>"))
  81. else
  82. return npairs.esc("<cr>")
  83. end
  84. else
  85. return npairs.autopairs_cr()
  86. end
  87. end
  88. remap('i' , '<CR>','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true})
  89. npairs.setup({
  90. check_ts = true,
  91. ts_config = {
  92. lua = {'string'},-- it will not add pair on that treesitter node
  93. javascript = {'template_string'},
  94. java = false,-- don't check treesitter on java
  95. }
  96. })
  97. require('nvim-treesitter.configs').setup {
  98. autopairs = {enable = true}
  99. }
  100. local ts_conds = require('nvim-autopairs.ts-conds')
  101. -- press % => %% is only inside comment or string
  102. npairs.add_rules({
  103. Rule("%", "%", "lua")
  104. :with_pair(ts_conds.is_ts_node({'string','comment'})),
  105. Rule("$", "$", "lua")
  106. :with_pair(ts_conds.is_not_ts_node({'function'}))
  107. })