nvim: big lua update

This commit is contained in:
2022-11-01 22:25:50 +02:00
parent 7d0760b1f1
commit 806db190c4
16 changed files with 357 additions and 158 deletions

View File

@@ -2,8 +2,6 @@
-- License: WTFPL
-- Description: Personal neovim configuration
vim.g.mapleader = ' '
require('builtins')
require('filetypes')
require('settings')

View File

@@ -15,7 +15,3 @@ vim.g.loaded_matchit = 1
vim.g.loaded_matchparen = 1
vim.g.loaded_logiPat = 1
vim.g.loaded_rrhelper = 1
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.g.loaded_netrwSettings = 1

View File

@@ -2,23 +2,22 @@ if not vim.filetype then
return
end
vim.g.did_load_filetypes = 0 -- deactivate vim based filetype detection
vim.g.do_filetype_lua = 1 -- enable
vim.filetype.add({
extension = {
lock = 'yaml',
},
filename = {
['.gitignore'] = 'conf',
['launch.json'] = 'jsonc',
Podfile = 'ruby',
Brewfile = 'ruby',
Vagrantfile = 'ruby',
},
pattern = {
['*.gradle'] = 'groovy',
['*.env.*'] = 'env',
},
})
-- vim.g.did_load_filetypes = 0 -- deactivate vim based filetype detection
-- vim.g.do_filetype_lua = 1 -- enable lua ft detection
--
-- vim.filetype.add({
-- extension = {
-- -- yml = 'yaml',
-- docker = 'dockerfile',
-- },
-- filename = {
-- ['.gitignore'] = 'conf',
-- Podfile = 'ruby',
-- Brewfile = 'ruby',
-- Vagrantfile = 'ruby',
-- },
-- pattern = {
-- ['*.gradle'] = 'groovy',
-- ['*.env.*'] = 'env',
-- },
-- })

View File

@@ -10,6 +10,8 @@ end
--- Mappings
-- Essentials
vim.g.mapleader = ' '
nmap(';', ':')
nmap(',,', '<C-^>')
nmap('<leader>w', ':w<CR>') -- TODO: stop this madness, :h autowrite
@@ -46,19 +48,21 @@ map('v', 'K', ':m \'<-2<CR>gv=gv')
map('v', '<', '<gv')
map('v', '>', '>gv')
-- fzf
nmap('<leader>ff', ':Files<CR>')
nmap('<leader>ft', ':Files ~/Tmp<CR>')
-- TODO: make the path relative to ~/Syncthing/Obsidian/Personal
nmap('<leader>fo', ":call fzf#run(fzf#wrap(fzf#vim#with_preview({ 'source': 'fd . --type f --extension=md --follow --exclude .git ~/Syncthing/Obsidian/Personal' })))<CR>", { silent = true })
-- Telescope
nmap('<leader>ff', ':lua require("telescope.builtin").find_files({ hidden = true })<CR>')
-- TODO: change to Telescope
-- nmap('<leader>ft', ':Files ~/Tmp<CR>')
-- nmap('<leader>fo', ":call fzf#run(fzf#wrap(fzf#vim#with_preview({ 'source': 'fd . --type f --extension=md --follow --exclude .git ~/Syncthing/Obsidian/Personal' })))<CR>", { silent = true })
-- vim-easy-align
map('x', 'ga', ':EasyAlign<CR>') -- TODO: this should allow for gaip, but does not
map('v', 'ga', ':EasyAlign<CR>')
-- nvim-tree.lua
nmap('<leader>n', ':NERDTreeToggle<CR>')
nmap('<leader>N', ':NERDTreeFind<CR>')
-- nmap('<leader>n', ':NERDTreeToggle<CR>')
-- nmap('<leader>N', ':NERDTreeFind<CR>')
nmap('<leader>n', ':NvimTreeToggle<CR>')
nmap('<leader>N', ':NvimTreeFindFile<CR>')
-- glow.vim
nmap('<leader>p', ':Glow<CR>')

View File

@@ -0,0 +1,63 @@
local cmp = require 'cmp'
local luasnip = require 'luasnip'
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
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
end,
},
window = {
-- completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
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" }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' }, -- For luasnip users.
}, {
{ name = 'buffer' },
})
})
-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
require('lspconfig')['solargraph'].setup({ capabilities = capabilities })
-- require("luasnip.loaders.from_lua").lazy_load()
require('luasnip').filetype_extend("ruby", {"rails"})
require('luasnip.loaders.from_vscode').lazy_load()

View File

@@ -0,0 +1 @@
require('Comment').setup()

View File

@@ -7,9 +7,8 @@ end
require('packer').startup(function()
use 'wbthomason/packer.nvim'
use 'arcticicestudio/nord-vim'
use 'shaunsingh/nord.nvim'
use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }
use 'tpope/vim-commentary'
use 'tpope/vim-surround'
use { 'junegunn/fzf', run = 'cd ~/.fzf && ./install --all' }
use 'junegunn/fzf.vim'
@@ -17,20 +16,23 @@ require('packer').startup(function()
use 'christoomey/vim-tmux-navigator'
use 'airblade/vim-gitgutter'
use 'tpope/vim-repeat'
use 'scrooloose/nerdtree' -- other file tree plugins are too fancy
use 'nvim-tree/nvim-tree.lua'
use 'numtostr/comment.nvim'
use 'ellisonleao/glow.nvim'
-- Snippets
use 'L3MON4D3/LuaSnip'
use 'hrsh7th/nvim-cmp'
use 'hrsh7th/cmp-nvim-lsp'
use 'saadparwaiz1/cmp_luasnip'
use 'rafamadriz/friendly-snippets'
use "rafamadriz/friendly-snippets"
use 'neovim/nvim-lspconfig'
-- tpope
use 'tpope/vim-fugitive'
use 'tpope/vim-rails'
use 'tpope/vim-rhubarb'
-- tests
use 'vim-test/vim-test'
@@ -38,25 +40,32 @@ require('packer').startup(function()
use 'dyng/ctrlsf.vim'
use 'nvim-lua/plenary.nvim'
use 'nvim-telescope/telescope.nvim'
-- Fuzzy Finder Algorithm which requires local dependencies to be built. Only load if `make` is available
use { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make', cond = vim.fn.executable "make" == 1 }
use { 'nvim-telescope/telescope.nvim', branch = '0.1.x', requires = { 'nvim-lua/plenary.nvim' } }
use "williamboman/mason.nvim"
use "WhoIsSethDaniel/mason-tool-installer.nvim"
use "jose-elias-alvarez/null-ls.nvim"
use({
"williamboman/mason-lspconfig.nvim",
requires = {
"neovim/nvim-lspconfig",
}
})
use 'AndrewRadev/splitjoin.vim'
end)
require 'plugins/treesitter'
require 'plugins/gitgutter'
require 'plugins/lsp'
require 'plugins/luasnip'
-- fzf
g.fzf_preview_window = ''
g.fzf_layout = { window = { width = 0.6, height = 0.6, border = 'sharp' } }
-- NERDTree
g.NERDTreeWinPos = "right"
g.NERDTreeMinimalUI = 1
g.NERDTreeDirArrows = 1
g.NERDTreeAutoDeleteBuffer = 1
g.NERDTreeHijackNetrw = 1
require 'plugins/cmp'
require 'plugins/nord'
require 'plugins/nvim-tree'
require 'plugins/comment'
require 'plugins/mason'
require 'plugins/null-ls'
require 'plugins/telescope'
-- vim-test
g['test#strategy'] = 'vimux'
@@ -73,7 +82,3 @@ g.ctrlsf_mapping = {
next = 'n',
prev = 'N',
}
-- fzf
g.fzf_preview_window = ''
g.fzf_layout = { window = { width = 0.6, height = 0.6, border = 'sharp' } }

View File

@@ -1,77 +1,47 @@
----------- LSP
require'lspconfig'.solargraph.setup{}
local nvim_lsp = require('lspconfig')
require("mason-lspconfig").setup()
local lspconfig = require('lspconfig')
lspconfig.ansiblels.setup({})
lspconfig.bashls.setup({})
lspconfig.dockerls.setup({})
lspconfig.gopls.setup({})
lspconfig.jsonls.setup({})
lspconfig.solargraph.setup({})
lspconfig.marksman.setup({})
lspconfig.terraformls.setup({})
lspconfig.vimls.setup({})
lspconfig.pylsp.setup({})
lspconfig.yamlls.setup({})
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
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
-- Provide settings that should only apply to the "sumneko_lua" server
local lua_runtime_path = vim.split(package.path, ';')
table.insert(lua_runtime_path, "lua/?.lua")
table.insert(lua_runtime_path, "lua/?/init.lua")
table.insert(lua_runtime_path, vim.fn.stdpath('config') .. "lua/?.lua")
-- 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
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', '<space>=', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'solargraph' }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
lspconfig.sumneko_lua.setup({
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT',
-- Setup your lua path
path = lua_runtime_path,
},
format = {
enable = true,
defaultConfig = {
keep_one_space_between_table_and_bracket = "false",
}
}
end
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = {'vim'},
["codestyle-check"] = "Any",
},
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '')
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-jump-prev', true, true, true), '')
else
fallback()
end
end,
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}
})

View File

@@ -0,0 +1,11 @@
require("mason").setup({})
require("mason-tool-installer").setup({
-- https://github.com/williamboman/mason-lspconfig.nvim/blob/main/doc/server-mapping.md
ensure_installed = { "bash-language-server", "black", "dockerfile-language-server",
"isort", "json-lsp", "jsonlint", "lua-language-server", "marksman", "prettierd",
"python-lsp-server", "rubocop", "shfmt", "solargraph", "terraform-ls",
"vim-language-server", "yaml-language-server",
},
auto_update = true,
run_on_start = true
})

View File

@@ -0,0 +1,30 @@
-- https://github.com/shaunsingh/nord.nvim#%EF%B8%8F-configuration
-- Make sidebars and popup menus like nvim-tree and telescope
-- have a different background
vim.g.nord_contrast = true
-- Enable the border between verticaly split windows visable
vim.g.nord_borders = true
-- Disable the setting of background color so that NeoVim
-- can use your terminal background
vim.g.nord_disable_background = false
-- Set the cursorline transparent/visible
vim.g.nord_cursorline_transparent = false
-- Re-enables the background of the sidebar if you disabled the background of everything
vim.g.nord_enable_sidebar_background = false
-- Enables/disables italics
vim.g.nord_italic = true
-- Enables/disables colorful backgrounds when used in diff mode
vim.g.nord_uniform_diff_background = true
-- Enables/disables bold
vim.g.nord_bold = false
-- Load the colorscheme
require('nord').set()

View File

@@ -0,0 +1,29 @@
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
require("null-ls").setup({
sources = {
require("null-ls").builtins.formatting.jq,
require("null-ls").builtins.formatting.gofmt,
require("null-ls").builtins.formatting.prettierd,
require("null-ls").builtins.formatting.terraform_fmt,
require("null-ls").builtins.diagnostics.jsonlint,
},
-- you can reuse a shared lspconfig on_attach callback here
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()
vim.lsp.buf.format({
bufnr = bufnr,
async = false,
filter = function(client)
return client.name == "null-ls"
end
})
end,
})
end
end,
})

View File

@@ -0,0 +1,14 @@
require("nvim-tree").setup({
sort_by = "case_sensitive",
renderer = {
icons = {
show = {
file = false,
folder = false,
folder_arrow = false,
git = false,
}
},
group_empty = true,
}
})

View File

@@ -0,0 +1,2 @@
-- Enable telescope fzf native, if installed
pcall(require('telescope').load_extension, 'fzf')

View File

@@ -6,7 +6,22 @@ require('nvim-treesitter.configs').setup {
'javascript', 'json', 'kotlin', 'latex', 'lua', 'make', 'markdown', 'perl', 'php',
'python', 'ruby', 'rust', 'scss', 'swift', 'toml', 'tsx', 'vim', 'vue', 'yaml' },
-- ignore_install = { 'norg' },
highlight = { enable = true },
indent = { enable = true },
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
context_commentstring = {
enable = true,
enable_autocmd = false,
},
rainbow = {
enable = true,
disable = { "html" },
extended_mode = false,
max_file_lines = nil,
},
indent = { enable = false },
autopairs = { enable = true },
autotag = { enable = true },
incremental_selection = { enable = true },
}

View File

@@ -12,6 +12,7 @@ cmd('au TextYankPost * lua vim.highlight.on_yank { timeout = 250 }')
cmd('colorscheme nord')
opt.smartindent = true -- Autoindenting when starting a new line
opt.completeopt = {'menu', 'menuone', 'noselect'}
opt.tabstop = 2 -- Tab counts as 2 columns
opt.shiftwidth = 2 -- Numbers of spaces to (auto)indent
opt.expandtab = true -- Tabs to spaces
@@ -47,6 +48,8 @@ opt.listchars = { trail = '·', tab = '->' }
opt.timeoutlen = 1000 -- Delay for mappings
opt.ttimeoutlen = 0 -- Delay between modes
opt.shellcmdflag = '-ic' -- Enables aliases from .bashrc in :! commands
opt.termguicolors = true -- 24-bit RGB color
if vim.fn.executable('rg') > 0 then
vim.o.grepprg = [[rg --glob "!.git" --no-heading --vimgrep --follow $*]]

View File

@@ -9,6 +9,9 @@ vim.api.nvim_command('packadd packer.nvim')
local no_errors, error_msg = pcall(function()
_G._packer = _G._packer or {}
_G._packer.inside_compile = true
local time
local profile_info
local should_profile = false
@@ -38,8 +41,10 @@ local function save_profiles(threshold)
results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms'
end
end
if threshold then
table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)')
end
_G._packer = _G._packer or {}
_G._packer.profile_output = results
end
@@ -74,11 +79,21 @@ _G.packer_plugins = {
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/LuaSnip",
url = "https://github.com/L3MON4D3/LuaSnip"
},
["cmp-nvim-lsp"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp",
url = "https://github.com/hrsh7th/cmp-nvim-lsp"
},
cmp_luasnip = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/cmp_luasnip",
url = "https://github.com/saadparwaiz1/cmp_luasnip"
},
["comment.nvim"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/comment.nvim",
url = "https://github.com/numtostr/comment.nvim"
},
["ctrlsf.vim"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/ctrlsf.vim",
@@ -104,15 +119,30 @@ _G.packer_plugins = {
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/glow.nvim",
url = "https://github.com/ellisonleao/glow.nvim"
},
nerdtree = {
["mason-lspconfig.nvim"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/nerdtree",
url = "https://github.com/scrooloose/nerdtree"
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim",
url = "https://github.com/williamboman/mason-lspconfig.nvim"
},
["nord-vim"] = {
["mason-tool-installer.nvim"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/nord-vim",
url = "https://github.com/arcticicestudio/nord-vim"
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/mason-tool-installer.nvim",
url = "https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim"
},
["mason.nvim"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/mason.nvim",
url = "https://github.com/williamboman/mason.nvim"
},
["nord.nvim"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/nord.nvim",
url = "https://github.com/shaunsingh/nord.nvim"
},
["null-ls.nvim"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/null-ls.nvim",
url = "https://github.com/jose-elias-alvarez/null-ls.nvim"
},
["nvim-cmp"] = {
loaded = true,
@@ -124,6 +154,11 @@ _G.packer_plugins = {
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/nvim-lspconfig",
url = "https://github.com/neovim/nvim-lspconfig"
},
["nvim-tree.lua"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/nvim-tree.lua",
url = "https://github.com/nvim-tree/nvim-tree.lua"
},
["nvim-treesitter"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/nvim-treesitter",
@@ -139,16 +174,24 @@ _G.packer_plugins = {
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/plenary.nvim",
url = "https://github.com/nvim-lua/plenary.nvim"
},
["splitjoin.vim"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/splitjoin.vim",
url = "https://github.com/AndrewRadev/splitjoin.vim"
},
["telescope-fzf-native.nvim"] = {
cond = { true },
loaded = false,
needs_bufread = false,
only_cond = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/opt/telescope-fzf-native.nvim",
url = "https://github.com/nvim-telescope/telescope-fzf-native.nvim"
},
["telescope.nvim"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/telescope.nvim",
url = "https://github.com/nvim-telescope/telescope.nvim"
},
["vim-commentary"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/vim-commentary",
url = "https://github.com/tpope/vim-commentary"
},
["vim-easy-align"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/vim-easy-align",
@@ -174,6 +217,11 @@ _G.packer_plugins = {
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/vim-repeat",
url = "https://github.com/tpope/vim-repeat"
},
["vim-rhubarb"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/vim-rhubarb",
url = "https://github.com/tpope/vim-rhubarb"
},
["vim-surround"] = {
loaded = true,
path = "/Users/madundead/.local/share/nvim/site/pack/packer/start/vim-surround",
@@ -197,6 +245,17 @@ _G.packer_plugins = {
}
time([[Defining packer_plugins]], false)
-- Conditional loads
time([[Conditional loading of telescope-fzf-native.nvim]], true)
require("packer.load")({"telescope-fzf-native.nvim"}, {}, _G.packer_plugins)
time([[Conditional loading of telescope-fzf-native.nvim]], false)
_G._packer.inside_compile = false
if _G._packer.needs_bufread == true then
vim.cmd("doautocmd BufRead")
end
_G._packer.needs_bufread = false
if should_profile then save_profiles() end
end)