summaryrefslogtreecommitdiff
path: root/nvim/lua
diff options
context:
space:
mode:
authorAlex NeonXP <i@neonxp.ru>2024-02-18 15:18:56 +0300
committerAlex NeonXP <i@neonxp.ru>2024-02-18 15:18:56 +0300
commitd3483449381b6a7ee4e62e352c699c63ddaab33a (patch)
tree6b181039580851d51629cb7e3bb139bde90e9720 /nvim/lua
parent17951e8c06f638543a19cbcaf95623ca211d6514 (diff)
Конфиги nvim
Diffstat (limited to 'nvim/lua')
-rw-r--r--nvim/lua/autocommands.lua46
-rw-r--r--nvim/lua/keymaps.lua49
-rw-r--r--nvim/lua/lsp.lua65
-rw-r--r--nvim/lua/options.lua46
-rw-r--r--nvim/lua/plugins/init.lua75
-rw-r--r--nvim/lua/plugins/lualine.lua40
-rw-r--r--nvim/lua/plugins/telescope.lua7
-rw-r--r--nvim/lua/plugins/tree.lua14
-rw-r--r--nvim/lua/plugins/treesitter.lua5
9 files changed, 347 insertions, 0 deletions
diff --git a/nvim/lua/autocommands.lua b/nvim/lua/autocommands.lua
new file mode 100644
index 0000000..a052a8c
--- /dev/null
+++ b/nvim/lua/autocommands.lua
@@ -0,0 +1,46 @@
+vim.api.nvim_create_autocmd({'BufWritePre'}, {
+ pattern = '*.go',
+ callback = function()
+ local params = vim.lsp.util.make_range_params(nil, vim.lsp.util._get_offset_encoding())
+ params.context = { only = {'source.organizeImports'} }
+ local result = vim.lsp.buf_request_sync(0, 'textDocument/codeAction', params, 3000)
+ for _, res in pairs(result or {}) do
+ for _, r in pairs(res.result or {}) do
+ if r.edit then
+ vim.lsp.util.apply_workspace_edit(r.edit, vim.lsp.util._get_offset_encoding())
+ else
+ vim.lsp.buf.execute_command(r.command)
+ end
+ end
+ end
+ end,
+})
+
+vim.api.nvim_create_autocmd({'BufWritePre'}, {
+ pattern = '*.go',
+ callback = function()
+ vim.lsp.buf.format(nil, 3000)
+ end
+})
+
+
+local TrimWhiteSpaceGrp = vim.api.nvim_create_augroup('TrimWhiteSpaceGrp', {})
+vim.api.nvim_create_autocmd('BufWritePre', {
+ group = TrimWhiteSpaceGrp,
+ pattern = '*',
+ command = '%s/\\s\\+$//e',
+})
+
+local YankHighlightGrp = vim.api.nvim_create_augroup('YankHighlightGrp', {})
+vim.api.nvim_create_autocmd('TextYankPost', {
+ group = YankHighlightGrp,
+ pattern = '*',
+ callback = function()
+ vim.highlight.on_yank({
+ higroup = 'IncSearch',
+ timeout = 40,
+ })
+ end,
+})
+
+
diff --git a/nvim/lua/keymaps.lua b/nvim/lua/keymaps.lua
new file mode 100644
index 0000000..8cbd8da
--- /dev/null
+++ b/nvim/lua/keymaps.lua
@@ -0,0 +1,49 @@
+local map = vim.api.nvim_set_keymap
+local opts = {noremap = true, silent = true}
+
+-- Tree
+map('n', '<C-h>', ':NvimTreeToggle<CR>', opts)
+
+-- Telescope
+map('n', '<leader>ff', '<cmd>Telescope find_files<CR>', opts)
+map('n', '<leader>fg', '<cmd>Telescope live_grep<CR>', opts)
+map('n', '<leader>fb', '<cmd>Telescope buffers<CR>', opts)
+
+-- LSP
+--map('n', '<leader>e', vim.diagnostic.open_float, opts)
+--map('n', '[d', vim.diagnostic.goto_prev, opts)
+--map('n', ']d', vim.diagnostic.goto_next, opts)
+--map('n', '<leader>q', vim.diagnostic.setloclist, opts)
+
+local on_attach = function(client, bufnr)
+ vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
+
+ local bufopts = { noremap=true, silent=true, buffer=bufnr }
+
+ -- стандартные горячие клавиши для LSP, больше в документации
+ -- https://github.com/neovim/nvim-lspconfig
+ map('n', 'gD', vim.lsp.buf.declaration, bufopts)
+ map('n', 'gd', vim.lsp.buf.definition, bufopts)
+ map('n', 'K', vim.lsp.buf.hover, bufopts)
+ map('n', 'gi', vim.lsp.buf.implementation, bufopts)
+ map('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
+ map('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, bufopts)
+ map('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
+ map('n', '<leader>wl', function()
+ print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
+ end, bufopts)
+ map('n', '<leader>D', vim.lsp.buf.type_definition, bufopts)
+ map('n', '<leader>rn', vim.lsp.buf.rename, bufopts)
+ map('n', '<leader>ca', vim.lsp.buf.code_action, bufopts)
+ map('n', 'gr', vim.lsp.buf.references, bufopts)
+ map('n', '<leader>f', vim.lsp.buf.formatting, bufopts)
+end
+
+local function change_root_to_global_cwd()
+ local api = require("nvim-tree.api")
+ local global_cwd = vim.fn.getcwd(-1, -1)
+ api.tree.change_root(global_cwd)
+end
+
+vim.keymap.set('n', '<C-c>', change_root_to_global_cwd, {})
+
diff --git a/nvim/lua/lsp.lua b/nvim/lua/lsp.lua
new file mode 100644
index 0000000..468ea71
--- /dev/null
+++ b/nvim/lua/lsp.lua
@@ -0,0 +1,65 @@
+
+local cmp = require('cmp')
+
+local source_mapping = {
+ buffer = '[Buffer]',
+ nvim_lsp = '[LSP]',
+ nvim_lua = '[Lua]',
+ cmp_tabnine = '[TN]',
+ path = '[Path]',
+}
+
+cmp.setup({
+ mapping = cmp.mapping.preset.insert({
+ ['<C-y>'] = cmp.mapping.confirm({ select = true }),
+ ['<C-d>'] = cmp.mapping.scroll_docs(-4),
+ ['<C-u>'] = cmp.mapping.scroll_docs(4),
+ ['<C-Space>'] = cmp.mapping.complete(),
+ }),
+ snippet = {
+ expand = function(args)
+ require('luasnip').lsp_expand(args.body)
+ end,
+ },
+ formatting = {
+ format = function(entry, vim_item)
+ local menu = source_mapping[entry.source.name]
+ vim_item.menu = menu
+ return vim_item
+ end
+ },
+ sources = cmp.config.sources({
+ { name = 'nvim_lsp' },
+ { name = 'luasnip' },
+ }, {
+ { name = 'buffer' },
+ })
+})
+
+-- инициализация LSP для различных ЯП
+local lspconfig = require('lspconfig')
+local util = require('lspconfig/util')
+
+local function config(_config)
+ return vim.tbl_deep_extend('force', {
+ capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()),
+ }, _config or {})
+end
+
+-- иницализация gopls LSP для Go
+-- https://github.com/golang/tools/blob/master/gopls/doc/vim.md#neovim-install
+lspconfig.gopls.setup(config({
+ on_attach = on_attach,
+ cmd = { 'gopls', 'serve' },
+ filetypes = { 'go', 'go.mod' },
+ root_dir = util.root_pattern('go.work', 'go.mod', '.git'),
+ settings = {
+ gopls = {
+ analyses = {
+ unusedparams = true,
+ shadow = true,
+ },
+ staticcheck = true,
+ }
+ }
+}))
diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua
new file mode 100644
index 0000000..327c817
--- /dev/null
+++ b/nvim/lua/options.lua
@@ -0,0 +1,46 @@
+vim.g.loaded_netrw = 1
+vim.g.loaded_netrwPlugin = 1
+
+local options = {
+ backup = false, -- creates a backup file
+ clipboard = "unnamedplus", -- allows neovim to access the system clipboard
+ cmdheight = 2, -- more space in the neovim command line for displaying messages
+ completeopt = { "menuone", "noselect" }, -- mostly just for cmp
+ conceallevel = 0, -- so that `` is visible in markdown files
+ fileencoding = "utf-8", -- the encoding written to a file
+ hidden = true, -- required to keep multiple buffers and open multiple buffers
+ hlsearch = true, -- highlight all matches on previous search pattern
+ ignorecase = true, -- ignore case in search patterns
+ mouse = "a", -- allow the mouse to be used in neovim
+ pumheight = 10, -- pop up menu height
+ showmode = false, -- we don't need to see things like -- INSERT -- anymore
+ showtabline = 2, -- always show tabs
+ smartcase = true, -- smart case
+ smartindent = true, -- make indenting smarter again
+ splitbelow = true, -- force all horizontal splits to go below current window
+ splitright = true, -- force all vertical splits to go to the right of current window
+ swapfile = false, -- creates a swapfile
+ termguicolors = true, -- set term gui colors (most terminals support this)
+ timeoutlen = 100, -- time to wait for a mapped sequence to complete (in milliseconds)
+ undofile = true, -- enable persistent undo
+ updatetime = 300, -- faster completion (4000ms default)
+ writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited
+ shiftwidth = 2, -- the number of spaces inserted for each indentation
+ tabstop = 2, -- insert 2 spaces for a tab
+ cursorline = true, -- highlight the current line
+ number = true, -- set numbered lines
+ relativenumber = false, -- set relative numbered lines
+ numberwidth = 4, -- set number column width to 2 {default 4}
+ signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time
+ wrap = false, -- display lines as one long line
+ scrolloff = 8, -- is one of my fav
+ sidescrolloff = 8,
+}
+
+vim.opt.shortmess:append "c"
+
+for k, v in pairs(options) do
+ vim.opt[k] = v
+end
+
+vim.cmd "set whichwrap+=<,>,[,],h,l"
diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua
new file mode 100644
index 0000000..6308262
--- /dev/null
+++ b/nvim/lua/plugins/init.lua
@@ -0,0 +1,75 @@
+local fn = vim.fn
+local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
+if fn.empty(fn.glob(install_path)) > 0 then
+ packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
+end
+
+return require('packer').startup(function(use)
+ use 'wbthomason/packer.nvim'
+ use 'nvim-lua/plenary.nvim'
+ use 'neovim/nvim-lspconfig'
+ use 'hrsh7th/cmp-nvim-lsp'
+ use 'hrsh7th/cmp-buffer'
+ use 'hrsh7th/cmp-path'
+ use 'hrsh7th/nvim-cmp'
+ use {
+ 'nvim-lualine/lualine.nvim',
+ config = function()
+ require 'plugins.lualine'
+ end
+ }
+
+ -- движок сниппетов
+ use {
+ 'L3MON4D3/LuaSnip',
+ after = 'friendly-snippets',
+ config = function()
+ require('luasnip/loaders/from_vscode').load({
+ paths = { '~/.local/share/nvim/site/pack/packer/start/friendly-snippets' }
+ })
+ end
+ }
+
+ -- автодополнения для сниппетов
+ use 'saadparwaiz1/cmp_luasnip'
+
+ -- набор готовых сниппетов для всех языков, включая go
+ use 'rafamadriz/friendly-snippets'
+
+ -- плагин для простого комментирования кода
+ use {
+ 'numToStr/Comment.nvim',
+ config = function()
+ require('Comment').setup()
+ end
+ }
+ use {
+ 'nvim-treesitter/nvim-treesitter',
+ run = ':TSUpdate',
+ config = function()
+ require 'plugins.treesitter'
+ end
+ }
+ use {
+ 'nvim-telescope/telescope.nvim',
+ config = function()
+ require 'plugins.telescope'
+ end
+ }
+ use {
+ 'olexsmir/gopher.nvim',
+ config = function()
+ -- require 'plugins.gopher'
+ end
+ }
+ use {
+ 'nvim-tree/nvim-tree.lua',
+ config = function()
+ require 'plugins.tree'
+ end
+ }
+ use 'nvim-tree/nvim-web-devicons'
+ if packer_bootstrap then
+ require('packer').sync()
+ end
+end)
diff --git a/nvim/lua/plugins/lualine.lua b/nvim/lua/plugins/lualine.lua
new file mode 100644
index 0000000..891b392
--- /dev/null
+++ b/nvim/lua/plugins/lualine.lua
@@ -0,0 +1,40 @@
+require('lualine').setup {
+ options = {
+ icons_enabled = true,
+ theme = 'auto',
+ component_separators = { left = '', right = ''},
+ section_separators = { left = '', right = ''},
+ disabled_filetypes = {
+ statusline = {},
+ winbar = {},
+ },
+ ignore_focus = {},
+ always_divide_middle = true,
+ globalstatus = false,
+ refresh = {
+ statusline = 1000,
+ tabline = 1000,
+ winbar = 1000,
+ }
+ },
+ sections = {
+ lualine_a = {'mode'},
+ lualine_b = {'branch', 'diff', 'diagnostics'},
+ lualine_c = {'filename'},
+ lualine_x = {'encoding', 'fileformat', 'filetype'},
+ lualine_y = {'progress'},
+ lualine_z = {'location'}
+ },
+ inactive_sections = {
+ lualine_a = {},
+ lualine_b = {},
+ lualine_c = {'filename'},
+ lualine_x = {'location'},
+ lualine_y = {},
+ lualine_z = {}
+ },
+ tabline = {},
+ winbar = {},
+ inactive_winbar = {},
+ extensions = {}
+}
diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua
new file mode 100644
index 0000000..44b1869
--- /dev/null
+++ b/nvim/lua/plugins/telescope.lua
@@ -0,0 +1,7 @@
+require('telescope').setup{
+ pickers = {
+ buffers = {
+ initial_mode = 'normal'
+ }
+ }
+}
diff --git a/nvim/lua/plugins/tree.lua b/nvim/lua/plugins/tree.lua
new file mode 100644
index 0000000..86cc36c
--- /dev/null
+++ b/nvim/lua/plugins/tree.lua
@@ -0,0 +1,14 @@
+require("nvim-tree").setup({
+ sort = {
+ sorter = "case_sensitive",
+ },
+ view = {
+ width = 30,
+ },
+ renderer = {
+ group_empty = true,
+ },
+ filters = {
+ dotfiles = true,
+ },
+})
diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua
new file mode 100644
index 0000000..ff02ec4
--- /dev/null
+++ b/nvim/lua/plugins/treesitter.lua
@@ -0,0 +1,5 @@
+require('nvim-treesitter.configs').setup{
+ ensure_installed = 'all',
+ ignore_install = { 'phpdoc' },
+ highlight = { enable = true }
+}