mirror of
https://github.com/halfdan/dotfiles.git
synced 2025-09-10 19:56:24 +00:00
Refactor nvim config, thanks ThePrimeagen
This commit is contained in:
98
.config/nvim/after/plugin/cmp.lua
Normal file
98
.config/nvim/after/plugin/cmp.lua
Normal file
@@ -0,0 +1,98 @@
|
||||
local cmp = require'cmp'
|
||||
local lspkind = require('lspkind')
|
||||
local luasnip = require 'luasnip'
|
||||
|
||||
local source_mapping = {
|
||||
buffer = "[Buffer]",
|
||||
nvim_lsp = "[LSP]",
|
||||
nvim_lua = "[Lua]",
|
||||
cmp_tabnine = "[TN]",
|
||||
path = "[Path]",
|
||||
}
|
||||
|
||||
cmp.setup({
|
||||
-- snippet = {
|
||||
-- -- REQUIRED - you must specify a snippet engine
|
||||
-- expand = function(args)
|
||||
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
|
||||
-- -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
||||
-- -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
|
||||
-- -- require'snippy'.expand_snippet(args.body) -- For `snippy` users.
|
||||
-- end,
|
||||
-- },
|
||||
--mapping = {
|
||||
--['<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' }),
|
||||
--['<CR>'] = cmp.mapping.confirm({ select = true }),
|
||||
--},
|
||||
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 = false, -- only replace if explicitly selected
|
||||
},
|
||||
},
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'cmp_tabnine' },
|
||||
{ name = 'nvim_lsp' },
|
||||
}),
|
||||
formatting = {
|
||||
format = function(entry, vim_item)
|
||||
vim_item.kind = lspkind.presets.default[vim_item.kind]
|
||||
local menu = source_mapping[entry.source.name]
|
||||
if entry.source.name == 'cmp_tabnine' then
|
||||
if entry.completion_item.data ~= nil and entry.completion_item.data.detail ~= nil then
|
||||
menu = entry.completion_item.data.detail .. ' ' .. menu
|
||||
end
|
||||
vim_item.kind = '?'
|
||||
end
|
||||
vim_item.menu = menu
|
||||
return vim_item
|
||||
end
|
||||
}
|
||||
})
|
||||
|
||||
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
|
||||
cmp.setup.cmdline('/', {
|
||||
sources = {
|
||||
{ name = 'buffer' }
|
||||
}
|
||||
})
|
||||
|
||||
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
|
||||
cmp.setup.cmdline(':', {
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'path' }
|
||||
}, {
|
||||
{ name = 'cmdline' }
|
||||
})
|
||||
})
|
||||
|
||||
-- Setup tabnine
|
||||
local tabnine = require('cmp_tabnine.config')
|
||||
tabnine:setup({
|
||||
max_lines = 1000;
|
||||
max_num_results = 20;
|
||||
sort = true;
|
||||
run_on_every_keystroke = true;
|
||||
snippet_placeholder = '..';
|
||||
ignored_file_types = { -- default is not to ignore
|
||||
-- uncomment to ignore in lua:
|
||||
lua = true
|
||||
};
|
||||
})
|
||||
|
||||
-- Setup lspconfig.
|
||||
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
|
0
.config/nvim/after/plugin/init.lua
Normal file
0
.config/nvim/after/plugin/init.lua
Normal file
80
.config/nvim/after/plugin/keymappings.lua
Normal file
80
.config/nvim/after/plugin/keymappings.lua
Normal file
@@ -0,0 +1,80 @@
|
||||
local Remap = require("halfdan.keymap")
|
||||
local nnoremap = Remap.nnoremap
|
||||
local vnoremap = Remap.vnoremap
|
||||
local inoremap = Remap.inoremap
|
||||
local xnoremap = Remap.xnoremap
|
||||
local nmap = Remap.nmap
|
||||
|
||||
-- better window movement
|
||||
nnoremap('<C-h>', '<C-w>h')
|
||||
nnoremap('<C-j>', '<C-w>j')
|
||||
nnoremap('<C-k>', '<C-w>k')
|
||||
nnoremap('<C-l>', '<C-w>l')
|
||||
|
||||
-- resize with arrows
|
||||
nnoremap('<C-Up>', ':resize -2<CR>')
|
||||
nnoremap('<C-Down>', ':resize +2<CR>')
|
||||
nnoremap('<C-Left>', ':vertical resize -2<CR>')
|
||||
nnoremap('<C-Right>', ':vertical resize +2<CR>')
|
||||
|
||||
-- improved keyboard support for navigation (especially terminal)
|
||||
nnoremap('<leader>h', '<C-w>h')
|
||||
nnoremap('<leader>j', '<C-w>j')
|
||||
nnoremap('<leader>k', '<C-w>k')
|
||||
nnoremap('<leader>l', '<C-w>l')
|
||||
nnoremap('<A-h>', '<C-w>h')
|
||||
nnoremap('<A-j>', '<C-w>j')
|
||||
nnoremap('<A-k>', '<C-w>k')
|
||||
nnoremap('<A-l>', '<C-w>l')
|
||||
|
||||
-- Change 2 split windows from vert to horiz or horiz to vert
|
||||
nnoremap('<leader>th', '<C-w>t<C-w>H')
|
||||
nnoremap('<leader>tk', '<C-w>t<C-w>K')
|
||||
|
||||
-- Make adjusting split sizes a bit more friendly
|
||||
vim.cmd([[
|
||||
noremap <silent> <C-Left> :vertical resize +3<CR>
|
||||
noremap <silent> <C-Right> :vertical resize -3<CR>
|
||||
noremap <silent> <C-Up> :resize +3<CR>
|
||||
noremap <silent> <C-Down> :resize -3<CR>
|
||||
]])
|
||||
|
||||
-- better indenting
|
||||
vnoremap('<', '<gv')
|
||||
vnoremap('>', '>gv')
|
||||
|
||||
-- Tab switch buffer
|
||||
nnoremap('<TAB>', ':bnext<CR>')
|
||||
nnoremap('<S-TAB>', ':bprevious<CR>')
|
||||
|
||||
-- Move selected line / block of text in visual mode
|
||||
xnoremap('J', ':move \'>+1<CR>gv-gv')
|
||||
xnoremap('K', ':move \'<-2<CR>gv-gv')
|
||||
|
||||
nnoremap('Q', '<Nop>')
|
||||
|
||||
-- Tagbar
|
||||
nnoremap('<Leader>hl', ':nohl<CR>')
|
||||
|
||||
-- Vim Test
|
||||
nnoremap('<leader>t', ':TestNearest<CR>')
|
||||
nnoremap('<leader>T', ':TestFile<CR>')
|
||||
nnoremap('<leader>a', ':TestSuite<CR>')
|
||||
nnoremap('<leader>l', ':TestLast<CR>')
|
||||
nnoremap('<leader>g', ':TestVisit<CR>')
|
||||
|
||||
vim.cmd("nnoremap <silent> <C-p> :Lspsaga diagnostic_jump_prev<CR>")
|
||||
vim.cmd("nnoremap <silent> <C-n> :Lspsaga diagnostic_jump_next<CR>")
|
||||
-- -- scroll down hover doc or scroll in definition preview
|
||||
vim.cmd("nnoremap <silent> <C-f> <cmd>lua require('lspsaga.action').smart_scroll_with_saga(1)<CR>")
|
||||
-- -- scroll up hover doc
|
||||
vim.cmd("nnoremap <silent> <C-b> <cmd>lua require('lspsaga.action').smart_scroll_with_saga(-1)<CR>")
|
||||
vim.cmd('command! -nargs=0 LspVirtualTextToggle lua require("lsp/virtual_text").toggle()')
|
||||
|
||||
-- Yank until end of line
|
||||
nnoremap('Y', 'yg$')
|
||||
-- Next item, but center line
|
||||
nnoremap('n', 'nzzzv')
|
||||
nnoremap('N', 'Nzzzv')
|
||||
-- Join line but keep cursor intact
|
||||
nnoremap('J', 'mzJ`z')
|
164
.config/nvim/after/plugin/lsp.lua
Normal file
164
.config/nvim/after/plugin/lsp.lua
Normal file
@@ -0,0 +1,164 @@
|
||||
local Remap = require("halfdan.keymap")
|
||||
local nnoremap = Remap.nnoremap
|
||||
local inoremap = Remap.inoremap
|
||||
|
||||
-- TODO figure out why this don't work
|
||||
vim.fn.sign_define(
|
||||
"LspDiagnosticsSignError",
|
||||
{texthl = "LspDiagnosticsSignError", text = "", numhl = "LspDiagnosticsSignError"}
|
||||
)
|
||||
vim.fn.sign_define(
|
||||
"LspDiagnosticsSignWarning",
|
||||
{texthl = "LspDiagnosticsSignWarning", text = "", numhl = "LspDiagnosticsSignWarning"}
|
||||
)
|
||||
vim.fn.sign_define(
|
||||
"LspDiagnosticsSignHint",
|
||||
{texthl = "LspDiagnosticsSignHint", text = "", numhl = "LspDiagnosticsSignHint"}
|
||||
)
|
||||
vim.fn.sign_define(
|
||||
"LspDiagnosticsSignInformation",
|
||||
{texthl = "LspDiagnosticsSignInformation", text = "", numhl = "LspDiagnosticsSignInformation"}
|
||||
)
|
||||
|
||||
-- Set Default Prefix.
|
||||
-- Note: You can set a prefix per lsp server in the lv-globals.lua file
|
||||
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
|
||||
vim.lsp.diagnostic.on_publish_diagnostics, {
|
||||
virtual_text = {
|
||||
prefix = "",
|
||||
spacing = 1,
|
||||
},
|
||||
signs = true,
|
||||
underline = true,
|
||||
}
|
||||
)
|
||||
|
||||
local saga = require 'lspsaga'
|
||||
saga.init_lsp_saga({
|
||||
-- symbols in winbar
|
||||
symbol_in_winbar = true,
|
||||
winbar_file_format = function()
|
||||
return vim.fn.expand("%=%m %f")
|
||||
end,
|
||||
})
|
||||
|
||||
-- symbols for autocomplete
|
||||
vim.lsp.protocol.CompletionItemKind = {
|
||||
" (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)"
|
||||
}
|
||||
|
||||
local function documentHighlight(client, bufnr)
|
||||
-- Set autocommands conditional on server_capabilities
|
||||
if client.resolved_capabilities.document_highlight then
|
||||
vim.api.nvim_exec(
|
||||
[[
|
||||
hi LspReferenceRead cterm=bold ctermbg=red guibg=#464646
|
||||
hi LspReferenceText cterm=bold ctermbg=red guibg=#464646
|
||||
hi LspReferenceWrite cterm=bold ctermbg=red guibg=#464646
|
||||
augroup lsp_document_highlight
|
||||
autocmd! * <buffer>
|
||||
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
||||
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
||||
augroup END
|
||||
]],
|
||||
false
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
-- needed for the LSP to recognize elixir files (alternativly just use elixir-editors/vim-elixir)
|
||||
vim.cmd([[
|
||||
au BufRead,BufNewFile *.ex,*.exs set filetype=elixir
|
||||
au BufRead,BufNewFile *.eex,*.leex,*.sface set filetype=eelixir
|
||||
au BufRead,BufNewFile mix.lock set filetype=elixir
|
||||
]])
|
||||
|
||||
|
||||
|
||||
-- Diagnostic keymaps
|
||||
vim.api.nvim_set_keymap('n', '<leader>e', '<cmd>lua vim.diagnostic.open_float()<CR>', { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('n', '<leader>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', { noremap = true, silent = true })
|
||||
|
||||
-- LSP settings
|
||||
local lspconfig = require 'lspconfig'
|
||||
local function config(_config)
|
||||
return vim.tbl_deep_extend("force", {
|
||||
capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()),
|
||||
on_attach = function()
|
||||
-- local opts = { noremap = true, silent = true }
|
||||
nnoremap("gd", function() vim.lsp.buf.definition() end)
|
||||
nnoremap("gD", function() vim.lsp.buf.declaration() end)
|
||||
nnoremap("K", function() vim.lsp.buf.hover() end)
|
||||
nnoremap("<leader>vws", function() vim.lsp.buf.workspace_symbol() end)
|
||||
nnoremap("<leader>vd", function() vim.diagnostic.open_float() end)
|
||||
nnoremap("[d", function() vim.diagnostic.goto_next() end)
|
||||
nnoremap("]d", function() vim.diagnostic.goto_prev() end)
|
||||
nnoremap("<leader>vca", function() vim.lsp.buf.code_action() end)
|
||||
nnoremap("<leader>vrr", function() vim.lsp.buf.references() end)
|
||||
nnoremap("<leader>vrn", function() vim.lsp.buf.rename() end)
|
||||
inoremap("<C-h>", function() vim.lsp.buf.signature_help() end)
|
||||
--vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
||||
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>so', [[<cmd>lua require('telescope.builtin').lsp_document_symbols()<CR>]], opts)
|
||||
-- vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]]
|
||||
end,
|
||||
}, _config or {})
|
||||
end
|
||||
|
||||
lspconfig['elixirls'].setup{config({
|
||||
cmd = { "/Users/fbecker18/opt/elixir-ls/language_server.sh"}
|
||||
})}
|
||||
|
||||
-- Enable the following language servers
|
||||
local servers = { 'gopls', 'julials', 'rust_analyzer', 'pyright' }
|
||||
for _, lsp in ipairs(servers) do
|
||||
lspconfig[lsp].setup(config())
|
||||
end
|
||||
|
||||
require('rust-tools').setup({
|
||||
tools = {
|
||||
inlay_hints = {
|
||||
parameter_hints_prefix = "← ",
|
||||
other_hints_prefix = "➜ ",
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
--vim.cmd([[
|
||||
--augroup
|
||||
--autocmd!
|
||||
--autocmd BufWritePre *.go lua vim.lsp.buf.formatting_sync(nil, 100)
|
||||
--autocmd BufWritePre *.rs lua vim.lsp.buf.formatting_sync(nil, 100)
|
||||
--autocmd BufWritePre *.ex,*.exs lua vim.lsp.buf.formatting_sync(nil, 100)
|
||||
--autocmd BufWritePre *.py lua vim.lsp.buf.formatting_sync(nil, 100)
|
||||
--augroup END
|
||||
--]])
|
8
.config/nvim/after/plugin/sneak.lua
Normal file
8
.config/nvim/after/plugin/sneak.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
vim.cmd([[
|
||||
let g:sneak#label = 1
|
||||
let g:sneak#prompt = '🔎'
|
||||
let g:sneak#s_next = 1
|
||||
|
||||
let test#strategy = "neovim"
|
||||
let test#neovim#term_position = "vert rightbelow 50"
|
||||
]])
|
1
.config/nvim/after/plugin/tagbar.lua
Normal file
1
.config/nvim/after/plugin/tagbar.lua
Normal file
@@ -0,0 +1 @@
|
||||
vim.g.tagbar_ctags_bin = '/usr/local/bin/ctags'
|
32
.config/nvim/after/plugin/telescope.lua
Normal file
32
.config/nvim/after/plugin/telescope.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
local Remap = require("halfdan.keymap")
|
||||
local nnoremap = Remap.nnoremap
|
||||
|
||||
nnoremap("<leader>ps", function()
|
||||
require('telescope.builtin').grep_string({ search = vim.fn.input("Grep For > ")})
|
||||
end)
|
||||
nnoremap("<C-p>", function()
|
||||
require('telescope.builtin').git_files()
|
||||
end)
|
||||
nnoremap("<Leader>pf", function()
|
||||
require('telescope.builtin').find_files()
|
||||
end)
|
||||
|
||||
nnoremap("<leader>pw", function()
|
||||
require('telescope.builtin').grep_string { search = vim.fn.expand("<cword>") }
|
||||
end)
|
||||
nnoremap("<leader>pb", function()
|
||||
require('telescope.builtin').buffers()
|
||||
end)
|
||||
nnoremap("<leader>vh", function()
|
||||
require('telescope.builtin').help_tags()
|
||||
end)
|
||||
|
||||
-- Telescope
|
||||
-- nnoremap('<leader>fs', ':lua require(\'telescope.builtin\').grep_string({ search = vim.fn.input("Grep For > ")})<CR>')
|
||||
-- nnoremap('<Leader>ff', ':lua require(\'telescope.builtin\').find_files()<CR>')
|
||||
|
||||
-- nnoremap('<leader>fw', ':lua require(\'telescope.builtin\').grep_string { search = vim.fn.expand("<cword>") }<CR>')
|
||||
-- nnoremap('<leader>fb', ':lua require(\'telescope.builtin\').buffers()<CR>')
|
||||
-- nnoremap('<leader>vh', ':lua require(\'telescope.builtin\').help_tags()<CR>')
|
||||
-- nnoremap('<leader>gwl', ':lua require(\'telescope\').extensions.git_worktree.git_worktrees()<CR>')
|
||||
-- nnoremap('<leader>gwc', ':lua require(\'telescope\').extensions.git_worktree.create_git_worktree()<CR>')
|
Reference in New Issue
Block a user