init.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. -- require('nvim-autopairs').setup()
  2. --
  3. -- local pairs_map = {
  4. -- ["'"] = "'",
  5. -- ['"'] = '"',
  6. -- ['('] = ')',
  7. -- ['['] = ']',
  8. -- ['{'] = '}',
  9. -- ['`'] = '`',
  10. -- ['```'] = '```',
  11. -- }
  12. -- local disable_filetype = { "TelescopePrompt" }
  13. -- local break_line_filetype = nil -- mean all file type
  14. -- local html_break_line_filetype = {'html' , 'vue' , 'typescriptreact' , 'svelte' , 'javascriptreact'}
  15. -- local ignored_next_char = "%w"
  16. --
  17. -- local remap = vim.api.nvim_set_keymap
  18. -- local npairs = require('nvim-autopairs')
  19. --
  20. -- -- skip it, if you use another global object
  21. -- _G.MUtils= {}
  22. --
  23. -- vim.g.completion_confirm_key = ""
  24. -- MUtils.completion_confirm=function()
  25. -- if vim.fn.pumvisible() ~= 0 then
  26. -- if vim.fn.complete_info()["selected"] ~= -1 then
  27. -- vim.fn["compe#confirm"]()
  28. -- return npairs.esc("<c-y>")
  29. -- else
  30. -- vim.defer_fn(function()
  31. -- vim.fn["compe#confirm"]("<cr>")
  32. -- end, 20)
  33. -- return npairs.esc("<c-n>")
  34. -- end
  35. -- else
  36. -- return npairs.check_break_line_char()
  37. -- end
  38. -- end
  39. --
  40. --
  41. -- remap('i' , '<CR>','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true})
  42. -- TODO switch to lua plugin when possible
  43. -- vim.cmd([[
  44. -- let g:lexima_no_default_rules = v:true
  45. -- call lexima#set_default_rules()
  46. -- inoremap <silent><expr> <C-Space> compe#complete()
  47. -- inoremap <silent><expr> <CR> compe#confirm(lexima#expand('<LT>CR>', 'i'))
  48. -- inoremap <silent><expr> <C-e> compe#close('<C-e>')
  49. -- inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })
  50. -- inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })
  51. -- ]])
  52. require('nvim-autopairs').setup()
  53. local npairs = require('nvim-autopairs')
  54. local function imap(lhs, rhs, opts)
  55. local options = {noremap = false}
  56. if opts then options = vim.tbl_extend('force', options, opts) end
  57. vim.api.nvim_set_keymap('i', lhs, rhs, options)
  58. end
  59. _G.MUtils = {}
  60. MUtils.completion_confirm = function()
  61. if vim.fn.pumvisible() ~= 0 then
  62. if vim.fn.complete_info()["selected"] ~= -1 then
  63. vim.fn["compe#confirm"]()
  64. return npairs.esc("")
  65. else
  66. vim.fn.nvim_select_popupmenu_item(0, false, false, {})
  67. vim.fn["compe#confirm"]()
  68. return npairs.esc("<c-n>")
  69. end
  70. else
  71. return npairs.check_break_line_char()
  72. end
  73. end
  74. MUtils.tab=function()
  75. if vim.fn.pumvisible() ~= 0 then
  76. return npairs.esc("<C-n>")
  77. else
  78. if vim.fn["vsnip#available"](1) ~= 0 then
  79. vim.fn.feedkeys(string.format('%c%c%c(vsnip-expand-or-jump)', 0x80, 253, 83))
  80. return npairs.esc("")
  81. else
  82. return npairs.esc("<Tab>")
  83. end
  84. end
  85. end
  86. MUtils.s_tab=function()
  87. if vim.fn.pumvisible() ~= 0 then
  88. return npairs.esc("<C-p>")
  89. else
  90. if vim.fn["vsnip#jumpable"](-1) ~= 0 then
  91. vim.fn.feedkeys(string.format('%c%c%c(vsnip-jump-prev)', 0x80, 253, 83))
  92. return npairs.esc("")
  93. else
  94. return npairs.esc("<C-h>")
  95. end
  96. end
  97. end
  98. -- Autocompletion and snippets
  99. imap("<CR>", "v:lua.MUtils.completion_confirm()", {expr = true, noremap = true})
  100. imap("<Tab>", "v:lua.MUtils.tab()", {expr = true, noremap = true})
  101. imap("<S-Tab>", "v:lua.MUtils.s_tab()", {expr = true, noremap = true})