neovim config

This commit is contained in:
2025-03-09 20:59:55 +03:00
parent bdab2117f3
commit 972a43b01f
10 changed files with 305 additions and 0 deletions

5
nvim/lua/keymap.lua Normal file
View File

@@ -0,0 +1,5 @@
vim.g.mapleader = " "
vim.keymap.set("n", "<space><space>", "<cmd> :noh<CR>", { desc = "Clear search highlighting" })
-- Find and replace visual selection using CTRL-r
vim.keymap.set("v", "<C-r>", "\"hy:%s/<C-r>h//gc<left><left><left>")

123
nvim/lua/lsp-config.lua Normal file
View File

@@ -0,0 +1,123 @@
require("mason").setup()
require("mason-lspconfig").setup({
ensure_installed = {
'lua_ls',
'gopls',
'bashls',
},
automatic_installation = true,
})
-- Customized on_attach function
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
--
local opts = { noremap = true, silent = true }
vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, opts)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist, opts)
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
if client.name == "rust_analyzer" then
-- This requires Neovim 0.10 or later
vim.lsp.inlay_hint.enable()
end
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, bufopts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, bufopts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set("n", "<space>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts)
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, bufopts)
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, bufopts)
vim.keymap.set("n", "<space>ca", vim.lsp.buf.code_action, bufopts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, bufopts)
vim.keymap.set("n", "<space>lf", function()
vim.lsp.buf.format({
async = true,
})
end, bufopts)
end
-- Specify the border characters
local border = {
{ '', 'FloatBorder' },
{ '', 'FloatBorder' },
{ '', 'FloatBorder' },
{ '', 'FloatBorder' },
{ '', 'FloatBorder' },
{ '', 'FloatBorder' },
{ '', 'FloatBorder' },
{ '', 'FloatBorder' },
}
-- Add the border on hover and on signature help popup window
local handlers = {
['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }),
['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }),
}
-- Add border to the diagnostic popup window
vim.diagnostic.config({
virtual_text = {
prefix = '', -- Could be '●', '▎', 'x', '■', , 
},
signs = false, -- Show signs in the gutter
underline = true,
update_in_insert = false, -- Don't update diagnostics in insert mode
severity_sort = true, -- Sort diagnostics by severity
float = { border = "rounded" },
})
local capabilities = require('cmp_nvim_lsp').default_capabilities()
require("lspconfig").lua_ls.setup({
on_attach = on_attach,
settings = {
Lua = {
format = {
enable = true,
defaultConfig = {
indent_style = "space",
indent_size = "2",
}
},
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
}
},
capabilities = capabilities,
handlers = handlers
})
require("lspconfig").gopls.setup {capabilities = capabilities, handlers = handlers}
require("lspconfig").bashls.setup {capabilities = capabilities, handlers = handlers,
settings = {
bashIde = {
globPattern = "*@(.sh|.inc|.bash|.command)"
}
}
}

22
nvim/lua/options.lua Normal file
View File

@@ -0,0 +1,22 @@
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
-- case insensitive search
vim.opt.ignorecase = true
vim.opt.smartcase = true
-- show line numbers
vim.opt.number = true
vim.opt.relativenumber = true
-- show trailing whitespace
vim.opt.list = true
vim.opt.listchars = {
tab = '',
multispace = '',
trail = '·',
extends = '',
precedes = ''
}
vim.cmd([[match errorMsg /\s\+$/]])

View File

@@ -0,0 +1,61 @@
vim.opt.completeopt = { 'menu', 'menuone', 'noselect' }
-- Set up nvim-cmp
local cmp = require('cmp')
local luasnip = require('luasnip')
local select_opts = { behavior = cmp.SelectBehavior.Select }
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end
},
window = {
documentation = cmp.config.window.bordered(),
completion = { border = 'rounded' }
},
formatting = {
fields = { 'menu', 'abbr', 'kind' },
format = function(entry, item)
local menu_icon = {
nvim_lsp = 'λ',
luasnip = '',
buffer = 'Ω',
path = '🖫',
}
item.menu = menu_icon[entry.source.name]
return item
end,
},
mapping = {
-- Trigger completion menu with <Tab>
['<Tab>'] = cmp.mapping(function(fallback)
local col = vim.fn.col('.') - 1
if cmp.visible() then
cmp.select_next_item(select_opts)
elseif col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
fallback()
else
cmp.complete()
end
end, { 'i', 's' }),
-- Trigger completion menu with <C-Space>
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), -- Open completion menu
-- Navigate completion menu with <C-n> and <C-p>
['<C-n>'] = cmp.mapping.select_next_item(), -- Next item
['<C-p>'] = cmp.mapping.select_prev_item(), -- Previous item
-- Confirm selection with <CR> (Enter)
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Confirm selection
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' }, -- LSP source
{ name = 'buffer' }, -- Buffer source
{ name = 'path' }, -- Path source
{ name = 'luasnip' }, -- Path source
}),
})

52
nvim/lua/plugins/init.lua Normal file
View File

@@ -0,0 +1,52 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
local plugins = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
{
"neovim/nvim-lspconfig",
dependencies = { 'hrsh7th/cmp-nvim-lsp' }
},
{
'projekt0n/github-nvim-theme',
name = 'github-theme',
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()
require('github-theme').setup({
-- ...
})
vim.cmd('colorscheme github_light_colorblind')
-- vim.cmd('colorscheme github_dark_colorblind')
-- vim.cmd('colorscheme github_dark')
end,
},
{
"nvim-telescope/telescope-file-browser.nvim",
dependencies = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" }
},
'hrsh7th/nvim-cmp', -- Auto-completion plugin
dependencies = {
'hrsh7th/cmp-nvim-lsp', -- LSP source for nvim-cmp
'hrsh7th/cmp-buffer', -- Buffer source for nvim-cmp
'hrsh7th/cmp-path', -- Path source for nvim-cmp
},
'L3MON4D3/LuaSnip',
}
require("lazy").setup(plugins)
require("plugins/telescope")
require("plugins/completions")

View File

@@ -0,0 +1,20 @@
require("telescope").setup {
extensions = {
file_browser = {
initial_mode = "normal",
-- ...
},
},
}
require("telescope").load_extension "file_browser"
-- require("telescope").load_extension "find_files"
-- vim.keymap.set("n", "<space>fb", ":Telescope file_browser<CR>")
-- open file_browser with the path of the current buffer
vim.keymap.set("n", "<space>fb", ":Telescope file_browser path=%:p:h select_buffer=true<CR>")
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = 'Telescope find files' })
vim.keymap.set('n', '<leader>fg', builtin.live_grep, { desc = 'Telescope live grep' })
vim.keymap.set('n', '<leader>b', builtin.buffers, { desc = 'Telescope buffers' })
vim.keymap.set('n', '<leader>fh', builtin.help_tags, { desc = 'Telescope help tags' })