Merge branch 'nvim-lua-master'

This commit is contained in:
Baipyrus 2024-02-27 14:40:04 +01:00
commit 73e1f58a5a
13 changed files with 373 additions and 161 deletions

View File

@ -4,6 +4,7 @@ on: pull_request_target
jobs: jobs:
stylua-check: stylua-check:
if: github.repository == 'nvim-lua/kickstart.nvim'
name: Stylua Check name: Stylua Check
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:

2
.gitignore vendored
View File

@ -2,4 +2,6 @@ tags
test.sh test.sh
.luarc.json .luarc.json
nvim nvim
spell/
lazy-lock.json lazy-lock.json

View File

@ -11,15 +11,32 @@ cmp.setup {
luasnip.lsp_expand(args.body) luasnip.lsp_expand(args.body)
end, end,
}, },
completion = { completion = { completeopt = 'menu,menuone,noinsert' },
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 { mapping = cmp.mapping.preset.insert {
-- Select the [n]ext item
['<C-n>'] = cmp.mapping.select_next_item(), ['<C-n>'] = cmp.mapping.select_next_item(),
-- Select the [p]revious item
['<C-p>'] = cmp.mapping.select_prev_item(), ['<C-p>'] = 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.
['<C-y>'] = cmp.mapping.confirm { select = true },
['<C-b>'] = cmp.mapping.scroll_docs(-4), ['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4), ['<C-f>'] = 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.
['<C-Space>'] = cmp.mapping.complete {}, ['<C-Space>'] = cmp.mapping.complete {},
['<CR>'] = cmp.mapping.confirm { ['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace, behavior = cmp.ConfirmBehavior.Replace,
select = true, select = true,
@ -42,6 +59,25 @@ cmp.setup {
fallback() fallback()
end end
end, { 'i', 's' }), end, { 'i', 's' }),
-- Think of <c-l> as moving to the right of your snippet expansion.
-- So if you have a snippet that's like:
-- function $name($args)
-- $body
-- end
--
-- <c-l> will move you to the right of each of the expansion locations.
-- <c-h> is similar, except moving you backwards.
['<C-l>'] = cmp.mapping(function()
if luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
end
end, { 'i', 's' }),
['<C-h>'] = cmp.mapping(function()
if luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
end
end, { 'i', 's' }),
}, },
sources = { sources = {
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },

View File

@ -14,15 +14,30 @@ vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnos
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
-- [[ Highlight on yank ]] -- Disable arrow keys in normal mode
vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
vim.keymap.set('n', '<right>', '<cmd>echo "Use l to move!!"<CR>')
vim.keymap.set('n', '<up>', '<cmd>echo "Use k to move!!"<CR>')
vim.keymap.set('n', '<down>', '<cmd>echo "Use j to move!!"<CR>')
-- Keybinds to make split navigation easier.
-- Use CTRL+<hjkl> to switch between windows
--
-- See `:help wincmd` for a list of all window commands
vim.keymap.set('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' })
vim.keymap.set('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right window' })
vim.keymap.set('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower window' })
vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { 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()` -- See `:help vim.highlight.on_yank()`
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
vim.api.nvim_create_autocmd('TextYankPost', { 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() callback = function()
vim.highlight.on_yank() vim.highlight.on_yank()
end, end,
group = highlight_group,
pattern = '*',
}) })
-- vim: ts=2 sts=2 sw=2 et -- vim: ts=2 sts=2 sw=2 et

51
lua/kickstart/health.lua Normal file
View File

@ -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,
}

View File

@ -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,
}

View File

@ -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 = {},
},
}

View File

@ -3,15 +3,16 @@
-- `:help lazy.nvim.txt` for more info -- `:help lazy.nvim.txt` for more info
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then if not vim.loop.fs_stat(lazypath) then
local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
vim.fn.system { vim.fn.system {
'git', 'git',
'clone', 'clone',
'--filter=blob:none', '--filter=blob:none',
'https://github.com/folke/lazy.nvim.git', '--branch=stable',
'--branch=stable', -- latest stable release lazyrepo,
lazypath, lazypath
} }
end end ---@diagnostic disable-next-line: undefined-field
vim.opt.rtp:prepend(lazypath) vim.opt.rtp:prepend(lazypath)
-- vim: ts=2 sts=2 sw=2 et -- vim: ts=2 sts=2 sw=2 et

View File

@ -1,9 +1,14 @@
-- [[ Configure plugins ]] -- [[ Configure and install plugins ]]
-- NOTE: Here is where you install your plugins.
-- You can configure plugins using the `config` key.
-- --
-- You can also configure plugins after the setup call, -- To check the current status of your plugins, run
-- as they will be available in your neovim runtime. -- :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({ require('lazy').setup({
-- NOTE: First, some plugins that don't require any configuration -- NOTE: First, some plugins that don't require any configuration
-- Discord RPC -- Discord RPC
@ -19,15 +24,14 @@ require('lazy').setup({
-- Detect tabstop and shiftwidth automatically -- Detect tabstop and shiftwidth automatically
'tpope/vim-sleuth', '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 -- LSP Configuration & Plugins
'neovim/nvim-lspconfig', 'neovim/nvim-lspconfig',
dependencies = { dependencies = {
-- Automatically install LSPs to stdpath for neovim -- Automatically install LSPs to stdpath for neovim
{ 'williamboman/mason.nvim', config = true }, 'williamboman/mason.nvim',
'williamboman/mason-lspconfig.nvim', 'williamboman/mason-lspconfig.nvim',
'WhoIsSethDaniel/mason-tool-installer.nvim',
-- Useful status updates for LSP -- Useful status updates for LSP
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
@ -43,7 +47,18 @@ require('lazy').setup({
'hrsh7th/nvim-cmp', 'hrsh7th/nvim-cmp',
dependencies = { dependencies = {
-- Snippet Engine & its associated nvim-cmp source -- 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', 'saadparwaiz1/cmp_luasnip',
-- Adds LSP completion capabilities -- Adds LSP completion capabilities
@ -56,7 +71,22 @@ require('lazy').setup({
}, },
-- Useful plugin to show you pending keybinds. -- 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 {
['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
}
end,
},
{ {
-- Adds git related signs to the gutter, as well as utilities for managing changes -- Adds git related signs to the gutter, as well as utilities for managing changes
'lewis6991/gitsigns.nvim', 'lewis6991/gitsigns.nvim',
@ -133,43 +163,82 @@ require('lazy').setup({
}, },
{ {
-- Theme inspired by Atom -- Autoformat
'navarasu/onedark.nvim', 'stevearc/conform.nvim',
priority = 1000, opts = {
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" } },
},
},
},
{
-- 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() config = function()
vim.cmd.colorscheme 'onedark' -- 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 = {} },
{
-- 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, end,
}, },
{ {
-- Set lualine as statusline
'nvim-lualine/lualine.nvim',
-- See `:help lualine.txt`
opts = {
options = {
icons_enabled = false,
theme = 'onedark',
component_separators = '|',
section_separators = '',
},
},
},
{
-- Add indentation guides even on blank lines
'lukas-reineke/indent-blankline.nvim',
-- Enable `lukas-reineke/indent-blankline.nvim`
-- See `:help ibl`
main = 'ibl',
opts = {},
},
-- "gc" to comment visual regions/lines
{ 'numToStr/Comment.nvim', opts = {} },
-- Fuzzy Finder (files, lsp, etc) -- Fuzzy Finder (files, lsp, etc)
{
'nvim-telescope/telescope.nvim', 'nvim-telescope/telescope.nvim',
event = 'VeryLazy',
branch = '0.1.x', branch = '0.1.x',
dependencies = { dependencies = {
'nvim-lua/plenary.nvim', 'nvim-lua/plenary.nvim',
@ -177,12 +246,26 @@ require('lazy').setup({
-- Only load if `make` is available. Make sure you have the system -- Only load if `make` is available. Make sure you have the system
-- requirements installed. -- requirements installed.
{ {
-- If encountering errors, see telescope-fzf-native README for install instructions
'nvim-telescope/telescope-fzf-native.nvim', '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 = build =
'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release; cmake --build build --config Release; cmake --install build --prefix 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', build = ':TSUpdate',
}, },
-- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart -- The following two comments only work if you have downloaded the kickstart repo, not just copy pasted the
-- These are some example plugins that I've included in the kickstart repository. -- init.lua. If you want these files, they are in the repository, so you can just download them and
-- Uncomment any of the lines below to enable them. -- put them in the right spots if you want.
require 'kickstart.plugins.autoformat',
-- 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', require 'kickstart.plugins.debug',
-- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- 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 -- This is the easiest way to modularize your config.
-- 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.
-- --
-- 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' }, -- { import = 'custom.plugins' },
}, {}) }, {})

View File

@ -1,6 +1,10 @@
-- [[ Configure LSP ]] -- [[ Configure LSP ]]
-- This function gets run when an LSP connects to a particular buffer. -- 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 -- 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 -- to define small helper and utility functions so you don't have to repeat yourself
-- many times. -- many times.
@ -18,12 +22,12 @@ local on_attach = function(_, bufnr)
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') nmap('gd', builtin.lsp_definitions, '[G]oto [D]efinition')
nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') nmap('gr', builtin.lsp_references, '[G]oto [R]eferences')
nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') nmap('gI', builtin.lsp_implementations, '[G]oto [I]mplementation')
nmap('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') nmap('<leader>D', builtin.lsp_type_definitions, 'Type [D]efinition')
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') nmap('<leader>ds', builtin.lsp_document_symbols, '[D]ocument [S]ymbols')
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') nmap('<leader>ws', builtin.lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
-- See `:help K` for why this keymap -- See `:help K` for why this keymap
nmap('K', vim.lsp.buf.hover, 'Hover Documentation') 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.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
vim.lsp.buf.format() vim.lsp.buf.format()
end, { desc = 'Format current buffer with LSP' }) 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 end
-- document existing key chains -- document existing key chains
@ -82,9 +103,19 @@ local servers = {
svelte = {}, svelte = {},
lua_ls = { lua_ls = {
Lua = { 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 }, 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 -- nvim-cmp supports additional completion capabilities, so broadcast that to servers
local capabilities = vim.lsp.protocol.make_client_capabilities() 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 -- You can add other tools here that you want Mason to install
local mason_lspconfig = require 'mason-lspconfig' -- 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 { require('mason-tool-installer').setup { ensure_installed = ensure_installed }
ensure_installed = vim.tbl_keys(servers),
}
mason_lspconfig.setup_handlers { require('mason-lspconfig').setup {
handlers = {
function(server_name) function(server_name)
local server = servers[server_name] or {}
require('lspconfig')[server_name].setup { require('lspconfig')[server_name].setup {
capabilities = capabilities, cmd = server.cmd,
on_attach = on_attach, on_attach = on_attach,
settings = servers[server_name], settings = server.settings,
filetypes = (servers[server_name] or {}).filetypes, 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, end,
} }
}
-- vim: ts=2 sts=2 sw=2 et -- vim: ts=2 sts=2 sw=2 et

View File

@ -33,8 +33,9 @@ vim.o.wrap = false
-- Search -- Search
vim.o.scrolloff = 8 vim.o.scrolloff = 8
-- Set highlight on search -- Set highlight on search, but clear on pressing <Esc> in normal mode
vim.o.hlsearch = false vim.o.hlsearch = true
vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
-- Make line numbers default -- Make line numbers default
vim.wo.number = true vim.wo.number = true
@ -42,6 +43,9 @@ vim.wo.number = true
-- Enable mouse mode -- Enable mouse mode
vim.o.mouse = 'a' 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. -- Sync clipboard between OS and Neovim.
-- Remove this option if you want your OS clipboard to remain independent. -- Remove this option if you want your OS clipboard to remain independent.
-- See `:help 'clipboard'` -- See `:help 'clipboard'`
@ -70,4 +74,14 @@ vim.o.completeopt = 'menuone,noselect'
-- NOTE: You should make sure your terminal supports this -- NOTE: You should make sure your terminal supports this
vim.o.termguicolors = true 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 -- vim: ts=2 sts=2 sw=2 et

View File

@ -3,16 +3,22 @@
require('telescope').setup { require('telescope').setup {
defaults = { defaults = {
mappings = { mappings = {
i = { i = { ['<c-enter>'] = 'to_fuzzy_refine' },
['<C-u>'] = false,
['<C-d>'] = false,
}, },
}, },
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, 'fzf')
pcall(require('telescope').load_extension, 'ui-select')
-- See `:help telescope.builtin`
local builtin = require 'telescope.builtin'
-- Telescope live_grep in git root -- Telescope live_grep in git root
-- Function to find the git root directory based on the current buffer's path -- 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 function live_grep_git_root()
local git_root = find_git_root() local git_root = find_git_root()
if git_root then if git_root then
require('telescope.builtin').live_grep { builtin.live_grep {
search_dirs = { git_root }, search_dirs = { git_root },
} }
end end
@ -51,31 +57,37 @@ end
vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {}) vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {})
-- See `:help telescope.builtin` -- See `:help telescope.builtin`
vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) vim.keymap.set('n', '<leader>?', builtin.oldfiles, { desc = '[?] Find recently opened files' })
vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) vim.keymap.set('n', '<leader><space>', builtin.buffers, { desc = '[ ] Find existing buffers' })
vim.keymap.set('n', '<leader>/', function() vim.keymap.set('n', '<leader>/', function()
-- You can pass additional configuration to telescope to change theme, layout, etc. -- 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, winblend = 10,
previewer = false, previewer = false,
}) })
end, { desc = '[/] Fuzzily search in current buffer' }) end, { desc = '[/] Fuzzily search in current buffer' })
local function telescope_live_grep_open_files() local function telescope_live_grep_open_files()
require('telescope.builtin').live_grep { builtin.live_grep {
grep_open_files = true, grep_open_files = true,
prompt_title = 'Live Grep in Open Files', prompt_title = 'Live Grep in Open Files',
} }
end end
vim.keymap.set('n', '<leader>s/', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' }) vim.keymap.set('n', '<leader>s/', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' })
vim.keymap.set('n', '<leader>ss', require('telescope.builtin').builtin, { desc = '[S]earch [S]elect Telescope' }) vim.keymap.set('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' })
vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) vim.keymap.set('n', '<leader>gf', builtin.git_files, { desc = 'Search [G]it [F]iles' })
vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) vim.keymap.set('n', '<leader>sf', builtin.find_files, { desc = '[S]earch [F]iles' })
vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) vim.keymap.set('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' })
vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) vim.keymap.set('n', '<leader>sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' })
vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) vim.keymap.set('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' })
vim.keymap.set('n', '<leader>sg', builtin.live_grep, { desc = '[S]earch by [G]rep' })
vim.keymap.set('n', '<leader>s.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
vim.keymap.set('n', '<leader>sG', ':LiveGrepGitRoot<cr>', { desc = '[S]earch by [G]rep on Git Root' }) vim.keymap.set('n', '<leader>sG', ':LiveGrepGitRoot<cr>', { desc = '[S]earch by [G]rep on Git Root' })
vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' })
vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' })
-- Shortcut for searching your neovim configuration files
vim.keymap.set('n', '<leader>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 -- vim: ts=2 sts=2 sw=2 et

View File

@ -2,6 +2,7 @@
-- See `:help nvim-treesitter` -- See `:help nvim-treesitter`
-- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}' -- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}'
vim.defer_fn(function() vim.defer_fn(function()
---@diagnostic disable-next-line: missing-fields
require('nvim-treesitter.configs').setup { require('nvim-treesitter.configs').setup {
-- Add languages to be installed here that you want installed for treesitter -- Add languages to be installed here that you want installed for treesitter
ensure_installed = { 'lua', 'python', 'rust', 'javascript', 'typescript', 'vimdoc', 'vim', 'svelte', 'c_sharp' }, ensure_installed = { 'lua', 'python', 'rust', 'javascript', 'typescript', 'vimdoc', 'vim', 'svelte', 'c_sharp' },