diff --git a/dot_config/nvim/after/plugin/treesitter.lua b/dot_config/nvim/after/plugin/treesitter.lua index a775e84..c8c7255 100644 --- a/dot_config/nvim/after/plugin/treesitter.lua +++ b/dot_config/nvim/after/plugin/treesitter.lua @@ -15,7 +15,6 @@ treesitter.setup { node_decremental = "grm" -- decrement to the previous node } }, - textobjects = { -- syntax-aware textobjects enable = true, @@ -51,35 +50,38 @@ treesitter.setup { enable = true, set_jumps = true, -- whether to set jumps in the jumplist goto_next_start = { - ["]]"] = "@function.outer" + ["]]"] = "@function.outer", + ["]c"] = { query = "@class.outer", desc = "Next class start" }, + -- + -- You can use regex matching and/or pass a list in a "query" key to group multiple queires. + ["]o"] = "@loop.*", + -- ["]o"] = { query = { "@loop.inner", "@loop.outer" } } + -- + -- You can pass a query group to use query from `queries//.scm file in your runtime path. + -- Below example nvim-treesitter's `locals.scm` and `folds.scm`. They also provide highlights.scm and indent.scm. + ["]s"] = { query = "@scope", query_group = "locals", desc = "Next scope" }, + ["]z"] = { query = "@fold", query_group = "folds", desc = "Next fold" }, }, goto_next_end = { - ["]["] = "@function.outer" + ["]["] = "@function.outer", + ["]C"] = "@class.outer", }, goto_previous_start = { - ["[["] = "@function.outer" + ["[["] = "@function.outer", + ["[c"] = "@class.outer", }, goto_previous_end = { - ["[]"] = "@function.outer" - } - }, - select = { - enable = true, - lookahead = true, - keymaps = { - -- You can use the capture groups defined in textobjects.scm - ["af"] = "@function.outer", - ["if"] = "@function.inner", - ["ac"] = "@class.outer", - ["ic"] = "@class.inner", - -- Or you can define your own textobjects like this - ["iF"] = { - python = "(function_definition) @function", - cpp = "(function_definition) @function", - c = "(function_definition) @function", - java = "(method_declaration) @function", - go = "(method_declaration) @function" - } + ["[]"] = "@function.outer", + ["[C"] = "@class.outer", + }, + -- Below will go to either the start or the end, whichever is closer. + -- Use if you want more granular movements + -- Make it even more gradual by adding multiple queries and regex. + goto_next = { + ["]d"] = "@conditional.outer", + }, + goto_previous = { + ["[d"] = "@conditional.outer", } }, swap = { diff --git a/dot_config/nvim/init.lua.tmpl b/dot_config/nvim/init.lua.tmpl index 8bb2d5c..d7867da 100644 --- a/dot_config/nvim/init.lua.tmpl +++ b/dot_config/nvim/init.lua.tmpl @@ -6,61 +6,62 @@ vim.g.maplocalleader = '\\' -- Plugins require "paq" { - "savq/paq-nvim"; + "savq/paq-nvim", - "nvim-treesitter/nvim-treesitter"; - "nvim-treesitter/nvim-treesitter-textobjects"; + "nvim-treesitter/nvim-treesitter", + "nvim-treesitter/nvim-treesitter-textobjects", -- Theming - "ellisonleao/gruvbox.nvim"; - "nvim-lualine/lualine.nvim"; - "nvim-tree/nvim-web-devicons"; - "lukas-reineke/indent-blankline.nvim"; + "ellisonleao/gruvbox.nvim", + "nvim-lualine/lualine.nvim", + "nvim-tree/nvim-web-devicons", + "lukas-reineke/indent-blankline.nvim", -- LSP support - "onsails/lspkind.nvim"; - "lukas-reineke/lsp-format.nvim"; - "neovim/nvim-lspconfig"; + "onsails/lspkind.nvim", + "lukas-reineke/lsp-format.nvim", + "neovim/nvim-lspconfig", + {{- if ne .chezmoi.os "openbsd" }} - "williamboman/mason.nvim"; - "williamboman/mason-lspconfig.nvim"; + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", {{- end }} -- Autocomplete - "hrsh7th/nvim-cmp"; - "hrsh7th/cmp-buffer"; - "hrsh7th/cmp-path"; - "saadparwaiz1/cmp_luasnip"; - "hrsh7th/cmp-nvim-lsp"; - "hrsh7th/cmp-nvim-lua"; + "hrsh7th/nvim-cmp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-nvim-lua", -- Snippets - "L3MON4D3/LuaSnip"; - "rafamadriz/friendly-snippets"; + "L3MON4D3/LuaSnip", + "rafamadriz/friendly-snippets", -- Programming support - "kylechui/nvim-surround"; - "windwp/nvim-autopairs"; - "numToStr/Comment.nvim"; - "ggandor/leap.nvim"; + "kylechui/nvim-surround", + "windwp/nvim-autopairs", + "numToStr/Comment.nvim", + "ggandor/leap.nvim", -- Fuzzy search - { "nvim-telescope/telescope-fzf-native.nvim", run = "gmake" }; - "nvim-telescope/telescope-file-browser.nvim"; - "nvim-telescope/telescope.nvim"; - "folke/trouble.nvim"; + { "nvim-telescope/telescope-fzf-native.nvim", run = "gmake" }, + "nvim-telescope/telescope-file-browser.nvim", + "nvim-telescope/telescope.nvim", + "folke/trouble.nvim", - "mfussenegger/nvim-dap"; - "theHamsta/nvim-dap-virtual-text"; - "rcarriga/nvim-dap-ui"; + "mfussenegger/nvim-dap", + "theHamsta/nvim-dap-virtual-text", + "rcarriga/nvim-dap-ui", - "norcalli/nvim-colorizer.lua"; - "lewis6991/gitsigns.nvim"; - "tpope/vim-fugitive"; - "renerocksai/telekasten.nvim"; - "renerocksai/calendar-vim"; - "nvim-lua/plenary.nvim"; - "akinsho/toggleterm.nvim"; + "norcalli/nvim-colorizer.lua", + "lewis6991/gitsigns.nvim", + "tpope/vim-fugitive", + "renerocksai/telekasten.nvim", + "renerocksai/calendar-vim", + "nvim-lua/plenary.nvim", + "akinsho/toggleterm.nvim", } @@ -80,8 +81,8 @@ require 'colorizer'.setup { filetypes = { 'css', 'javascript', - scss = { rgb_fn = true; }; - html = { mode = 'foreground'; } + scss = { rgb_fn = true, }, + html = { mode = 'foreground', } }, } @@ -114,28 +115,28 @@ require("gruvbox").setup { } -- Options -local o = vim.opt +local o = vim.opt -- basic settings -o.encoding = "utf-8" -o.backspace = "indent,eol,start" -- backspace works on every char in insert mode -o.completeopt = { 'menu', 'menuone', 'noselect' } -o.history = 1000 +o.encoding = "utf-8" +o.backspace = "indent,eol,start" -- backspace works on every char in insert mode +o.completeopt = { 'menu', 'menuone', 'noselect' } +o.history = 1000 -- o.dictionary = '/home/jan/.vim/dict/words' -- o.dictionary = '/usr/share/dict/words' -o.startofline = true -o.title = true -o.clipboard = 'unnamedplus' +o.startofline = true +o.title = true +o.clipboard = 'unnamedplus' -- Mapping waiting time -o.timeoutlen = 200 -o.ttimeoutlen = 0 +o.timeoutlen = 200 +o.ttimeoutlen = 0 -- Spellchecker -o.spell = false -o.spelllang = { 'en_us' } -o.spellfile = HOME .. '/.vim/spell/en.utf8.add' -o.thesaurus = HOME .. '/.vim/thesaurus/english.txt' +o.spell = false +o.spelllang = { 'en_us' } +o.spellfile = HOME .. '/.vim/spell/en.utf8.add' +o.thesaurus = HOME .. '/.vim/thesaurus/english.txt' -- Display o.showmatch = true -- show matching brackets @@ -150,15 +151,22 @@ o.laststatus = 2 -- always show status line o.list = false -- do not display white characters o.termguicolors = true o.background = "dark" --- o.updatetime = 100 +o.wrap = false --do not wrap lines even if very long +o.eol = false -- show if there's no eol char +o.showbreak = '↪' -- character to show when line is broken -- Folding -o.foldenable = false -o.foldlevel = 4 -- limit folding to 4 levels -o.foldmethod = 'syntax' -- use language syntax to generate folds -o.wrap = false --do not wrap lines even if very long -o.eol = false -- show if there's no eol char -o.showbreak = '↪' -- character to show when line is broken +o.foldenable = true +o.foldnestmax = 2 +o.foldminlines = 10 +o.foldmethod = "expr" +o.foldexpr = "nvim_treesitter#foldexpr()" + +-- workaround for Telescope bug +vim.api.nvim_create_autocmd({ "BufEnter" }, { + pattern = { "*" }, + command = "normal zx", +}) -- Sidebar o.number = true -- line number on the left @@ -222,7 +230,8 @@ o.backupdir = HOME .. '/.local/share/nvim/dirs/backup//' -- backups -- Commands mode o.wildmenu = true -- on TAB, complete options for system command -o.wildignore = 'deps,.svn,CVS,.git,.hg,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif,.DS_Store,*.aux,*.out,*.toc' +o.wildignore = +'deps,.svn,CVS,.git,.hg,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif,.DS_Store,*.aux,*.out,*.toc' vim.cmd([[ au BufRead,BufNewFile *.md set ft=mkd tw=80 syntax=markdown