12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- local MiniAi = require('mini.ai')
- local MiniAlign = require('mini.align')
- local MiniComment = require('mini.comment')
- local MiniPairs = require('mini.pairs')
- local MiniSurround = require('mini.surround')
- -- comment actions
- MiniComment.setup()
- -- keymap: overrides default vim gc / gcc
- -- surround actions
- MiniSurround.setup({
- custom_surroundings = {
- -- js template string
- ['$'] = {
- output = {
- left = '`${',
- right = '}`',
- },
- },
- },
- })
- -- keymap:
- -- sa (surround add)
- -- sr (surround replace)
- -- sd (surround delete)
- local spec_treesitter = require('mini.ai').gen_spec.treesitter
- MiniAi.setup({
- -- only consider the current location
- search_method = 'cover',
- custom_textobjects = {
- ['.'] = spec_treesitter({
- a = '@call.outer',
- i = '@call.inner',
- }),
- [','] = spec_treesitter({
- a = '@parameter.outer',
- i = '@parameter.inner',
- }),
- },
- });
- -- align actions
- MiniAlign.setup()
- -- keymap: ga / gA
- -- Treesitter-aware split/join
- require('treesj').setup({
- use_default_keymaps = false,
- })
- vim.keymap.set('n', '<Leader>s', '<cmd>TSJSplit<CR>')
- vim.keymap.set('n', '<Leader>j', '<cmd>TSJJoin<CR>')
- -- autopair brackets
- MiniPairs.setup({
- mappings = {
- -- default config includes (, [ and {
- -- autopair <> if preceded by a character, otherwise it might be a regular
- -- comparison operation
- ['<'] = { action = 'open', pair = '<>', neigh_pattern = '%w.' },
- ['>'] = { action = 'close', pair = '<>' },
- },
- })
- local function toggle_end_char(char)
- local cursor = vim.api.nvim_win_get_cursor(0)
- local row = cursor[1] - 1
- local end_char = vim.api.nvim_buf_get_text(0, row, -2, row, -1, {})[1]
- if end_char == char then
- vim.api.nvim_buf_set_text(0, row, -2, row, -1, {})
- else
- vim.api.nvim_buf_set_text(0, row, -1, row, -1, { char })
- end
- end
- -- add ,/; to end of line
- vim.keymap.set('i', '<C-,>', function() toggle_end_char(',') end)
- vim.keymap.set('i', '<C-;>', function() toggle_end_char(';') end)
|