my nix dotfiles
at master 46 lines 1.8 kB view raw
1local map = vim.keymap.set 2local loaded = false 3 4local function load() 5 if loaded then return end 6 loaded = true 7 8 require('nvim-treesitter-textobjects').setup({ 9 select = { lookahead = true }, 10 move = { set_jumps = true }, 11 }) 12 13 local select = require('nvim-treesitter-textobjects.select') 14 local move = require('nvim-treesitter-textobjects.move') 15 16 map({'x', 'o'}, 'af', function() select.select_textobject('@function.outer') end) 17 map({'x', 'o'}, 'if', function() select.select_textobject('@function.inner') end) 18 map({'x', 'o'}, 'ac', function() select.select_textobject('@class.outer') end) 19 map({'x', 'o'}, 'ic', function() select.select_textobject('@class.inner') end) 20 map('n', ']m', function() move.goto_next_start('@function.outer') end) 21 map('n', ']]', function() move.goto_next_start('@class.outer') end) 22 map('n', ']M', function() move.goto_next_end('@function.outer') end) 23 map('n', '][', function() move.goto_next_end('@class.outer') end) 24 map('n', '[m', function() move.goto_previous_start('@function.outer') end) 25 map('n', '[[', function() move.goto_previous_start('@class.outer') end) 26 map('n', '[M', function() move.goto_previous_end('@function.outer') end) 27 map('n', '[]', function() move.goto_previous_end('@class.outer') end) 28end 29 30-- stub keymaps: load + re-invoke on first use 31local stubs = { 32 { {'x', 'o'}, 'af' }, { {'x', 'o'}, 'if' }, 33 { {'x', 'o'}, 'ac' }, { {'x', 'o'}, 'ic' }, 34 { 'n', ']m' }, { 'n', ']]' }, { 'n', ']M' }, { 'n', '][' }, 35 { 'n', '[m' }, { 'n', '[[' }, { 'n', '[M' }, { 'n', '[]' }, 36} 37 38for _, s in ipairs(stubs) do 39 local mode, lhs = s[1], s[2] 40 map(mode, lhs, function() 41 load() 42 vim.api.nvim_feedkeys( 43 vim.api.nvim_replace_termcodes(lhs, true, false, true), 'x', false 44 ) 45 end) 46end