neovim: refactor, add lua-tree

This commit is contained in:
Dmitry Zakharchenko 2024-01-05 17:21:53 +02:00
parent 24385168fa
commit 434e181ec3
7 changed files with 12 additions and 129 deletions

View File

@ -6,12 +6,11 @@ require 'paq' {
'neovim/nvim-lspconfig',
'nvim-lua/plenary.nvim',
'nvim-telescope/telescope.nvim',
'nvim-tree/nvim-tree.lua',
{ 'nvim-treesitter/nvim-treesitter', build = ':TSUpdate' }
}
require('colors')
require('sets')
require('maps')
require('lsp')
require('tlp')
require('trs')
require('plugins')

View File

@ -14,13 +14,15 @@ vim.cmd.highlight({'StatusLine', 'guibg=' .. base16.colors.base01})
vim.cmd.highlight({'TabLine', 'guifg=' .. base16.colors.base0D})
vim.cmd.highlight({'TabLineSel', 'guifg=' .. base16.colors.base0A})
vim.cmd.highlight({'TelescopeBorder', 'guibg=' .. base16.colors.base00})
vim.cmd.highlight({'TelescopeNormal', 'guibg=' .. base16.colors.base00, 'guifg=' .. base16.colors.base0D})
vim.cmd.highlight({'TelescopePreviewLine', 'guibg=' .. base16.colors.base02})
vim.cmd.highlight({'TelescopePromptBorder', 'guibg=' .. base16.colors.base00})
vim.cmd.highlight({'TelescopeNormal', 'guifg=' .. base16.colors.base0D, 'guibg=none'})
vim.cmd.highlight({'TelescopeBorder', 'guifg=' .. base16.colors.base02, 'guibg=none'})
vim.cmd.highlight({'TelescopePromptTitle', 'guifg=' .. base16.colors.base05, 'guibg=none'})
vim.cmd.highlight({'TelescopePreviewTitle', 'guifg=' .. base16.colors.base05, 'guibg=none'})
vim.cmd.highlight({'TelescopeResultsTitle', 'guifg=' .. base16.colors.base00, 'guibg=none'})
vim.cmd.highlight({'TelescopeSelection', 'guifg=' .. base16.colors.base0A, 'guibg=none', 'gui=bold'})
vim.cmd.highlight({'TelescopePromptNormal', 'guibg=' .. base16.colors.base01})
vim.cmd.highlight({'TelescopePromptTitle', 'guibg=' .. base16.colors.base00, 'guifg=' .. base16.colors.base05})
vim.cmd.highlight({'TelescopeSelection', 'guibg=' .. base16.colors.base00, 'guifg=' .. base16.colors.base0A, 'gui=bold'})
vim.cmd.highlight({'TelescopePreviewLine', 'guibg=' .. base16.colors.base02})
vim.cmd.highlight({'TelescopePromptBorder', 'guibg=none'})
vim.cmd.highlight({'TSComment', 'gui=none'})
vim.cmd.highlight({'TSConstBuiltin', 'gui=none'})

View File

@ -1,58 +0,0 @@
local map = vim.keymap.set
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local lsp = require('lspconfig')
local cmp = require('cmp')
cmp.setup({
preselect = cmp.PreselectMode.None,
mapping = {
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end,
["<S-Tab>"] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end,
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
},
sources = {
{name = 'nvim_lsp', max_item_count = 10},
{name = 'buffer', max_item_count = 10},
{name = 'path', priority = 1}
},
})
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
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 }
map('n', 'gD', vim.lsp.buf.declaration, bufopts)
map('n', 'gd', vim.lsp.buf.definition, bufopts)
map('n', 'F', vim.lsp.buf.hover, bufopts)
map('n', 'gr', vim.lsp.buf.references, bufopts)
map('n', 'gi', vim.lsp.buf.implementation, bufopts)
map('n', 'gS', vim.lsp.buf.signature_help, bufopts)
map('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
map('n', '<space>cw', vim.lsp.buf.rename, bufopts)
end
lsp['gopls'].setup{
cmd = {'gopls'},
on_attach = on_attach,
capabilities = capabilities
}

View File

@ -1,5 +1,4 @@
local map = vim.keymap.set
local opts = { noremap=true, silent=true }
local builtin = require('telescope.builtin')
vim.g.mapleader = ' '
@ -19,8 +18,8 @@ map('n', '<C-o>', ':bprevious<CR>')
map('n', '<C-p>', ':bnext<CR>')
map('n', '<C-x>', ':bdelete<CR>')
map('n', '<leader>d', ':NvimTreeFindFileToggle<CR>')
map('n', '<leader>f', builtin.find_files, {})
map('n', '<leader>d', ':Vexplore<CR>')
map('n', '<leader>b', builtin.buffers, {})
map('n', '<leader>g', builtin.live_grep, {})
map('', '<leader>c', ':w! | !compiler "<c-r>%"<CR>')

View File

@ -1,10 +1,7 @@
g = vim.g
o = vim.o
au = vim.api.nvim_create_autocmd
bo = vim.bo
wo = vim.wo
o.backup = false
o.clipboard = 'unnamedplus'
o.completeopt = 'menu', 'menuone', 'noselect'
o.hlsearch = false
@ -26,10 +23,9 @@ o.splitright = true
o.swapfile = false
o.tabstop = 4
o.undofile = true
o.autochdir = true
wo.wrap = false
g.is_posix = 1
au({ 'BufWritePre' }, { pattern = { '*' }, command = [[%s/\n\+\%$//e]] })
au({ 'FileType' }, { pattern = { '*' }, command = [[setlocal formatoptions-=cro]] })

View File

@ -1,46 +0,0 @@
local actions = require('telescope.actions')
require('telescope').setup {
defaults = {
mappings = {
n = {
["Z"] = actions.select_horizontal,
["X"] = actions.select_vertical,
["C"] = actions.select_tab
},
},
},
pickers = {
buffers = {
ignore_current_buffer = true,
initial_mode = "normal",
previewer = false,
sort_lastused = true,
theme = "ivy",
mappings = {
n = {
["<c-x>"] = actions.delete_buffer,
},
},
layout_config = {
height = 10,
},
},
find_files = {
hidden = false,
initial_mode = "normal",
layout_strategies = "vertical",
theme = "ivy",
layout_config = {
height = 15,
},
},
live_grep = {
no_ignore = true,
theme = "ivy",
layout_config = {
height = 15,
},
},
},
}

View File

@ -1,9 +0,0 @@
local treesitter = require('nvim-treesitter.configs')
treesitter.setup({
auto_install = true,
highlight = {
enable = true,
},
indent = { enable = true },
})