diff --git a/.github/workflows/stylua.yml b/.github/workflows/stylua.yml index 5ec9dab..75db6c3 100644 --- a/.github/workflows/stylua.yml +++ b/.github/workflows/stylua.yml @@ -4,6 +4,7 @@ on: pull_request_target jobs: stylua-check: + if: github.repository == 'nvim-lua/kickstart.nvim' name: Stylua Check runs-on: ubuntu-latest steps: diff --git a/.gitignore b/.gitignore index ea93eda..005b535 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ tags test.sh .luarc.json nvim + +spell/ lazy-lock.json diff --git a/lua/cmp-setup.lua b/lua/cmp-setup.lua index 3ccd00c..184a599 100644 --- a/lua/cmp-setup.lua +++ b/lua/cmp-setup.lua @@ -11,15 +11,32 @@ cmp.setup { luasnip.lsp_expand(args.body) end, }, - completion = { - completeopt = 'menu,menuone,noinsert', - }, + completion = { completeopt = 'menu,menuone,noinsert' }, + + -- For an understanding of why these mappings were + -- chosen, you will need to read `:help ins-completion` + -- + -- No, but seriously. Please read `:help ins-completion`, it is really good! mapping = cmp.mapping.preset.insert { + -- Select the [n]ext item [''] = cmp.mapping.select_next_item(), + -- Select the [p]revious item [''] = cmp.mapping.select_prev_item(), + + -- Accept ([y]es) the completion. + -- This will auto-import if your LSP supports it. + -- This will expand snippets if the LSP sent a snippet. + [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), + + + -- Manually trigger a completion from nvim-cmp. + -- Generally you don't need this, because nvim-cmp will display + -- completions whenever it has completion options available. [''] = cmp.mapping.complete {}, + [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, @@ -42,6 +59,25 @@ cmp.setup { fallback() end end, { 'i', 's' }), + + -- Think of as moving to the right of your snippet expansion. + -- So if you have a snippet that's like: + -- function $name($args) + -- $body + -- end + -- + -- 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' }, diff --git a/lua/keymaps.lua b/lua/keymaps.lua index f821e65..78361e3 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -14,15 +14,30 @@ vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnos vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) --- [[ Highlight on yank ]] --- See `:help vim.highlight.on_yank()` -local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) +-- Disable arrow keys in normal mode +vim.keymap.set('n', '', 'echo "Use h to move!!"') +vim.keymap.set('n', '', 'echo "Use l to move!!"') +vim.keymap.set('n', '', 'echo "Use k to move!!"') +vim.keymap.set('n', '', 'echo "Use j to move!!"') + +-- Keybinds to make split navigation easier. +-- Use CTRL+ to switch between windows +-- +-- See `:help wincmd` for a list of all window commands +vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }) +vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) +vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) +vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) + +-- Highlight when yanking (copying) text +-- Try it with `yap` in normal mode +-- See `:help vim.highlight.on_yank()` vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'Highlight when yanking (copying) text', + group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), callback = function() vim.highlight.on_yank() end, - group = highlight_group, - pattern = '*', }) -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/kickstart/health.lua b/lua/kickstart/health.lua new file mode 100644 index 0000000..957204e --- /dev/null +++ b/lua/kickstart/health.lua @@ -0,0 +1,51 @@ +--[[ +-- +-- This file is not required for your own configuration, +-- but helps people determine if their system is setup correctly. +-- +--]] + +local check_version = function() + if not vim.version.cmp then + vim.health.error(string.format("Neovim out of date: '%s'. Upgrade to latest stable or nightly", tostring(vim.version()))) + return + end + + if vim.version.cmp(vim.version(), { 0, 9, 4 }) >= 0 then + vim.health.ok(string.format("Neovim version is: '%s'", tostring(vim.version()))) + else + vim.health.error(string.format("Neovim out of date: '%s'. Upgrade to latest stable or nightly", tostring(vim.version()))) + end +end + +local check_external_reqs = function() + -- Basic utils: `git`, `make`, `unzip` + for _, exe in ipairs { 'git', 'make', 'unzip', 'rg' } do + local is_executable = vim.fn.executable(exe) == 1 + if is_executable then + vim.health.ok(string.format("Found executable: '%s'", exe)) + else + vim.health.warn(string.format("Could not find executable: '%s'", exe)) + end + end + + return true +end + +return { + check = function() + vim.health.start 'kickstart.nvim' + + vim.health.info [[NOTE: Not every warning is a 'must-fix' in `:checkhealth` + + Fix only warnings for plugins and languages you intend to use. + Mason will give warnings for languages that are not installed. + You do not need to install, unless you want to use those languages!]] + + local uv = vim.uv or vim.loop + vim.health.info('System Information: ' .. vim.inspect(uv.os_uname())) + + check_version() + check_external_reqs() + end, +} diff --git a/lua/kickstart/plugins/autoformat.lua b/lua/kickstart/plugins/autoformat.lua deleted file mode 100644 index b18af36..0000000 --- a/lua/kickstart/plugins/autoformat.lua +++ /dev/null @@ -1,59 +0,0 @@ --- Uses installed LSP servers to automatically format code on save. - -return { - 'neovim/nvim-lspconfig', - config = function() - -- Switch for controlling whether you want autoformatting. - local format_is_enabled = true - vim.api.nvim_create_user_command('KickstartFormatToggle', function() - format_is_enabled = not format_is_enabled - print('Setting autoformatting to: ' .. tostring(format_is_enabled)) - end, {}) - - -- Create an augroup that is used for managing our formatting autocmds. - local _augroups = {} - local get_augroup = function(client) - if not _augroups[client.id] then - local group_name = 'kickstart-lsp-format-' .. client.name - local id = vim.api.nvim_create_augroup(group_name, { clear = true }) - _augroups[client.id] = id - end - - return _augroups[client.id] - end - - -- Whenever an LSP attaches to a buffer, we will run this function. - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-attach-format', { clear = true }), - -- This is where we attach the autoformatting for reasonable clients - callback = function(args) - local client_id = args.data.client_id - local client = vim.lsp.get_client_by_id(client_id) - local bufnr = args.buf - - -- Only attach to clients that support document formatting - if not client.server_capabilities.documentFormattingProvider then - return - end - - -- Create an autocmd that will run *before* we save the buffer. - vim.api.nvim_create_autocmd('BufWritePre', { - group = get_augroup(client), - buffer = bufnr, - callback = function() - if not format_is_enabled then - return - end - - vim.lsp.buf.format { - async = false, - filter = function(c) - return c.id == client.id - end, - } - end, - }) - end, - }) - end, -} diff --git a/lua/kickstart/plugins/indent_line.lua b/lua/kickstart/plugins/indent_line.lua new file mode 100644 index 0000000..ed7f269 --- /dev/null +++ b/lua/kickstart/plugins/indent_line.lua @@ -0,0 +1,9 @@ +return { + { -- Add indentation guides even on blank lines + 'lukas-reineke/indent-blankline.nvim', + -- Enable `lukas-reineke/indent-blankline.nvim` + -- See `:help ibl` + main = 'ibl', + opts = {}, + }, +} diff --git a/lua/lazy-bootstrap.lua b/lua/lazy-bootstrap.lua index f75c630..61bc85c 100644 --- a/lua/lazy-bootstrap.lua +++ b/lua/lazy-bootstrap.lua @@ -3,15 +3,16 @@ -- `:help lazy.nvim.txt` for more info local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' if not vim.loop.fs_stat(lazypath) then + local lazyrepo = 'https://github.com/folke/lazy.nvim.git' vim.fn.system { 'git', 'clone', '--filter=blob:none', - 'https://github.com/folke/lazy.nvim.git', - '--branch=stable', -- latest stable release - lazypath, + '--branch=stable', + lazyrepo, + lazypath } -end +end ---@diagnostic disable-next-line: undefined-field vim.opt.rtp:prepend(lazypath) -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/lazy-plugins.lua b/lua/lazy-plugins.lua index a1a4f7f..afb6cf3 100644 --- a/lua/lazy-plugins.lua +++ b/lua/lazy-plugins.lua @@ -1,9 +1,14 @@ --- [[ Configure plugins ]] --- NOTE: Here is where you install your plugins. --- You can configure plugins using the `config` key. +-- [[ Configure and install plugins ]] -- --- You can also configure plugins after the setup call, --- as they will be available in your neovim runtime. +-- To check the current status of your plugins, run +-- :Lazy +-- +-- You can press `?` in this menu for help. Use `:q` to close the window +-- +-- To update plugins, you can run +-- :Lazy update +-- +-- NOTE: Here is where you install your plugins. require('lazy').setup({ -- NOTE: First, some plugins that don't require any configuration -- Discord RPC @@ -19,19 +24,18 @@ require('lazy').setup({ -- Detect tabstop and shiftwidth automatically 'tpope/vim-sleuth', - -- NOTE: This is where your plugins related to LSP can be installed. - -- The configuration is done below. Search for lspconfig to find it below. { -- LSP Configuration & Plugins 'neovim/nvim-lspconfig', dependencies = { -- Automatically install LSPs to stdpath for neovim - { 'williamboman/mason.nvim', config = true }, + 'williamboman/mason.nvim', 'williamboman/mason-lspconfig.nvim', + 'WhoIsSethDaniel/mason-tool-installer.nvim', -- Useful status updates for LSP -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` - { 'j-hui/fidget.nvim', opts = {} }, + { 'j-hui/fidget.nvim', opts = {} }, -- Additional lua configuration, makes nvim stuff amazing! 'folke/neodev.nvim', @@ -43,7 +47,18 @@ require('lazy').setup({ 'hrsh7th/nvim-cmp', dependencies = { -- Snippet Engine & its associated nvim-cmp source - 'L3MON4D3/LuaSnip', + { + 'L3MON4D3/LuaSnip', + build = (function() + -- Build Step is needed for regex support in snippets + -- This step is not supported in many windows environments + -- Remove the below condition to re-enable on windows + 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 @@ -56,7 +71,22 @@ require('lazy').setup({ }, -- Useful plugin to show you pending keybinds. - { 'folke/which-key.nvim', opts = {} }, + { + 'folke/which-key.nvim', + event = 'VeryLazy', -- Sets the loading event to 'VeryLazy' + config = function() -- This is the function that runs, AFTER loading + require('which-key').setup() + + -- Document existing key chains + require('which-key').register { + ['c'] = { name = '[C]ode', _ = '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, + }, { -- Adds git related signs to the gutter, as well as utilities for managing changes 'lewis6991/gitsigns.nvim', @@ -133,43 +163,82 @@ require('lazy').setup({ }, { - -- Theme inspired by Atom - 'navarasu/onedark.nvim', - priority = 1000, - config = function() - vim.cmd.colorscheme 'onedark' - end, - }, - - { - -- Set lualine as statusline - 'nvim-lualine/lualine.nvim', - -- See `:help lualine.txt` + -- Autoformat + 'stevearc/conform.nvim', opts = { - options = { - icons_enabled = false, - theme = 'onedark', - component_separators = '|', - section_separators = '', + notify_on_error = false, + format_on_save = { + timeout_ms = 500, + lsp_fallback = true, + }, + formatters_by_ft = { + lua = { 'stylua' }, + -- Conform can also run multiple formatters sequentially + python = { "isort", "black" }, + -- + -- You can use a sub-list to tell conform to run *until* a formatter + -- is found. + javascript = { { "prettierd", "prettier" } }, }, }, }, { - -- Add indentation guides even on blank lines - 'lukas-reineke/indent-blankline.nvim', - -- Enable `lukas-reineke/indent-blankline.nvim` - -- See `:help ibl` - main = 'ibl', - opts = {}, + -- You can easily change to a different colorscheme. + -- Change the name of the colorscheme plugin below, and then + -- change the command in the config to whatever the name of that colorscheme is + -- + -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme` + 'folke/tokyonight.nvim', + lazy = false, -- make sure we load this during startup if it is your main colorscheme + priority = 1000, -- make sure to load this before all the other start plugins + config = function() + -- Load the colorscheme here + vim.cmd.colorscheme 'tokyonight-night' + + -- You can configure highlights by doing something like + vim.cmd.hi 'Comment gui=none' + end, }, + -- Highlight todo, notes, etc in comments + { 'folke/todo-comments.nvim', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } }, -- "gc" to comment visual regions/lines - { 'numToStr/Comment.nvim', opts = {} }, + { 'numToStr/Comment.nvim', opts = {} }, - -- Fuzzy Finder (files, lsp, etc) { + -- Collection of various small independent plugins/modules + 'echasnovski/mini.nvim', + config = function() + -- Better Around/Inside textobjects + -- + -- Examples: + -- - va) - [V]isually select [A]round [)]parenthen + -- - yinq - [Y]ank [I]nside [N]ext [']quote + -- - ci' - [C]hange [I]nside [']quote + require('mini.ai').setup { n_lines = 500 } + + -- Add/delete/replace surroundings (brackets, quotes, etc.) + -- + -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren + -- - sd' - [S]urround [D]elete [']quotes + -- - sr)' - [S]urround [R]eplace [)] ['] + require('mini.surround').setup() + + -- Simple and easy statusline. + -- You could remove this setup call if you don't like it, + -- and try some other statusline plugin + require('mini.statusline').setup() + + -- ... and there is more! + -- Check out: https://github.com/echasnovski/mini.nvim + end, + }, + + { + -- Fuzzy Finder (files, lsp, etc) 'nvim-telescope/telescope.nvim', + event = 'VeryLazy', branch = '0.1.x', dependencies = { 'nvim-lua/plenary.nvim', @@ -177,12 +246,26 @@ require('lazy').setup({ -- Only load if `make` is available. Make sure you have the system -- requirements installed. { + -- If encountering errors, see telescope-fzf-native README for install instructions 'nvim-telescope/telescope-fzf-native.nvim', - -- NOTE: If you are having trouble with this installation, - -- refer to the README for telescope-fzf-native for more instructions. + + -- `build` is used to run some command when the plugin is installed/updated. + -- This is only run then, not every time Neovim starts up. build = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release; cmake --build build --config Release; cmake --install build --prefix build', + + -- `cond` is a condition used to determine whether this plugin should be + -- installed and loaded. + cond = function() + return vim.fn.executable 'make' == 1 + end, }, + { 'nvim-telescope/telescope-ui-select.nvim' }, + + -- Useful for getting pretty icons, but requires special font. + -- If you already have a Nerd Font, or terminal set up with fallback fonts + -- you can enable this + { 'nvim-tree/nvim-web-devicons' } }, }, @@ -195,18 +278,24 @@ require('lazy').setup({ build = ':TSUpdate', }, - -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart - -- These are some example plugins that I've included in the kickstart repository. - -- Uncomment any of the lines below to enable them. - require 'kickstart.plugins.autoformat', + -- The following two comments only work if you have downloaded the kickstart repo, not just copy pasted the + -- init.lua. If you want these files, they are in the repository, so you can just download them and + -- put them in the right spots if you want. + + -- NOTE: Next step on your Neovim journey: Add/Configure additional plugins for kickstart + -- + -- Here are some example plugins that I've included in the kickstart repository. + -- Uncomment any of the lines below to enable them (you will need to restart nvim). + + require 'kickstart.plugins.indent_line', + require 'kickstart.plugins.health', require 'kickstart.plugins.debug', -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` - -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping - -- up-to-date with whatever is in the kickstart repo. - -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. + -- This is the easiest way to modularize your config. -- - -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins + -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. + -- For additional information see: :help lazy.nvim-lazy.nvim-structuring-your-plugins -- { import = 'custom.plugins' }, }, {}) diff --git a/lua/lsp-setup.lua b/lua/lsp-setup.lua index b493a4d..c1c0037 100644 --- a/lua/lsp-setup.lua +++ b/lua/lsp-setup.lua @@ -1,6 +1,10 @@ -- [[ Configure LSP ]] -- This function gets run when an LSP connects to a particular buffer. -local on_attach = function(_, bufnr) + +-- See `:help telescope.builtin` +local builtin = require 'telescope.builtin' + +local on_attach = function(client, bufnr) -- NOTE: Remember that lua is a real programming language, and as such it is possible -- to define small helper and utility functions so you don't have to repeat yourself -- many times. @@ -18,12 +22,12 @@ local on_attach = function(_, bufnr) nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') - nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') - nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') - nmap('D', require('telescope.builtin').lsp_type_definitions, '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') + nmap('gd', builtin.lsp_definitions, '[G]oto [D]efinition') + nmap('gr', builtin.lsp_references, '[G]oto [R]eferences') + nmap('gI', builtin.lsp_implementations, '[G]oto [I]mplementation') + nmap('D', builtin.lsp_type_definitions, 'Type [D]efinition') + nmap('ds', builtin.lsp_document_symbols, '[D]ocument [S]ymbols') + nmap('ws', builtin.lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') -- See `:help K` for why this keymap nmap('K', vim.lsp.buf.hover, 'Hover Documentation') @@ -41,6 +45,23 @@ local on_attach = function(_, bufnr) vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) vim.lsp.buf.format() end, { desc = 'Format current buffer with LSP' }) + + -- The following two autocommands are used to highlight references of the + -- word under your cursor when your cursor rests there for a little while. + -- See `:help CursorHold` for information about when this is executed + -- + -- When you move your cursor, the highlights will be cleared (the second autocommand). + 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 -- document existing key chains @@ -82,9 +103,19 @@ local servers = { svelte = {}, lua_ls = { Lua = { - workspace = { checkThirdParty = false }, + runtime = { version = 'LuaJIT' }, + workspace = { + checkThirdParty = false, + -- Tells lua_ls where to find all the Lua files that you have loaded + -- for your neovim configuration. + library = { + '${3rd}/luv/library', + unpack(vim.api.nvim_get_runtime_file('', true)), + }, + -- If lua_ls is really slow on your computer, you can try this instead: + -- library = { vim.env.VIMRUNTIME }, + }, telemetry = { enable = false }, - -- diagnostics = { disable = { 'missing-fields' } }, }, }, } @@ -94,24 +125,33 @@ 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) +capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities()) --- Ensure the servers above are installed -local mason_lspconfig = require 'mason-lspconfig' +-- You can add other tools here that you want Mason to install +-- for you, so that they are available from within Neovim. +local ensure_installed = vim.tbl_keys(servers or {}) +vim.list_extend(ensure_installed, { + 'stylua', -- Used to format lua code +}) -mason_lspconfig.setup { - ensure_installed = vim.tbl_keys(servers), -} +require('mason-tool-installer').setup { ensure_installed = ensure_installed } -mason_lspconfig.setup_handlers { - function(server_name) - require('lspconfig')[server_name].setup { - capabilities = capabilities, - on_attach = on_attach, - settings = servers[server_name], - filetypes = (servers[server_name] or {}).filetypes, - } - end, +require('mason-lspconfig').setup { + handlers = { + function(server_name) + local server = servers[server_name] or {} + require('lspconfig')[server_name].setup { + cmd = server.cmd, + on_attach = on_attach, + settings = server.settings, + filetypes = server.filetypes, + -- 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) + capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}), + } + end, + } } -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/options.lua b/lua/options.lua index e472d0c..30d6a02 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -33,8 +33,9 @@ vim.o.wrap = false -- Search vim.o.scrolloff = 8 --- Set highlight on search -vim.o.hlsearch = false +-- Set highlight on search, but clear on pressing in normal mode +vim.o.hlsearch = true +vim.keymap.set('n', '', 'nohlsearch') -- Make line numbers default vim.wo.number = true @@ -42,6 +43,9 @@ vim.wo.number = true -- Enable mouse mode vim.o.mouse = 'a' +-- Don't show the mode, since it's already in status line +vim.o.showmode = false + -- Sync clipboard between OS and Neovim. -- Remove this option if you want your OS clipboard to remain independent. -- See `:help 'clipboard'` @@ -70,4 +74,14 @@ vim.o.completeopt = 'menuone,noselect' -- NOTE: You should make sure your terminal supports this vim.o.termguicolors = true +-- Configure how new splits should be opened +vim.o.splitright = true +vim.o.splitbelow = true + +-- Preview substitutions live, as you type! +vim.o.inccommand = 'split' + +-- Show which line your cursor is on +vim.opt.cursorline = true + -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/telescope-setup.lua b/lua/telescope-setup.lua index cfb5a56..d800b37 100644 --- a/lua/telescope-setup.lua +++ b/lua/telescope-setup.lua @@ -3,16 +3,22 @@ require('telescope').setup { defaults = { mappings = { - i = { - [''] = false, - [''] = false, - }, + i = { [''] = 'to_fuzzy_refine' }, + }, + }, + extensions = { + ['ui-select'] = { + require('telescope.themes').get_dropdown(), }, }, } --- Enable telescope fzf native, if installed +-- Enable telescope extensions, if they are installed pcall(require('telescope').load_extension, 'fzf') +pcall(require('telescope').load_extension, 'ui-select') + +-- See `:help telescope.builtin` +local builtin = require 'telescope.builtin' -- Telescope live_grep in git root -- Function to find the git root directory based on the current buffer's path @@ -42,7 +48,7 @@ end local function live_grep_git_root() local git_root = find_git_root() if git_root then - require('telescope.builtin').live_grep { + builtin.live_grep { search_dirs = { git_root }, } end @@ -51,31 +57,37 @@ end vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {}) -- See `:help telescope.builtin` -vim.keymap.set('n', '?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) -vim.keymap.set('n', '', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) +vim.keymap.set('n', '?', builtin.oldfiles, { desc = '[?] Find recently opened files' }) +vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) vim.keymap.set('n', '/', function() -- You can pass additional configuration to telescope to change theme, layout, etc. - require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { winblend = 10, previewer = false, }) end, { desc = '[/] Fuzzily search in current buffer' }) local function telescope_live_grep_open_files() - require('telescope.builtin').live_grep { + builtin.live_grep { grep_open_files = true, prompt_title = 'Live Grep in Open Files', } end vim.keymap.set('n', 's/', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' }) -vim.keymap.set('n', 'ss', require('telescope.builtin').builtin, { desc = '[S]earch [S]elect Telescope' }) -vim.keymap.set('n', 'gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) -vim.keymap.set('n', 'sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) -vim.keymap.set('n', 'sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) -vim.keymap.set('n', 'sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) -vim.keymap.set('n', 'sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) +vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) +vim.keymap.set('n', 'gf', builtin.git_files, { desc = 'Search [G]it [F]iles' }) +vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) +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', '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', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) vim.keymap.set('n', 'sG', ':LiveGrepGitRoot', { desc = '[S]earch by [G]rep on Git Root' }) -vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) -vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) +vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) +vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) +-- Shortcut for searching your neovim configuration files +vim.keymap.set('n', 'sn', function() + builtin.find_files { cwd = vim.fn.stdpath 'config' } +end, { desc = '[S]earch [N]eovim files' }) -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/treesitter-setup.lua b/lua/treesitter-setup.lua index 56e3498..6a46fea 100644 --- a/lua/treesitter-setup.lua +++ b/lua/treesitter-setup.lua @@ -2,6 +2,7 @@ -- See `:help nvim-treesitter` -- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}' vim.defer_fn(function() + ---@diagnostic disable-next-line: missing-fields require('nvim-treesitter.configs').setup { -- Add languages to be installed here that you want installed for treesitter ensure_installed = { 'lua', 'python', 'rust', 'javascript', 'typescript', 'vimdoc', 'vim', 'svelte', 'c_sharp' },