diff --git a/nvim/.config/nvim/after/plugin/lspconfig.lua b/nvim/.config/nvim/after/plugin/lspconfig.lua deleted file mode 100644 index 75ae1d0..0000000 --- a/nvim/.config/nvim/after/plugin/lspconfig.lua +++ /dev/null @@ -1,140 +0,0 @@ --- [[ Configure LSP ]] --- This function gets run when an LSP connects to a particular buffer. -local on_attach = function(_, bufnr) - local nmap = function(keys, func, desc) - if desc then - desc = 'LSP: ' .. desc - end - - vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) - end - - nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') - nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') - - nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') - nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') - nmap('D', vim.lsp.buf.type_definition, 'Type [D]efinition') - nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') - nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') - - -- See `:help K` for why this keymap - nmap('K', vim.lsp.buf.hover, 'Hover Documentation') - nmap('K', vim.lsp.buf.signature_help, 'Signature Documentation') - - -- Lesser used LSP functionality - nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') - nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') - nmap('wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, '[W]orkspace [L]ist Folders') - - -- Create a command `:Format` local to the LSP buffer - vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) - vim.lsp.buf.format() - end, { desc = 'Format current buffer with LSP' }) -end - --- Enable the following language servers. They will automatically be installed. -local servers = { - clangd = {}, - gopls = {}, - -- pyright = {}, - rust_analyzer = {}, - tsserver = {}, - - lua_ls = { - Lua = { - workspace = { checkThirdParty = false }, - telemetry = { enable = false }, - }, - }, - - html = {}, - htmx = {}, - unocss = {}, -} - -require 'lspconfig'.html.setup { - filetypes = { "html", "templ" }, -} - -require 'lspconfig'.htmx.setup { - filetypes = { "html", "templ" }, -} - -require 'lspconfig'.unocss.setup { - filetypes = { "html", "templ" }, -} - --- Setup neovim lua configuration -require('neodev').setup() - --- nvim-cmp supports additional completion capabilities, so broadcast that to servers -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) - --- Ensure the servers above are installed -local mason_lspconfig = require 'mason-lspconfig' - -mason_lspconfig.setup { - ensure_installed = vim.tbl_keys(servers), -} - -mason_lspconfig.setup_handlers { - function(server_name) - require('lspconfig')[server_name].setup { - capabilities = capabilities, - on_attach = on_attach, - settings = servers[server_name], - } - end, -} - --- [[ Configure nvim-cmp ]] --- See `:help cmp` -local cmp = require 'cmp' -local luasnip = require 'luasnip' -require('luasnip.loaders.from_vscode').lazy_load() -luasnip.config.setup {} - -cmp.setup { - completion = { autocomplete = false }, - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert { - [''] = cmp.mapping.confirm({ select = true }), - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete {}, - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { 'i', 's' }), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { 'i', 's' }), - }, - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - }, -} diff --git a/nvim/.config/nvim/after/plugin/luasnip.lua b/nvim/.config/nvim/after/plugin/luasnip.lua deleted file mode 100644 index 2ea1b63..0000000 --- a/nvim/.config/nvim/after/plugin/luasnip.lua +++ /dev/null @@ -1,8 +0,0 @@ -local ls = require "luasnip" - -ls.config.set_config { - history = true, - updateevents = "TextChanged,TextChangedI", -} - -require("luasnip.loaders.from_lua").load({ paths = "~/.config/nvim/snippets" }) diff --git a/nvim/.config/nvim/after/plugin/telescope.lua b/nvim/.config/nvim/after/plugin/telescope.lua deleted file mode 100644 index 7015cde..0000000 --- a/nvim/.config/nvim/after/plugin/telescope.lua +++ /dev/null @@ -1,14 +0,0 @@ -local telescope = require 'telescope' - -telescope.setup({ - extensions = { - whaler = { - directories = { "/home/lupan/src" }, - oneoff_directories = { "/home/lupan/dotfiles" }, - auto_file_explorer = false, - auto_cwd = true, - } - } -}) - -telescope.load_extension("whaler") diff --git a/nvim/.config/nvim/after/plugin/treesitter.lua b/nvim/.config/nvim/after/plugin/treesitter.lua deleted file mode 100644 index f93cbbe..0000000 --- a/nvim/.config/nvim/after/plugin/treesitter.lua +++ /dev/null @@ -1,78 +0,0 @@ -local org = require('orgmode') -org.setup_ts_grammar() - -require('nvim-treesitter.configs').setup { - ensure_installed = { 'c', 'cpp', 'go', 'haskell', 'lua', 'org', 'python', 'rust', 'tsx', 'templ', 'typescript', 'vimdoc', 'vim' }, - auto_install = false, - highlight = { - enable = true, - additional_vim_regex_highlighting = { 'org' }, - }, - indent = { enable = true }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = '', - node_incremental = '', - scope_incremental = '', - node_decremental = '', - }, - }, - textobjects = { - select = { - enable = true, - lookahead = true, - keymaps = { - ['aa'] = '@parameter.outer', - ['ia'] = '@parameter.inner', - ['af'] = '@function.outer', - ['if'] = '@function.inner', - ['ac'] = '@class.outer', - ['ic'] = '@class.inner', - ['al'] = '@call.outer', - ['il'] = '@call.inner', - ['ao'] = '@loop.outer', - ['io'] = '@loop.inner', - ['ar'] = '@return.outer', - ['ir'] = '@return.inner', - ['as'] = '@statement.outer', - ['ag'] = '@assignment.outer', - ['ig'] = '@assignment.inner', - }, - }, - move = { - enable = true, - set_jumps = true, - goto_next_start = { - [']m'] = '@function.outer', - [']]'] = '@class.outer', - }, - goto_next_end = { - [']M'] = '@function.outer', - [']['] = '@class.outer', - }, - goto_previous_start = { - ['[m'] = '@function.outer', - ['[['] = '@class.outer', - }, - goto_previous_end = { - ['[M'] = '@function.outer', - ['[]'] = '@class.outer', - }, - }, - swap = { - enable = true, - swap_next = { - ['a'] = '@parameter.inner', - }, - swap_previous = { - ['A'] = '@parameter.inner', - }, - }, - }, -} - -org.setup({ - org_agenda_files = { '~/org/*.org' }, - org_default_notes_file = '~/org/capture.org', -}) diff --git a/nvim/.config/nvim/lua/lupan/autocmd.lua b/nvim/.config/nvim/lua/lupan/autocmd.lua index b279e3b..66243e0 100644 --- a/nvim/.config/nvim/lua/lupan/autocmd.lua +++ b/nvim/.config/nvim/lua/lupan/autocmd.lua @@ -1,17 +1,18 @@ -- [[ Highlight on yank ]] -- See `:help vim.highlight.on_yank()` -local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'Highlight when yanking (copying) text', + group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }), callback = function() vim.highlight.on_yank() end, - group = highlight_group, - pattern = '*', }) vim.api.nvim_create_autocmd('BufWritePre', { + desc = 'Format on saving buffer', callback = function() vim.lsp.buf.format() end, - pattern = { '*.go', '*.lua' }, + group = vim.api.nvim_create_augroup('BufWriteFormat', { clear = true }), + pattern = { '*.go', '*.lua', '*.rs' }, }) diff --git a/nvim/.config/nvim/lua/lupan/options.lua b/nvim/.config/nvim/lua/lupan/options.lua index 438f530..0de2776 100644 --- a/nvim/.config/nvim/lua/lupan/options.lua +++ b/nvim/.config/nvim/lua/lupan/options.lua @@ -1,7 +1,10 @@ -- See `:help vim.o` +vim.opt.showmode = false + -- Set highlight on search -vim.o.hlsearch = false +vim.o.hlsearch = true -- false +vim.keymap.set('n', '', 'nohlsearch') -- Make line numbers default vim.wo.number = true diff --git a/nvim/.config/nvim/lua/lupan/remap.lua b/nvim/.config/nvim/lua/lupan/remap.lua index bd5b944..53bc6a3 100644 --- a/nvim/.config/nvim/lua/lupan/remap.lua +++ b/nvim/.config/nvim/lua/lupan/remap.lua @@ -19,25 +19,7 @@ key("n", "ut", ":UndotreeToggle", { desc = "[U]undotree [t]oggle" }) -- telescope -key('n', '', 'Telescope buffers', { desc = '[ ] Find existing buffers' }) -key('n', '?', 'Telescope oldfiles', { desc = '[?] Find recently opened buffers' }) -key('n', '/', function() - require('telescope.builtin').current_buffer_fuzzy_find(require("telescope.themes").get_dropdown { previewer = false }) -end, { desc = '[/] Find in current buffer' }) - -key('n', 'gf', 'Telescope git_files', { desc = '[G]it [f]iles' }) -key('n', 'gs', 'Telescope git_status', { desc = '[G]it [s]tatus' }) key('n', 'gg', ':Git grep ', { desc = '[G]it [g]rep' }) -key('n', 'ff', 'Telescope find_files', { desc = '[F]ind [f]iles' }) -key('n', 'fg', 'Telescope live_grep', { desc = '[F]ind [g]rep' }) -key('n', 'fw', 'Telescope grep_string', { desc = '[F]ind [w]ord' }) -key('n', 'fh', 'Telescope help_tags', { desc = '[F]ind [h]elp (tags)' }) -key('n', 'fd', 'Telescope diagnostics', { desc = '[F]ind [d]iagnostics' }) -key('n', 'fk', 'Telescope keymaps', { desc = '[F]ind [k]eymaps' }) - -key('n', 'fF', function() - require('telescope.builtin').find_files { hidden = true } -end, { desc = '[F]ind [F]iles (with hidden)' }) key('n', 'td', function() require('lupan.ui').tab_change_dir() @@ -59,13 +41,11 @@ for i = 1, 9, 1 do key('n', 't' .. i, '' .. i .. 'tabnext', { desc = '[T]ab nr [' .. i .. ']' }) end -key("n", "fl", 'Telescope whaler', { desc = '[F]ind with wha[l]er' }) - -- Diagnostic keymaps -key('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) -key('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) -key('n', 'e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) -key('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' }) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' }) +vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' }) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) key('n', 'N', ':bn', { desc = '[N]ext buffer' }) key('n', 'P', ':bp', { desc = '[P]revious buffer' }) diff --git a/nvim/.config/nvim/lua/plugins/autocompletion.lua b/nvim/.config/nvim/lua/plugins/autocompletion.lua new file mode 100644 index 0000000..06cb61b --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/autocompletion.lua @@ -0,0 +1,71 @@ +return { + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + dependencies = { + -- Snippet Engine & its associated nvim-cmp source + { + 'L3MON4D3/LuaSnip', + build = (function() + if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then + return + end + return 'make install_jsregexp' + end)(), + }, + 'saadparwaiz1/cmp_luasnip', + + -- Adds LSP completion capabilities + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-path', + + -- Adds a number of user-friendly snippets + 'rafamadriz/friendly-snippets', + }, + config = function() + -- See `:help cmp` + local cmp = require 'cmp' + local luasnip = require 'luasnip' + require('luasnip.loaders.from_vscode').lazy_load() + require('luasnip.loaders.from_lua').lazy_load({ paths = '~/.config/nvim/snippets' }) + luasnip.config.setup {} + + cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + -- completion = { autocomplete = false }, + completion = { completeopt = 'menu,menuone,noinsert' }, + + -- See `:help ins-completion` + mapping = cmp.mapping.preset.insert { + -- [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping.complete {}, + + -- will move you to the right of each of the expansion locations. + -- is similar, except moving you backwards. + [''] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, { 'i', 's' }), + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + }, + } + end, +} diff --git a/nvim/.config/nvim/lua/plugins/convenience.lua b/nvim/.config/nvim/lua/plugins/convenience.lua new file mode 100644 index 0000000..3c4cf8f --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/convenience.lua @@ -0,0 +1,18 @@ +return { + { + 'folke/which-key.nvim', + event = 'VimEnter', + config = function() + require('which-key').setup() + + -- Document existing key chains + require('which-key').register { + ['c'] = { name = '[C]ode/Color', _ = 'which_key_ignore' }, + ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, + ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, + ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, + ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, + } + end, + }, +} diff --git a/nvim/.config/nvim/lua/plugins/editing.lua b/nvim/.config/nvim/lua/plugins/editing.lua index 3fc25ca..d905368 100644 --- a/nvim/.config/nvim/lua/plugins/editing.lua +++ b/nvim/.config/nvim/lua/plugins/editing.lua @@ -8,7 +8,6 @@ return { -- Undo browsing 'mbbill/undotree', - -- Tabstops autodetected 'tpope/vim-sleuth', @@ -20,7 +19,4 @@ return { require("nvim-surround").setup({}) end }, - - -- change directory with telescope from a list of dierectories - "SalOrak/whaler", } diff --git a/nvim/.config/nvim/lua/plugins/init.lua b/nvim/.config/nvim/lua/plugins/init.lua index 85713d9..15b6a76 100644 --- a/nvim/.config/nvim/lua/plugins/init.lua +++ b/nvim/.config/nvim/lua/plugins/init.lua @@ -1,63 +1,4 @@ return { - -- Fuzzy finder - { - 'nvim-telescope/telescope.nvim', - branch = '0.1.x', - dependencies = { - 'nvim-lua/plenary.nvim' }, - config = function() - pcall(require('telescope').load_extension, 'fzf') - end, - cmd = 'Telescope', - }, - - { - 'nvim-treesitter/nvim-treesitter', - dependencies = { - 'nvim-treesitter/nvim-treesitter-textobjects', - 'nvim-orgmode/orgmode', -- as configured together - 'vrischmann/tree-sitter-templ', - "nushell/tree-sitter-nu", -- additional parser - }, - build = - ':TSUpdate' - }, - - { - -- LSP Configuration & Plugins - 'neovim/nvim-lspconfig', - dependencies = { - -- Automatically install LSPs to stdpath for neovim - { 'williamboman/mason.nvim', config = true }, - 'williamboman/mason-lspconfig.nvim', - - -- Useful status updates for LSP - { 'j-hui/fidget.nvim', tag = 'legacy', opts = {} }, - - -- Additional lua configuration, makes nvim stuff amazing! - 'folke/neodev.nvim', - }, - }, - - { - -- Autocompletion - 'hrsh7th/nvim-cmp', - dependencies = { - -- Snippet Engine & its associated nvim-cmp source - 'L3MON4D3/LuaSnip', - 'saadparwaiz1/cmp_luasnip', - - -- Adds LSP completion capabilities - 'hrsh7th/cmp-nvim-lsp', - - -- Adds a number of user-friendly snippets - 'rafamadriz/friendly-snippets', - }, - }, - - -- Show pending keybinds - { 'folke/which-key.nvim', opts = {} }, - { 'ThePrimeagen/harpoon', dependencies = { 'nvim-lua/plenary.nvim' }, @@ -67,5 +8,6 @@ return { { 'crusj/hierarchy-tree-go.nvim', dependencies = 'neovim/nvim-lspconfig', + lazy = true, }, } diff --git a/nvim/.config/nvim/lua/plugins/lsp.lua b/nvim/.config/nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..05e25d8 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/lsp.lua @@ -0,0 +1,115 @@ +return { + { + 'neovim/nvim-lspconfig', + dependencies = { + -- Automatically install LSPs and related tools to stdpath for neovim + 'williamboman/mason.nvim', + 'williamboman/mason-lspconfig.nvim', + 'WhoIsSethDaniel/mason-tool-installer.nvim', + 'folke/neodev.nvim', + + -- Useful status updates for LSP. + { 'j-hui/fidget.nvim', opts = {} }, + }, + config = function() + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('my-lsp-attach', { clear = true }), + callback = function(event) + local map = function(keys, func, desc) + vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) + end + + map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + map('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') + map('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') + map('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + map('rn', vim.lsp.buf.rename, '[R]e[n]ame') + map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') + map('K', vim.lsp.buf.hover, 'Hover Documentation') + map('K', vim.lsp.buf.signature_help, 'Signature Documentation') + map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + + -- Highlight references under cursor (clear highlight when cursor moves). + local client = vim.lsp.get_client_by_id(event.data.client_id) + if client and client.server_capabilities.documentHighlightProvider then + vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { + buffer = event.buf, + callback = vim.lsp.buf.document_highlight, + }) + + vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { + buffer = event.buf, + callback = vim.lsp.buf.clear_references, + }) + end + end, + }) + + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities()) + + local servers = { + clangd = {}, + gopls = {}, + -- pyright = {}, + rust_analyzer = {}, + tsserver = {}, + + lua_ls = { + settings = { + Lua = { + runtime = { version = 'LuaJIT' }, + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + completion = { + callSnippet = 'Replace', + }, + }, + }, + }, + + html = {}, + htmx = {}, + unocss = {}, + } + + require 'lspconfig'.html.setup { + filetypes = { "html", "templ" }, + } + + require 'lspconfig'.htmx.setup { + filetypes = { "html", "templ" }, + } + + require 'lspconfig'.unocss.setup { + filetypes = { "html", "templ" }, + } + + -- Setup neovim lua configuration + require('neodev').setup() + + require('mason').setup() + + local ensure_installed = vim.tbl_keys(servers or {}) + vim.list_extend(ensure_installed, { + 'stylua', -- Used to format lua code + }) + require('mason-tool-installer').setup { ensure_installed = ensure_installed } + + require('mason-lspconfig').setup { + handlers = { + function(server_name) + local server = servers[server_name] or {} + -- This handles overriding only values explicitly passed + -- by the server configuration above. Useful when disabling + -- certain features of an LSP (for example, turning off formatting for tsserver) + server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) + require('lspconfig')[server_name].setup(server) + end, + }, + } + end, + }, +} diff --git a/nvim/.config/nvim/lua/plugins/telescope.lua b/nvim/.config/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..b5d8741 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/telescope.lua @@ -0,0 +1,94 @@ +return { + { -- Fuzzy Finder (files, lsp, etc) + 'nvim-telescope/telescope.nvim', + event = 'VimEnter', + branch = '0.1.x', + dependencies = { + 'nvim-lua/plenary.nvim', + { -- If encountering errors, see telescope-fzf-native README for install instructions + 'nvim-telescope/telescope-fzf-native.nvim', + build = 'make', + cond = function() + return vim.fn.executable 'make' == 1 + end, + }, + { 'nvim-telescope/telescope-ui-select.nvim' }, + + + -- change directory with telescope from a list of directories + { + "SalOrak/whaler", + opts = { + directories = { "/home/lupan/src" }, + oneoff_directories = { "/home/lupan/dotfiles" }, + auto_file_explorer = false, + auto_cwd = true, + } + }, + + -- Icons, requires Nerd font. + { 'nvim-tree/nvim-web-devicons' }, + }, + config = function() + local telescope = require 'telescope' + -- To list available key bindings inside given telescope picker: + -- - Insert mode: + -- - Normal mode: ? + telescope.setup { + extensions = { + ['ui-select'] = { + require('telescope.themes').get_dropdown(), + }, + whaler = { + directories = { "/home/lupan/src" }, + oneoff_directories = { "/home/lupan/dotfiles" }, + auto_file_explorer = false, + auto_cwd = true, + } + }, + } + + pcall(telescope.load_extension, 'fzf') + pcall(telescope.load_extension, 'ui-select') + pcall(telescope.load_extension, 'whaler') + + -- See `:help telescope.builtin` + local builtin = require 'telescope.builtin' + vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) + vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) + vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) + vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) + vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) + vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) + vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) + vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) + vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) + vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + vim.keymap.set('n', 'sF', function() builtin.find_files { hidden = true } end, + { desc = '[S]earch [F]iles (with hidden)' }) + vim.keymap.set('n', 'sl', function() telescope.extensions.whaler.whaler() end, + { desc = '[S]earch with wha[L]er' }) + vim.keymap.set('n', 'gf', builtin.git_files, { desc = '[G]it [F]iles' }) + vim.keymap.set('n', 'gs', builtin.git_status, { desc = '[G]it [S]tatus' }) + + vim.keymap.set('n', '/', function() + builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + winblend = 10, + previewer = false, + }) + end, { desc = '[/] Fuzzily search in current buffer' }) + + vim.keymap.set('n', 's/', function() + builtin.live_grep { + grep_open_files = true, + prompt_title = 'Live Grep in Open Files', + } + end, { desc = '[S]earch [/] in Open Files' }) + + vim.keymap.set('n', 'sn', function() + builtin.find_files { cwd = vim.fn.stdpath 'config' } + end, { desc = '[S]earch [N]eovim files' }) + end, + } + +} diff --git a/nvim/.config/nvim/lua/plugins/treesitter.lua b/nvim/.config/nvim/lua/plugins/treesitter.lua new file mode 100644 index 0000000..1da0478 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/treesitter.lua @@ -0,0 +1,94 @@ +return { + + { -- Highlight, edit, and navigate code + 'nvim-treesitter/nvim-treesitter', + dependencies = { + 'nvim-treesitter/nvim-treesitter-textobjects', + 'nvim-orgmode/orgmode', -- as configured together + 'vrischmann/tree-sitter-templ', + "nushell/tree-sitter-nu", -- additional parser + }, + build = ':TSUpdate', + config = function() + -- See `:help nvim-treesitter` + local org = require('orgmode') + org.setup_ts_grammar() + + ---@diagnostic disable-next-line: missing-fields + require('nvim-treesitter.configs').setup { + ensure_installed = { 'c', 'cpp', 'go', 'haskell', 'lua', 'org', 'python', 'rust', 'tsx', 'templ', 'typescript', 'vimdoc', 'vim' }, + auto_install = false, + highlight = { + enable = true, + additional_vim_regex_highlighting = { 'org' }, + }, + indent = { enable = true }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = '', + node_incremental = '', + scope_incremental = '', + node_decremental = '', + }, + }, + textobjects = { + select = { + enable = true, + lookahead = true, + keymaps = { + ['aa'] = '@parameter.outer', + ['ia'] = '@parameter.inner', + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@class.outer', + ['ic'] = '@class.inner', + ['al'] = '@call.outer', + ['il'] = '@call.inner', + ['ao'] = '@loop.outer', + ['io'] = '@loop.inner', + ['ar'] = '@return.outer', + ['ir'] = '@return.inner', + ['as'] = '@statement.outer', + ['ag'] = '@assignment.outer', + ['ig'] = '@assignment.inner', + }, + }, + move = { + enable = true, + set_jumps = true, + goto_next_start = { + [']m'] = '@function.outer', + [']]'] = '@class.outer', + }, + goto_next_end = { + [']M'] = '@function.outer', + [']['] = '@class.outer', + }, + goto_previous_start = { + ['[m'] = '@function.outer', + ['[['] = '@class.outer', + }, + goto_previous_end = { + ['[M'] = '@function.outer', + ['[]'] = '@class.outer', + }, + }, + swap = { + enable = true, + swap_next = { + ['a'] = '@parameter.inner', + }, + swap_previous = { + ['A'] = '@parameter.inner', + }, + }, + }, + } + org.setup({ + org_agenda_files = { '~/org/*.org' }, + org_default_notes_file = '~/org/capture.org', + }) + end, + } +}