feat nvim: migrate to mason and refactor

This commit is contained in:
vincent 2022-12-01 20:45:01 +01:00
parent ff48d339af
commit 41a931018e
21 changed files with 744 additions and 433 deletions

View File

@ -1,30 +1,9 @@
require('plugins') require('plugins')
require('options')
require('keymapping')
require('colorscheme')
require('plugins.lsp.mason')
vim.cmd([[
augroup packer_user_config
autocmd!
autocmd BufWritePost plugins.lua source <afile> | PackerCompile
augroup end
]])
-------------
-- Options --
-- ----------
vim.opt.completeopt = {'menuone', 'noinsert', 'noselect'} -- Completion options (for deoplete)
vim.opt.ignorecase = true
vim.opt.number = true
vim.opt.smartcase = true
vim.opt.mouse = 'a'
vim.opt.background = 'dark'
vim.opt.tabstop= 2
vim.opt.softtabstop = 2 vim.opt.shiftwidth= 2 vim.opt.expandtab = true
vim.opt.autoindent = true
vim.opt.copyindent= true
vim.opt.termguicolors = true
vim.cmd([[colorscheme gruvbox]])
--------------------- ---------------------
--Global Varialbles-- --Global Varialbles--
--------------------- ---------------------
@ -35,25 +14,3 @@ vim.g.easyescape_chars = {
k = 1 k = 1
} }
vim.g.easyescape_timeout = 100 vim.g.easyescape_timeout = 100
vim.g.python3_host_prog='/usr/bin/python3'
vim.g.python_host_prog='/usr/bin/python'
------------
--Mappings--
------------
vim.g.mapleader= ' '
-- Copy and paste with system clipboard
vim.api.nvim_set_keymap('v', '<C-c>', '"+y', {noremap = true})
vim.api.nvim_set_keymap('i', '<C-v>', '<C-r>+', {noremap = true})
vim.api.nvim_set_keymap('i', 'jk','<esc>', {noremap = true})
vim.api.nvim_set_keymap('i', 'kj','<esc>', {noremap = true})
vim.api.nvim_set_keymap('n', '<C-n>',':NvimTreeToggle<CR>', {noremap = true})
vim.api.nvim_set_keymap('n', '<leader>r',':NvimTreeRefresh<CR>', {noremap = true})
vim.api.nvim_set_keymap('n', '<leader>n',':NvimTreeFindFile<CR>', {noremap = true})
--vim.api.nvim_set_keymap('n', '<C-s>',':BufferLinePick<CR>', {noremap = true})
vim.api.nvim_set_keymap('c', 'w!!','w !sudo tee > /dev/null %', {noremap = true})

View File

@ -0,0 +1,2 @@
vim.cmd([[colorscheme gruvbox]])

View File

@ -0,0 +1,35 @@
-----------
--Mappings--
------------
local keymap = vim.keymap.set
local opts = { silent = true }
vim.g.mapleader= ' '
-- Copy and paste with system clipboard
keymap('v', '<C-c>', '"+y', opts)
keymap('i', '<C-v>', '<C-r>+', opts)
keymap('i', 'jk','<esc>', opts)
keymap('i', 'kj','<esc>', opts)
-- Normal --
-- -- Save and quit
keymap("n", "<C-s>", ":write<cr>", opts)
keymap("n", "<C-q>", ":quit<cr>", opts)
keymap('n', '<C-n>',':NvimTreeToggle<CR>', opts)
keymap('n', '<leader>r',':NvimTreeRefresh<CR>', opts)
keymap('n', '<leader>n',':NvimTreeFindFile<CR>', opts)
keymap("n", "<leader>e", ":NvimTreeToggle<CR>", opts)
-- Navigate buffers
keymap("n", "<C-l>", ":bnext<CR>", opts)
keymap("n", "<C-h>", ":bprevious<CR>", opts)
--keymap('n', '<C-s>',':BufferLinePick<CR>', opts)
--force sudo save
keymap('c', 'w!!','w !sudo tee > /dev/null %', opts)
require('plugins.markdown-preview')

View File

@ -0,0 +1,43 @@
-------------
-- Options --
-- ----------
vim.opt.backup = false -- creates a backup file
vim.opt.cmdheight = 1 -- more space in the neovim command line for displaying messages
vim.opt.completeopt = { "menuone", "noselect" } -- mostly just for cmp
vim.opt.conceallevel = 0 -- so that `` is visible in markdown files
vim.opt.fileencoding = "utf-8" -- the encoding written to a file
vim.opt.hlsearch = true -- highlight all matches on previous search pattern
vim.opt.ignorecase = true -- ignore case in search patterns
vim.opt.mouse = "a" -- allow the mouse to be used in neovim
vim.opt.pumheight = 10 -- pop up menu height
vim.opt.showmode = false -- we don't need to see things like -- INSERT -- anymore
vim.opt.showtabline = 0 -- always show tabs
vim.opt.smartcase = true -- smart case
vim.opt.smartindent = true -- make indenting smarter again
vim.opt.splitbelow = true -- force all horizontal splits to go below current window
vim.opt.splitright = true -- force all vertical splits to go to the right of current window
vim.opt.swapfile = false -- creates a swapfile
vim.opt.termguicolors = true -- set term gui colors (most terminals support this)
vim.opt.timeoutlen = 1000 -- time to wait for a mapped sequence to complete (in milliseconds)
vim.opt.undofile = true -- enable persistent undo
vim.opt.updatetime = 100 -- faster completion (4000ms default)
vim.opt.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
vim.opt.expandtab = true -- convert tabs to spaces
vim.opt.shiftwidth = 4 -- the number of spaces inserted for each indentation
vim.opt.tabstop = 4 -- insert 2 spaces for a tab
vim.opt.cursorline = true -- highlight the current line
vim.opt.number = true -- set numbered lines
vim.opt.relativenumber = true -- show relative line number
vim.opt.laststatus = 3 -- only the last window will always have a status line
vim.opt.showcmd = false -- hide (partial) command in the last line of the screen (for performance)
vim.opt.ruler = false -- hide the line and column number of the cursor position
vim.opt.numberwidth = 4 -- minimal number of columns to use for the line number {default 4}
vim.opt.signcolumn = "yes" -- always show the sign column, otherwise it would shift the text each time
vim.opt.wrap = false -- display lines as one long line
vim.opt.scrolloff = 3 -- minimal number of screen lines to keep above and below the cursor
vim.opt.sidescrolloff = 3 -- minimal number of screen columns to keep to the left and right of the cursor if wrap is `false`
vim.opt.shortmess:append("c") -- hide all the completion messages, e.g. "-- XXX completion (YYY)", "match 1 of 2", "The only match", "Pattern not found"
vim.opt.whichwrap:append("<,>,[,],h,l") -- keys allowed to move to the previous/next line when the beginning/end of line is reached

View File

@ -2,425 +2,174 @@
------------- -------------
-- Plugins -- -- Plugins --
------------- -------------
-- Autocommand that reloads neovim whenever you save the plugins.lua file
vim.cmd([[
augroup packer_user_config
autocmd!
autocmd BufWritePost plugins.lua source <afile> | PackerCompile
augroup end
]])
-- Auto install plugin manager -- Auto install plugin manager
local fn = vim.fn
local ensure_packer = function()
local fn = vim.fn local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then 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}) fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
vim.cmd [[packadd packer.nvim]]
return true
end end
return false
end
local packer_bootstrap = ensure_packer()
return require('packer').startup { return require('packer').startup {
function(use) function(use)
use {
'nvim-telescope/telescope.nvim',
requires = { {'nvim-lua/plenary.nvim'} }
}
use {
'nvim-telescope/telescope-fzf-native.nvim',
run = 'make',
config = function()
require('telescope').setup {
defaults = {
},
}
require('telescope').load_extension('fzf')
require'telescope.themes'.get_ivy()
vim.api.nvim_set_keymap("n", "<LEADER><LEADER>", ":Telescope find_files theme=get_ivy<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<LEADER>/", ":Telescope live_grep theme=get_ivy<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<LEADER>,", ":Telescope buffers theme=get_ivy<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<LEADER>?", ":Telescope current_buffer_fuzzy_find theme=get_ivy<CR>", { noremap = true })
end
}
use 'wbthomason/packer.nvim' use 'wbthomason/packer.nvim'
use { use {
'lewis6991/gitsigns.nvim', 'lewis6991/gitsigns.nvim',
requires = {
'nvim-lua/plenary.nvim'
},
config = function() config = function()
require('gitsigns').setup({ require('plugins.gitsign')
})
end end
} }
use 'ellisonleao/gruvbox.nvim' use 'ellisonleao/gruvbox.nvim'
-- Show indent line
use {
"lukas-reineke/indent-blankline.nvim",
config = function()
require('plugins.indent-blankline')
end
}
use 'zhou13/vim-easyescape' --LSP
use({ "https://github.com/neovim/nvim-lspconfig"})
use({ "https://github.com/williamboman/mason-lspconfig.nvim"})
use({ "https://github.com/williamboman/mason.nvim",
config= function()
end
})
use({ "https://github.com/jose-elias-alvarez/null-ls.nvim",
config= function()
require('plugins.lsp.null-ls')
end
})
use { use {
'iamcco/markdown-preview.nvim', 'iamcco/markdown-preview.nvim',
run = function() run = function()
vim.fn['mkdp#util#install'](0) vim.fn['mkdp#util#install'](0)
end, end,
ft = {
'markdown'
},
config = function() config = function()
vim.api.nvim_set_keymap('n', '<LEADER>mp', ':MarkdownPreviewToggle<CR>', {noremap = true, silent = true})
end
}
-- Fuzzy search
-- use {
-- 'junegunn/fzf.vim',
-- requires = {
-- 'junegunn/fzf'
-- },
-- config = function()
-- vim.g.fzf_buffers_jump = 1
-- vim.api.nvim_set_keymap('n', '<LEADER><TAB>', ':Buffers!<CR>', {noremap = true})
-- vim.api.nvim_set_keymap('n', '<LEADER>ff', ':Files!<CR>\'', {noremap = true})
-- vim.api.nvim_set_keymap('n', '<LEADER>f.', ':Files! '..vim.fn.expand('%:p:h'), {noremap = true})
-- vim.api.nvim_set_keymap('n', '<LEADER>f/', ':Rg!<CR>', {noremap = true})
-- vim.api.nvim_set_keymap('n', '<LEADER>fg', ':GFiles!<CR>', {noremap = true})
-- end
-- }
-- Show indent line
use {
"lukas-reineke/indent-blankline.nvim",
config = function()
require("indent_blankline").setup {
char = "",
show_first_indent_level = false,
show_trailing_blankline_indent = false,
}
end
}
-- Language server protocol
use {
'williamboman/nvim-lsp-installer',
requires = {
'neovim/nvim-lspconfig',
},
run = function()
local required_servers = {
"ansiblels",
"bashls",
"diagnosticls",
"dockerls",
"jsonls",
"pylsp",
"pyright",
"sqls",
"yamlls",
}
require "nvim-lsp-installer.ui.status-win"().open()
local lsp_installer_servers = require'nvim-lsp-installer.servers'
for _, required_server in pairs(required_servers) do
local _, server = lsp_installer_servers.get_server(required_server)
if not server:is_installed() then
server:install()
end
end
end,
config = function()
local lsp_installer = require("nvim-lsp-installer")
local enhance_server_opts = {
-- Provide settings that should only apply to the "eslintls" server
["ansiblels"] = function(opts)
opts.filetypes = {
"yaml.ansible"
}
end, end,
} }
lsp_installer.on_server_ready(function(server)
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
--Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
-- See `:help vim.lsp.*` for documentation on any of the below functions -- telescope
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts) use {
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts) 'nvim-telescope/telescope.nvim',
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<LEADER>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<LEADER>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<LEADER>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<LEADER>lD', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<LEADER>ln', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<LEADER>la', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<LEADER>le', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<LEADER>lq', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap('n', '<LEADER>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
local opts = {
on_attach = on_attach
} }
if enhance_server_opts[server.name] then use {
-- Enhance the default opts with the server-specific ones 'nvim-telescope/telescope-fzf-native.nvim',
enhance_server_opts[server.name](opts) run = 'make',
end config = function()
require ('plugins.telescope')
server:setup(opts)
vim.cmd [[ do User LspAttachBuffers ]]
end)
end end
} }
use {
'zhou13/vim-easyescape',
config = function()
require('plugins.vim-easyescape')
end
}
-- Autocomplete -- Autocomplete
use { use 'hrsh7th/cmp-nvim-lsp'
use 'hrsh7th/cmp-buffer'
use 'hrsh7th/cmp-cmdline'
use 'hrsh7th/cmp-path'
use 'hrsh7th/cmp-calc'
use 'hrsh7th/cmp-git'
use 'hrsh7th/cmp-nvim-lua'
use 'L3MON4D3/LuaSnip'
use 'rafamadriz/friendly-snippets'
use 'onsails/lspkind-nvim'
use({
'hrsh7th/nvim-cmp', 'hrsh7th/nvim-cmp',
requires = {
-- sources
'neovim/nvim-lspconfig',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-cmdline',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-path',
'hrsh7th/cmp-calc',
'hrsh7th/cmp-git',
-- snippets
'SirVer/ultisnips',
'honza/vim-snippets',
'quangnguyen30192/cmp-nvim-ultisnips',
config= function() config= function()
require("cmp_nvim_ultisnips").setup{} require('plugins.cmp')
end, end
-- pictograms })
'onsails/lspkind-nvim'
}, -- UI
use 'kyazdani42/nvim-web-devicons'
use {
'akinsho/bufferline.nvim',
config = function() config = function()
require('plugins.bufferline')
local cmp = require'cmp'
local cmp_ultisnips_mappings = require("cmp_nvim_ultisnips.mappings")
cmp.setup {
formatting = {
format = require'lspkind'.cmp_format(),
with_text = true,
},
snippet = {
expand = function(args)
vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
mapping = {
['<Tab>'] = cmp.mapping(
function(fallback)
cmp_ultisnips_mappings.expand_or_jump_forwards(fallback)
end,
{ 'i', 's', 'c' }
),
['<S-Tab>'] = cmp.mapping(
function(fallback)
cmp_ultisnips_mappings.jump_backwards(fallback)
end,
{ 'i', 's', 'c' }
),
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-y>'] = cmp.config.disable,
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
['<CR>'] = cmp.mapping.confirm({ select = false }),
},
sources = cmp.config.sources(
{
{ name = 'path' },
{ name = 'calc' },
{ name = 'nvim_lsp' },
{ name = 'ultisnips' },
},
{
{ name = 'buffer' },
}
)
}
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/`
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':'
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
end end
} }
-- use({'jose-elias-alvarez/null-ls.nvim',
-- config= function()
-- local lsp_formatting = function(bufnr)
-- vim.lsp.buf.format({
-- filter = function(clients)
-- -- filter out clients that you don't want to use
-- return vim.tbl_filter(function(client)
-- return client.name ~= "gopls"
-- end, clients)
-- end,
-- bufnr = bufnr,
-- })
-- end
--
-- -- if you want to set up formatting on save, you can use this as a callback
-- local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
--
-- require("null-ls").setup({
-- on_attach = function(client,bufnr)
-- if client.supports_method("textDocument/formatting") then
-- vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
-- vim.api.nvim_create_autocmd("BufWritePre", {
-- group = augroup,
-- buffer = bufnr,
-- callback = function()
-- lsp_formatting(bufnr)
-- end,
-- })
-- end
-- end,
-- sources = {
-- require("null-ls").builtins.formatting.prettier,
-- require("null-ls").builtins.formatting.trim_whitespace,
-- require("null-ls").builtins.formatting.trim_newlines,
-- require("null-ls").builtins.formatting.black,
-- require("null-ls").builtins.diagnostics.eslint,
-- },
-- })
-- end})
--
-- File manager
use({ use({
"kyazdani42/nvim-tree.lua", "kyazdani42/nvim-tree.lua",
requires = "kyazdani42/nvim-web-devicons",
config = function() config = function()
vim.api.nvim_set_keymap("n", "<leader>t", "<cmd>NvimTreeToggle<cr>", {}) require('plugins.nvim-tree')
require("nvim-tree").setup({
update_focused_file = {
enable = true,
},
view = {
width = 40,
},
})
end,
})
use({
"folke/which-key.nvim",
config = function()
vim.api.nvim_set_option("timeoutlen", 300)
require("which-key").setup({})
end, end,
}) })
use 'AckslD/nvim-whichkey-setup.lua' use 'AckslD/nvim-whichkey-setup.lua'
use({
"folke/which-key.nvim",
config = function()
require('plugins.which-key')
end,
})
use 'yamatsum/nvim-cursorline'
use 'freitass/todo.txt-vim'
--use 'freitass/todo.txt-vim'
use 'nvim-lua/plenary.nvim'
use { use {
'TimUntersberger/neogit', 'TimUntersberger/neogit',
requires = {
'nvim-lua/plenary.nvim'
},
keys = {
'<LEADER>gs'
},
cmd = {
'Neogit'
},
config = function() config = function()
require('neogit').setup { require('plugins.neogit')
disable_commit_confirmation = true,
disable_context_highlighting = true
}
vim.api.nvim_set_keymap('n', '<LEADER>gs', ':Neogit kind=split<CR>', {noremap = true})
end end
} }
use ({ use ({
'windwp/nvim-autopairs', 'windwp/nvim-autopairs',
config = function() config = function()
require('nvim-autopairs').setup{ require('plugins.autopairs')
fast_wrap= {},
}
end end
}) })
--treesitter
use 'RRethy/nvim-treesitter-endwise'
use({ use({
'nvim-treesitter/nvim-treesitter', 'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate',
config = function() config = function()
require'nvim-treesitter.configs'.setup { require('plugins.treesitter')
ensure_installed = "all",
highlight = {
enable = true
}
}
end end
}) })
use {
'akinsho/bufferline.nvim',
requires = {
'kyazdani42/nvim-web-devicons'
},
config = function()
require('bufferline').setup{
options = {
offsets = {
{
filetype = 'NvimTree',
text = 'File Explorer',
highlight = 'Directory',
text_align = 'left'
}
}
}
}
vim.api.nvim_set_keymap('n', '<C-l>', ':BufferLineCycleNext<CR>', {noremap = true})
vim.api.nvim_set_keymap('n', '<C-h>', ':BufferLineCyclePrev<CR>', {noremap = true})
end
}
use {'feline-nvim/feline.nvim', use {'feline-nvim/feline.nvim',
config = function() config = function()
require('feline').setup({}) require('feline').setup({})
end end
} }
use {'sheerun/vim-polyglot'}
if packer_bootstrap then if packer_bootstrap then
require('packer').sync() require('packer').sync()
end end

View File

@ -0,0 +1,33 @@
local status_ok, autopairs = pcall(require, "nvim-autopairs")
if not status_ok then
return
end
autopairs.setup({
check_ts = true, -- treesitter integration
disable_filetype = { "TelescopePrompt" },
ts_config = {
lua = { "string", "source" },
javascript = { "string", "template_string" },
java = false,
},
fast_wrap = {
map = "<M-e>",
chars = { "{", "[", "(", '"', "'" },
pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""),
offset = 0, -- Offset from pattern match
end_key = "$",
keys = "qwertyuiopzxcvbnmasdfghjkl",
check_comma = true,
highlight = "PmenuSel",
highlight_grey = "LineNr",
},
})
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
local cmp_status_ok, cmp = pcall(require, "cmp")
if not cmp_status_ok then
return
end
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({}))

View File

@ -0,0 +1,23 @@
local status_ok, bufferline = pcall(require, "bufferline")
if not status_ok then
return
end
bufferline.setup({
options = {
close_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions"
right_mouse_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions"
offsets = { { filetype = "NvimTree", text = "", padding = 1 } },
separator_style = "thin", -- | "thick" | "thin" | { 'any', 'any' },
offsets = {
{
filetype = 'NvimTree',
text = 'File Explorer',
highlight = 'Directory',
text_align = 'left'
}
}
},
})

View File

@ -0,0 +1,129 @@
local cmp_status_ok, cmp = pcall(require, "cmp")
if not cmp_status_ok then
return
end
local snip_status_ok, luasnip = pcall(require, "luasnip")
if not snip_status_ok then
return
end
require("luasnip/loaders/from_vscode").lazy_load()
local check_backspace = function()
local col = vim.fn.col(".") - 1
return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
end
local kind_icons = {
Text = "",
Method = "",
Function = "",
Constructor = "",
Field = "",
Variable = "",
Class = "",
Interface = "",
Module = "",
Property = "",
Unit = "",
Value = "",
Enum = "",
Keyword = "",
Snippet = "",
Color = "",
File = "",
Reference = "",
Folder = "",
EnumMember = "",
Constant = "",
Struct = "",
Event = "",
Operator = "",
TypeParameter = "",
}
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body) -- For `luasnip` users.
end,
},
mapping = cmp.mapping.preset.insert({
["<C-k>"] = cmp.mapping.select_prev_item(),
["<C-j>"] = cmp.mapping.select_next_item(),
["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
["<C-e>"] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
-- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items.
["<CR>"] = cmp.mapping.confirm({ select = false }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expandable() then
luasnip.expand()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif check_backspace() then
fallback()
else
fallback()
end
end, {
"i",
"s",
}),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {
"i",
"s",
}),
}),
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
vim_item.kind = kind_icons[vim_item.kind]
vim_item.menu = ({
nvim_lsp = "",
nvim_lua = "",
luasnip = "",
buffer = "",
path = "",
emoji = "",
})[entry.source.name]
return vim_item
end,
},
sources = {
{ name = "nvim_lsp" },
{ name = "nvim_lua" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
{ name = 'calc' },
},
confirm_opts = {
behavior = cmp.ConfirmBehavior.Replace,
select = false,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
experimental = {
ghost_text = true,
},
})

View File

@ -0,0 +1,7 @@
local status_ok, gitsigns = pcall(require, "gitsigns")
if not status_ok then
return
end
gitsigns.setup({
})

View File

@ -0,0 +1,12 @@
local status_ok, indent_blankline = pcall(require, "indent_blankline")
if not status_ok then
return
end
indent_blankline.setup {
char = "",
show_first_indent_level = false,
show_trailing_blankline_indent = false,
use_treesitter = true,
show_current_context = true,
}

View File

@ -0,0 +1,88 @@
local M = {}
local status_cmp_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
if not status_cmp_ok then
return
end
M.capabilities = vim.lsp.protocol.make_client_capabilities()
M.capabilities.textDocument.completion.completionItem.snippetSupport = true
M.capabilities = cmp_nvim_lsp.default_capabilities(M.capabilities)
M.setup = function()
local signs = {
{ name = "DiagnosticSignError", text = "" },
{ name = "DiagnosticSignWarn", text = "" },
{ name = "DiagnosticSignHint", text = "" },
{ name = "DiagnosticSignInfo", text = "" },
}
for _, sign in ipairs(signs) do
vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" })
end
local config = {
virtual_text = false, -- disable virtual text
signs = {
active = signs, -- show signs
},
update_in_insert = true,
underline = true,
severity_sort = true,
float = {
focusable = true,
style = "minimal",
border = "rounded",
source = "always",
header = "",
prefix = "",
},
}
vim.diagnostic.config(config)
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
border = "rounded",
})
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
border = "rounded",
})
end
local function lsp_keymaps(bufnr)
local opts = { noremap = true, silent = true }
local keymap = vim.api.nvim_buf_set_keymap
keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
keymap(bufnr, "n", "gI", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
keymap(bufnr, "n", "gl", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
keymap(bufnr, "n", "<leader>lf", "<cmd>lua vim.lsp.buf.format{async=true}<cr>", opts)
keymap(bufnr, "n", "<leader>li", "<cmd>LspInfo<cr>", opts)
keymap(bufnr, "n", "<leader>lI", "<cmd>LspInstallInfo<cr>", opts)
keymap(bufnr, "n", "<leader>la", "<cmd>lua vim.lsp.buf.code_action()<cr>", opts)
keymap(bufnr, "n", "<leader>lj", "<cmd>lua vim.diagnostic.goto_next({buffer=0})<cr>", opts)
keymap(bufnr, "n", "<leader>lk", "<cmd>lua vim.diagnostic.goto_prev({buffer=0})<cr>", opts)
keymap(bufnr, "n", "<leader>lr", "<cmd>lua vim.lsp.buf.rename()<cr>", opts)
keymap(bufnr, "n", "<leader>ls", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
keymap(bufnr, "n", "<leader>lq", "<cmd>lua vim.diagnostic.setloclist()<CR>", opts)
end
M.on_attach = function(client, bufnr)
if client.name == "tsserver" then
client.server_capabilities.document_formatting = false
end
lsp_keymaps(bufnr)
local status_ok, illuminate = pcall(require, "illuminate")
if not status_ok then
return
end
illuminate.on_attach(client)
end
return M

View File

@ -0,0 +1,60 @@
require("plugins.lsp.handlers").setup()
local servers = {
"ansiblels",
"bashls",
"cssls",
"dockerls",
"gopls",
"html",
"jsonls",
"pyright",
"pylsp",
"rnix",
"sumneko_lua",
"marksman",
"sqls",
"terraformls",
"tflint",
"tsserver",
"yamlls",
}
local settings = {
ui = {
border = "none",
icons = {
package_installed = "",
package_pending = "",
package_uninstalled = "",
},
},
log_level = vim.log.levels.INFO,
max_concurrent_installers = 4,
}
require("mason").setup(settings)
require("mason-lspconfig").setup({
ensure_installed = servers,
automatic_installation = true,
})
local lspconfig_status_ok, lspconfig = pcall(require, "lspconfig")
if not lspconfig_status_ok then
return
end
for _, server in pairs(servers) do
opts = {
on_attach = require("plugins.lsp.handlers").on_attach,
capabilities = require("plugins.lsp.handlers").capabilities,
}
server = vim.split(server, "@")[1]
local require_ok, conf_opts = pcall(require, "plugins.lsp.settings." .. server)
if require_ok then
opts = vim.tbl_deep_extend("force", conf_opts, opts)
end
lspconfig[server].setup(opts)
end

View File

@ -0,0 +1,27 @@
local null_ls_status_ok, null_ls = pcall(require, "null-ls")
if not null_ls_status_ok then
return
end
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting
local formatting = null_ls.builtins.formatting
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics
local diagnostics = null_ls.builtins.diagnostics
-- https://github.com/prettier-solidity/prettier-plugin-solidity
null_ls.setup({
debug = false,
sources = {
formatting.prettier.with({
extra_filetypes = { "toml" },
extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" },
}),
formatting.black.with({ extra_args = { "--fast" } }),
formatting.stylua,
formatting.google_java_format,
diagnostics.flake8,
diagnostics.eslint,
diagnostics.markdownlint,
},
})

View File

@ -0,0 +1,5 @@
return{
filetype= {
"yaml.ansible"
}
}

View File

@ -0,0 +1 @@
vim.keymap.set("n", "<leader>mp", ":MarkdownPreviewToggle<cr>", { silent = true })

View File

@ -0,0 +1,11 @@
local status_ok, neogit = pcall(require, "neogit")
if not status_ok then
return
end
neogit.setup{
disable_commit_confirmation = true,
disable_context_highlighting = true
}
vim.keymap.set('n', '<LEADER>gs', ':Neogit kind=split<CR>', {silent = true})

View File

@ -0,0 +1,38 @@
local status_ok, nvim_tree = pcall(require, "nvim-tree")
if not status_ok then
return
end
local config_status_ok, nvim_tree_config = pcall(require, "nvim-tree.config")
if not config_status_ok then
return
end
local tree_cb = nvim_tree_config.nvim_tree_callback
nvim_tree.setup({
update_focused_file = {
enable = true,
update_cwd = true,
},
diagnostics = {
enable = true,
show_on_dirs = true,
icons = {
hint = "",
info = "",
warning = "",
error = "",
},
},
view = {
width = 30,
side = "left",
mappings = {
list = {
{ key = { "l", "<CR>", "o" }, cb = tree_cb("edit") },
{ key = "h", cb = tree_cb("close_node") },
{ key = "v", cb = tree_cb("vsplit") },
},
},
},
})

View File

@ -0,0 +1,51 @@
local status_ok, telescope = pcall(require, "telescope")
if not status_ok then
return
end
local actions = require("telescope.actions")
local utils = require("telescope.utils")
telescope.setup {
defaults = {
path_display = { "absolute" },
file_ignore_patterns = { ".git/", "node_modules" },
mappings = {
i = {
["<Down>"] = actions.cycle_history_next,
["<Up>"] = actions.cycle_history_prev,
["<C-n>"] = actions.cycle_history_next,
["<C-p>"] = actions.cycle_history_prev,
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
},
},
},
extensions = {
fzf = {
fuzzy = true, -- false will only do exact matching
override_generic_sorter = true, -- override the generic sorter
override_file_sorter = true, -- override the file sorter
case_mode = "smart_case", -- or "ignore_case" or "respect_case"
-- the default case_mode is "smart_case"
},
},
pickers = {
find_files = {
no_ignore = true,
no_ignore_parent = true,
},
},
}
telescope.load_extension('fzf')
require'telescope.themes'.get_ivy()
local keymap = vim.keymap.set
local opts = { silent = true }
keymap("n", "<leader><leader>", ":Telescope git_files<CR>", opts)
keymap("n", "<leader>ff", ":Telescope find_files<CR>", opts)
keymap("n", "<leader>fF", function () builtin.find_files({ cwd = utils.buffer_dir() }) end, opts)
keymap("n", "<leader>/", ":Telescope live_grep<CR>", opts)
keymap("n", "<leader>pp", ":Telescope projects<CR>", opts)
keymap("n", "<leader>,", ":Telescope buffers<CR>", opts)

View File

@ -0,0 +1,33 @@
local status_ok, treesitter = pcall(require, "nvim-treesitter")
if not status_ok then
return
end
local status_ok, configs = pcall(require, "nvim-treesitter.configs")
if not status_ok then
return
end
configs.setup({
ensure_installed = {
all
},
highlight = {
enable = true,
},
autopairs = {
enable = true,
},
indent = {
enable = true,
},
context_commentstring = {
enable = true,
enable_autocmd = false,
},
endwise = {
enable = true,
},
})

View File

@ -0,0 +1,5 @@
vim.g.easyescape_chars = {
j = 0,
k = 0
}
vim.g.easyescape_timeout = 99

View File

@ -0,0 +1,2 @@
vim.api.nvim_set_option("timeoutlen", 300)
require("which-key").setup({})