Created
November 7, 2021 18:02
-
-
Save AlixShahid/5f4687f841c300473eaf733a00ae6413 to your computer and use it in GitHub Desktop.
Medium-Setting Up Neovim for Web Development - 15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require('nvim-autopairs').setup({ | |
| enable_check_bracket_line = true, -- Don't add pairs if it already have a close pairs in same line | |
| disable_filetype = { "TelescopePrompt" , "vim" }, -- | |
| enable_afterquote = false, -- add bracket pairs after quote | |
| enable_moveright = true | |
| }) | |
| -- If you want insert `(` after select function or method item | |
| local cmp_autopairs = require('nvim-autopairs.completion.cmp') | |
| local cmp = require('cmp') | |
| cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done()) | |
| local Rule = require('nvim-autopairs.rule') | |
| local npairs = require('nvim-autopairs') | |
| npairs.add_rules { | |
| -- before insert after | |
| -- (|) ( |) ( | ) | |
| Rule(' ', ' ') | |
| :with_pair(function (opts) | |
| local pair = opts.line:sub(opts.col - 1, opts.col) | |
| return vim.tbl_contains({ '()', '[]', '{}' }, pair) | |
| end), | |
| Rule('( ', ' )') | |
| :with_pair(function() return false end) | |
| :with_move(function(opts) | |
| return opts.prev_char:match('.%)') ~= nil | |
| end) | |
| :use_key(')'), | |
| Rule('{ ', ' }') | |
| :with_pair(function() return false end) | |
| :with_move(function(opts) | |
| return opts.prev_char:match('.%}') ~= nil | |
| end) | |
| :use_key('}'), | |
| Rule('[ ', ' ]') | |
| :with_pair(function() return false end) | |
| :with_move(function(opts) | |
| return opts.prev_char:match('.%]') ~= nil | |
| end) | |
| :use_key(']'), | |
| --[===[ | |
| arrow key on javascript | |
| Before Insert After | |
| (item)= > (item)=> { } | |
| --]===] | |
| Rule('%(.*%)%s*%=>$', ' { }', { 'typescript', 'typescriptreact', 'javascript' }) | |
| :use_regex(true) | |
| :set_end_pair_length(2), | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://xlwe.medium.com/setting-up-neovim-for-web-development-70c57c3d7d61