summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/_autopairs/init.lua
diff options
context:
space:
mode:
authoraktersnurra <grydholm@kth.se>2021-04-19 21:43:23 +0200
committeraktersnurra <grydholm@kth.se>2021-04-19 21:43:23 +0200
commit23b895222a16925d39d04d45dedbedec9db0c752 (patch)
treeeb5759eed884c1ddcb32f1b702e55dc4521bf60e /.config/nvim/lua/_autopairs/init.lua
parent174cd547dc32bb6d50ab5da329ad1bc4d516c20a (diff)
Updates to nvim
Diffstat (limited to '.config/nvim/lua/_autopairs/init.lua')
-rw-r--r--.config/nvim/lua/_autopairs/init.lua97
1 files changed, 67 insertions, 30 deletions
diff --git a/.config/nvim/lua/_autopairs/init.lua b/.config/nvim/lua/_autopairs/init.lua
index 6810a77..5d0adf8 100644
--- a/.config/nvim/lua/_autopairs/init.lua
+++ b/.config/nvim/lua/_autopairs/init.lua
@@ -1,40 +1,77 @@
require('nvim-autopairs').setup()
-
-local pairs_map = {
- ["'"] = "'",
- ['"'] = '"',
- ['('] = ')',
- ['['] = ']',
- ['{'] = '}',
- ['`'] = '`',
-}
-local disable_filetype = { "TelescopePrompt" }
-local break_line_filetype = nil -- mean all file type
-local html_break_line_filetype = {'html' , 'vue' , 'typescriptreact' , 'svelte' , 'javascriptreact'}
-local ignored_next_char = "%w"
-
-local remap = vim.api.nvim_set_keymap
local npairs = require('nvim-autopairs')
--- skip it, if you use another global object
-_G.MUtils= {}
+local function imap(lhs, rhs, opts)
+ local options = {noremap = false}
+ if opts then options = vim.tbl_extend('force', options, opts) end
+ vim.api.nvim_set_keymap('i', lhs, rhs, options)
+end
+
+_G.MUtils = {}
+-- TEST
vim.g.completion_confirm_key = ""
-MUtils.completion_confirm=function()
- if vim.fn.pumvisible() ~= 0 then
- if vim.fn.complete_info()["selected"] ~= -1 then
- vim.fn["compe#confirm"]()
- return npairs.esc("<c-y>")
+MUtils.completion_confirm = function()
+ if vim.fn.pumvisible() ~= 0 then
+ if vim.fn.complete_info()["selected"] ~= -1 then
+ vim.fn["compe#confirm"]()
+ -- return npairs.esc("<c-y>")
+ return npairs.esc("")
+ else
+ vim.defer_fn(function()
+ vim.fn["compe#confirm"]("<cr>")
+ end, 20)
+ return npairs.esc("<c-n>")
+ end
+ else
+ return npairs.check_break_line_char()
+ end
+end
+-- TEST
+
+MUtils.completion_confirm = function()
+ if vim.fn.pumvisible() ~= 0 then
+ if vim.fn.complete_info()["selected"] ~= -1 then
+ vim.fn["compe#confirm"]()
+ return npairs.esc("")
+ else
+ vim.api.nvim_select_popupmenu_item(0, false, false, {})
+ vim.fn["compe#confirm"]()
+ return npairs.esc("<c-n>")
+ end
else
- vim.defer_fn(function()
- vim.fn["compe#confirm"]("<cr>")
- end, 20)
- return npairs.esc("<c-n>")
+ return npairs.check_break_line_char()
end
- else
- return npairs.check_break_line_char()
- end
end
+MUtils.tab = function()
+ if vim.fn.pumvisible() ~= 0 then
+ return npairs.esc("<C-n>")
+ else
+ if vim.fn["vsnip#available"](1) ~= 0 then
+ vim.fn.feedkeys(string.format('%c%c%c(vsnip-expand-or-jump)', 0x80, 253, 83))
+ return npairs.esc("")
+ else
+ return npairs.esc("<Tab>")
+ end
+ end
+end
+
+MUtils.s_tab = function()
+ if vim.fn.pumvisible() ~= 0 then
+ return npairs.esc("<C-p>")
+ else
+ if vim.fn["vsnip#jumpable"](-1) ~= 0 then
+ vim.fn.feedkeys(string.format('%c%c%c(vsnip-jump-prev)', 0x80, 253, 83))
+ return npairs.esc("")
+ else
+ return npairs.esc("<C-h>")
+ end
+ end
+end
-remap('i' , '<CR>','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true})
+-- Autocompletion and snippets
+vim.api.nvim_set_keymap('i', '<CR>', 'v:lua.MUtils.completion_confirm()', {expr = true, noremap = true})
+-- imap("<CR>", "v:lua.MUtils.completion_confirm()", {expr = true, noremap = true})
+imap("<Tab>", "v:lua.MUtils.tab()", {expr = true, noremap = true})
+imap("<S-Tab>", "v:lua.MUtils.s_tab()", {expr = true, noremap = true})