Initial nvim config.

This commit is contained in:
Arthur Khachaturov 2023-11-28 23:54:18 +03:00
parent e915531d83
commit c26d67450b
19 changed files with 279 additions and 0 deletions

3
.config/nvim/init.lua Normal file
View file

@ -0,0 +1,3 @@
require("core")
require("plugins")
require("lsp")

View file

@ -0,0 +1,4 @@
return {
"bashls",
settings = { },
}

View file

@ -0,0 +1,5 @@
return {
"clangd",
settings = {}
}

View file

@ -0,0 +1,12 @@
return {
"pylsp",
settings = {
["pylsp"] = {
plugins = {
pylint = {
enabled = true,
},
},
},
},
}

View file

@ -0,0 +1 @@
return { "vim-airline/vim-airline" }

View file

@ -0,0 +1,8 @@
return {
"akinsho/bufferline.nvim",
config = {
options = {
buffer_close_icon = "",
}
}
}

View file

@ -0,0 +1,8 @@
return {
'numToStr/Comment.nvim',
opts = { },
lazy = false,
config = function()
require('Comment').setup()
end,
}

View file

@ -0,0 +1 @@
return { "nvim-tree/nvim-web-devicons" }

View file

@ -0,0 +1,8 @@
return {
'Wansmer/langmapper.nvim',
lazy = false,
priority = 1,
config = {
hack_keymap = true,
}
}

View file

@ -0,0 +1,5 @@
return {
"ethanholz/nvim-lastplace",
config = {}
}

View file

@ -0,0 +1 @@
return { "neovim/nvim-lspconfig" }

View file

@ -0,0 +1,10 @@
return {
"nvim-tree/nvim-tree.lua",
config = function()
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
require("nvim-tree").setup()
end,
}

View file

@ -0,0 +1,8 @@
return {
"joshdick/onedark.vim",
lazy = false,
config = function()
vim.cmd([[colorscheme onedark]])
end,
}

View file

@ -0,0 +1,14 @@
return {
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function ()
local configs = require("nvim-treesitter.configs")
configs.setup({
ensure_installed = { "c", "cpp", "lua", "vim", "vimdoc", "query", "python", "javascript", "html" },
sync_install = false,
highlight = { enable = true },
indent = { enable = true },
})
end
}

View file

@ -0,0 +1,4 @@
return {
"wakatime/vim-wakatime",
lazy = false,
}

33
.config/nvim/lua/core.lua Normal file
View file

@ -0,0 +1,33 @@
-- Line numbers
vim.opt.number = true
vim.opt.relativenumber = true
-- Indentation
vim.opt.expandtab = true
vim.opt.autoindent = true
vim.opt.smarttab = true
vim.opt.shiftwidth = 4
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
-- Enable syntax highlighting
vim.opt.termguicolors = true
vim.opt.syntax = on
-- Enable undo after closing vim
vim.opt.undofile = true
-- Make vim work with russian layout
local function escape(str)
local escape_chars = [[;,."|\]]
return vim.fn.escape(str, escape_chars)
end
local en = [[`qwertyuiop[]asdfghjkl;'zxcvbnm]] local ru = [[ёйцукенгшщзхъфывапролджэячсмить]]
local en_shift = [[~QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>]]
local ru_shift = [[ËЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ]]
vim.opt.langmap = vim.fn.join({
escape(ru_shift) .. ';' .. escape(en_shift),
escape(ru) .. ';' .. escape(en),
}, ',')

107
.config/nvim/lua/lsp.lua Normal file
View file

@ -0,0 +1,107 @@
-- require("utils").load_servers{
-- require("configs.lsp.pylsp"),
-- require("configs.lsp.clangd"),
-- require("configs.lsp.bash"),
-- }
--
local lspconfig = require("lspconfig")
local custom_attach = function(client, bufnr)
-- Mappings.
local map = function(mode, l, r, opts)
opts = opts or {}
opts.silent = true
opts.buffer = bufnr
keymap.set(mode, l, r, opts)
end
map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" })
map("n", "<C-]>", vim.lsp.buf.definition)
map("n", "K", vim.lsp.buf.hover)
map("n", "<C-k>", vim.lsp.buf.signature_help)
map("n", "<space>rn", vim.lsp.buf.rename, { desc = "varialbe rename" })
map("n", "gr", vim.lsp.buf.references, { desc = "show references" })
map("n", "[d", diagnostic.goto_prev, { desc = "previous diagnostic" })
map("n", "]d", diagnostic.goto_next, { desc = "next diagnostic" })
-- this puts diagnostics from opened files to quickfix
map("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" })
-- this puts diagnostics from current buffer to quickfix
map("n", "<space>qb", function() set_qflist(bufnr) end, { desc = "put buffer diagnostics to qf" })
map("n", "<space>ca", vim.lsp.buf.code_action, { desc = "LSP code action" })
map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" })
map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" })
map("n", "<space>wl", function()
inspect(vim.lsp.buf.list_workspace_folders())
end, { desc = "list workspace folder" })
-- Set some key bindings conditional on server capabilities
if client.server_capabilities.documentFormattingProvider then
map("n", "<space>f", vim.lsp.buf.format, { desc = "format code" })
end
api.nvim_create_autocmd("CursorHold", {
buffer = bufnr,
callback = function()
local float_opts = {
focusable = false,
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
border = "rounded",
source = "always", -- show source in diagnostic popup window
prefix = " ",
}
if not vim.b.diagnostics_pos then
vim.b.diagnostics_pos = { nil, nil }
end
local cursor_pos = api.nvim_win_get_cursor(0)
if (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2])
and #diagnostic.get() > 0
then
diagnostic.open_float(nil, float_opts)
end
vim.b.diagnostics_pos = cursor_pos
end,
})
-- The blow command will highlight the current variable and its usages in the buffer.
if client.server_capabilities.documentHighlightProvider then
vim.cmd([[
hi! link LspReferenceRead Visual
hi! link LspReferenceText Visual
hi! link LspReferenceWrite Visual
]])
local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true })
api.nvim_create_autocmd("CursorHold" , {
group = gid,
buffer = bufnr,
callback = function ()
lsp.buf.document_highlight()
end
})
api.nvim_create_autocmd("CursorMoved" , {
group = gid,
buffer = bufnr,
callback = function ()
lsp.buf.clear_references()
end
})
end
if vim.g.logging_level == "debug" then
local msg = string.format("Language server %s started!", client.name)
vim.notify(msg, vim.log.levels.DEBUG, { title = "Nvim-config" })
end
end
lspconfig.clangd.setup {
on_attach = custom_attach,
filetypes = { "c", "cpp", "cc" },
flags = {
debounce_text_changes = 500,
},
}

View file

@ -0,0 +1,14 @@
require("utils").init_lazy()
require("lazy").setup{
require("configs.plugins.bufferline"),
require("configs.plugins.comment"),
require("configs.plugins.lastplace"),
require("configs.plugins.nvim-tree"),
require("configs.plugins.onedark"),
require("configs.plugins.airline"),
require("configs.plugins.langmapper"),
require("configs.plugins.devicons"),
require("configs.plugins.treesitter"),
require("configs.plugins.lspconfig"),
}

View file

@ -0,0 +1,33 @@
local M = {}
function M.init_lazy()
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",
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
end
function load_server(lspconfig, server)
server_name = server[1]
table.remove(server, 1)
lspconfig[server_name].setup(server)
end
function M.load_servers(servers)
lspconfig = require("lspconfig")
for _, server in ipairs(servers) do
load_server(lspconfig, server)
end
end
return M