diff --git a/init.lua b/init.lua index e740a94..ff1e2e2 100644 --- a/init.lua +++ b/init.lua @@ -6,3 +6,4 @@ require "user.cmp" require "user.lsp" require "user.telescope" require "user.treesitter" +require "user.autopairs" diff --git a/lua/user/autopairs.lua b/lua/user/autopairs.lua new file mode 100644 index 0000000..577e571 --- /dev/null +++ b/lua/user/autopairs.lua @@ -0,0 +1,33 @@ +-- Setup nvim-cmp. +local status_ok, npairs = pcall(require, "nvim-autopairs") +if not status_ok then + return +end + +npairs.setup { + check_ts = true, + ts_config = { + lua = { "string", "source" }, + javascript = { "string", "template_string" }, + java = false, + }, + disable_filetype = { "TelescopePrompt", "spectre_panel" }, + fast_wrap = { + map = "", + chars = { "{", "[", "(", '"', "'" }, + pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""), + offset = 0, -- Offset from pattern match + end_key = "$", + keys = "qwertyuiopzxcvbnmasdfghjkl", + check_comma = true, + highlight = "PmenuSel", + highlight_grey = "LineNr", + }, +} + +local cmp_autopairs = require "nvim-autopairs.completion.cmp" +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end +cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done { map_char = { tex = "" } }) diff --git a/lua/user/plugins.lua b/lua/user/plugins.lua index af7dfb1..74fcb73 100644 --- a/lua/user/plugins.lua +++ b/lua/user/plugins.lua @@ -44,6 +44,7 @@ return packer.startup(function(use) use "wbthomason/packer.nvim" -- Have packer manage itself use "nvim-lua/popup.nvim" -- An implementation of the Popup API from vim in Neovim use "nvim-lua/plenary.nvim" -- Useful lua functions used ny lots of plugins + use "windwp/nvim-autopairs" -- Autopairs, integrates with both cmp and treesitter -- Colorschemes -- use "lunarvim/colorschemes" -- A bunch of colorschemes you can try out diff --git a/lua/user/treesitter.lua b/lua/user/treesitter.lua index f00cc2d..b5754d6 100644 --- a/lua/user/treesitter.lua +++ b/lua/user/treesitter.lua @@ -7,6 +7,9 @@ configs.setup { ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages sync_install = false, -- install languages synchronously (only applied to `ensure_installed`) ignore_install = { "" }, -- List of parsers to ignore installing + autopairs = { + enable = true, + }, highlight = { enable = true, -- false will disable the whole extension disable = { "" }, -- list of language that will be disabled