Last active
August 8, 2022 19:06
-
-
Save urandom/26aa85a1e4d5fe425c926fe11dd6eb25 to your computer and use it in GitHub Desktop.
init.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Install paq | |
local execute = vim.api.nvim_command | |
local install_path = vim.fn.stdpath('data') .. '/site/pack/paqs/start/paq-nvim' | |
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then | |
execute('!git clone --depth 1 https://github.com/savq/paq-nvim.git ' .. install_path) | |
end | |
require('paq') { | |
'savq/paq-nvim'; -- Package manager | |
'tpope/vim-fugitive'; -- Git commands in nvim | |
'tpope/vim-commentary'; -- "gc" to comment visual regions/lines | |
'AndrewRadev/linediff.vim'; | |
'akinsho/nvim-toggleterm.lua'; | |
-- Shared libraries | |
'nvim-lua/popup.nvim'; | |
'nvim-lua/plenary.nvim'; | |
'kyazdani42/nvim-web-devicons'; | |
{ | |
'nvim-telescope/telescope-fzy-native.nvim', | |
run = 'cd deps/fzy-lua-native && make', | |
}; | |
'nvim-telescope/telescope.nvim'; -- Fuzzy finder, requires plenary | |
'ThePrimeagen/git-worktree.nvim'; -- Git worktree, uses telescope | |
'kyazdani42/nvim-tree.lua'; -- File tree, uses devicons | |
'lewis6991/gitsigns.nvim'; -- Git status signs column, requires plenary | |
'kevinhwang91/nvim-bqf'; -- Better quickfix | |
'folke/which-key.nvim'; -- Mapping legend | |
'simnalamburt/vim-mundo'; -- Undo tree | |
'gennaro-tedesco/nvim-jqx'; -- JSON prettifier using jq | |
'vim-test/vim-test'; -- Test runner helpers | |
-- Colorschemes | |
'sainnhe/edge'; | |
'projekt0n/github-nvim-theme'; | |
'Mofiqul/adwaita.nvim'; | |
'nvim-treesitter/nvim-treesitter'; | |
'nvim-treesitter/nvim-treesitter-textobjects'; | |
'nvim-treesitter/playground'; | |
'p00f/nvim-ts-rainbow'; -- Colored brackets, requires treesitter | |
'lukas-reineke/indent-blankline.nvim'; -- Indentation gude, requires treesitter | |
'RRethy/nvim-treesitter-textsubjects'; -- Textsubject selection, requires treesitter | |
'windwp/nvim-ts-autotag'; -- Autotag completion, requires treesitter | |
'neovim/nvim-lspconfig'; -- LSP | |
'j-hui/fidget.nvim'; -- lsp status, requires lsp | |
'SmiteshP/nvim-gps'; -- Cursor location, requires treesitter, lsp | |
'stevearc/aerial.nvim'; -- Outline, requires lsp | |
'hoob3rt/lualine.nvim'; -- Statusline, requires gps | |
'rafamadriz/friendly-snippets'; | |
'L3MON4D3/LuaSnip'; -- Snippet engine, requires friendly snippets | |
-- Autocompletion | |
'hrsh7th/cmp-nvim-lsp'; -- LSP integration, requires lsp | |
'saadparwaiz1/cmp_luasnip'; -- Snippet integration, requires luasnip | |
'hrsh7th/cmp-path'; | |
'hrsh7th/cmp-buffer'; | |
--'hrsh7th/cmp-cmdline'; -- Autocompletion for command line | |
'hrsh7th/nvim-cmp'; -- Autocompletion engine, requires the above | |
'windwp/nvim-autopairs'; -- Bracket completion, requires cmp | |
'ray-x/go.nvim'; -- Go-specific commands | |
'mfussenegger/nvim-jdtls'; -- Java-specific commands | |
'mfussenegger/nvim-dap'; -- Debugger | |
'leoluz/nvim-dap-go' -- Go debugging extension, requires DAP | |
} | |
--Set highlight on search | |
vim.opt.hlsearch = true | |
vim.opt.incsearch = true | |
--Make line numbers default | |
vim.opt.number = true | |
vim.opt.relativenumber = true | |
--Enable mouse mode | |
vim.opt.mouse = "a" | |
--Save undo history | |
vim.opt.undofile = true | |
-- Do not expand tabs by default | |
vim.opt.expandtab = true | |
--Case insensitive searching UNLESS /C or capital in search | |
vim.opt.ignorecase = true | |
vim.opt.smartcase = true | |
vim.opt.shiftwidth = 4 | |
vim.opt.tabstop = 4 | |
--Decrease update time | |
vim.opt.updatetime = 250 | |
vim.opt.signcolumn = "yes" | |
vim.opt.termguicolors = true | |
vim.opt.guifont = "Fira Code:h12" | |
vim.opt.cursorline = true | |
vim.opt.pumblend = 20 | |
vim.opt.showbreak = "=> " | |
vim.opt.clipboard = { "unnamed" } | |
vim.opt.shortmess:append { c = true, A = true } | |
vim.opt.wildmode = "longest:full" | |
vim.opt.wildignore:append { "*.o", "*.obj", "*.jpg", "*.gif", "*.png", "*.jar", "*.zip", "*.jpeg", "*.tif*", "*.exe", | |
"*.jpe", "*.pdf", "*.doc", "*.mo", "*.svg", "*.cache", "*.mp4", "*.class", "*.a" } | |
-- make :grep use rg | |
vim.opt.grepprg = "rg --vimgrep --no-heading" | |
vim.opt.grepformat = "%f:%l:%c:%m" | |
vim.opt.shada:append { "%" } | |
vim.opt.showtabline = 2 | |
-- Set completeopt to have a better completion experience | |
vim.opt.completeopt = { "menu", "menuone", "noinsert" } | |
-- Highlight on yank | |
local yank_hl_group = vim.api.nvim_create_augroup('YankHighlight', { | |
clear = true, | |
}) | |
vim.api.nvim_create_autocmd('TextYankPost', { | |
callback = function() | |
vim.highlight.on_yank() | |
end, | |
group = yank_hl_group, | |
pattern = '*', | |
}) | |
-- go to last remembered position | |
vim.api.nvim_create_autocmd('BufReadPost', { | |
callback = function() | |
if vim.fn.line([['"]]) > 1 and vim.fn.line([['"]]) <= vim.fn.line("$") then | |
vim.api.nvim_exec([[ | |
normal! g'" | |
]], false) | |
end | |
end, | |
pattern = '*', | |
}) | |
-- autoformatting | |
local lsp_hl_group = vim.api.nvim_create_augroup('lsp', { | |
clear = true, | |
}) | |
vim.api.nvim_create_autocmd('BufWritePre', { | |
callback = function() | |
vim.lsp.buf.formatting_sync() | |
end, | |
group = lsp_hl_group, | |
pattern = '<buffer>', | |
}) | |
-- save session | |
vim.api.nvim_create_autocmd('VimLeave', { | |
callback = function() | |
if not vim.fn.empty("v:this_session") then | |
vim.api.nvim_exec([["mksession! "]] .. vim.v.this_session, false) | |
end | |
end, | |
pattern = '*', | |
}) | |
-- git editor handling using github.com/mhinz/neovim-remote | |
vim.api.nvim_create_autocmd('FileType', { | |
callback = function() | |
vim.bo.bufhidden = 'delete' | |
end, | |
pattern = 'gitcommit,gitrebase,gitconfig', | |
}) | |
if vim.fn.executable('nvr') then | |
vim.env.GIT_EDITOR = 'nvr -cc split --remote-wait' | |
end | |
--Remap for dealing with word wrap | |
vim.api.nvim_set_keymap('n', 'k', "v:count == 0 ? 'gk' : 'k'", { noremap = true, expr = true, silent = true }) | |
vim.api.nvim_set_keymap('n', 'j', "v:count == 0 ? 'gj' : 'j'", { noremap = true, expr = true, silent = true }) | |
--Remap escape to leave terminal mode | |
vim.keymap.set('t', '<Esc><Esc>', [[<c-\><c-n>]]) | |
-- next/prev buffer | |
vim.keymap.set('n', 'gb', [[:bn<CR>]]) | |
vim.keymap.set('n', 'gB', [[:bp<CR>]]) | |
-- expand %/ to the current path in cmd | |
vim.keymap.set('c', '%/', [[<C-R>=expand("%:p:h") . '/'<CR>]]) | |
vim.keymap.set('n', '<ESC>', [[<ESC>:noh<CR>]], { silent = true }) | |
-- Show diagnostic popup on hover | |
local diagnostic_float_group = vim.api.nvim_create_augroup('diagnostic_float', { | |
clear = false, | |
}) | |
vim.api.nvim_create_autocmd('CursorHold', { | |
callback = function() | |
vim.diagnostic.open_float({ border = 'rounded', focus = false }) | |
end, | |
pattern = '<buffer>', | |
group = diagnostic_float_group, | |
}) | |
local function configTelescope() | |
local telescope = require('telescope') | |
telescope.load_extension('fzy_native') | |
telescope.setup { | |
defaults = { | |
-- generic_sorter = require'telescope.sorters'.get_fzy_sorter, | |
-- file_sorter = require'telescope.sorters'.get_fzy_sorter, | |
file_previewer = require 'telescope.previewers'.vim_buffer_cat.new, | |
grep_previewer = require 'telescope.previewers'.vim_buffer_vimgrep.new, | |
qflist_previewer = require 'telescope.previewers'.vim_buffer_qflist.new, | |
winblend = 10, | |
color_devicons = true, | |
}, extensions = { | |
fzy_native = { | |
override_generic_sorter = false, | |
override_file_sorter = true, | |
} | |
}, | |
} | |
vim.keymap.set('n', '<F3>', function() | |
require 'telescope.builtin'.buffers {} | |
end) | |
vim.keymap.set('n', '<F4>', function() | |
require 'telescope.builtin'.oldfiles {} | |
end) | |
vim.keymap.set('n', '<C-p>', function() | |
require 'telescope.builtin'.find_files {} | |
end) | |
vim.keymap.set('n', '<leader>l', function() | |
require 'telescope.builtin'.current_buffer_fuzzy_find {} | |
end, { silent = true }) | |
vim.keymap.set('n', '<leader>t', function() | |
require 'telescope.builtin'.tags {} | |
end, { silent = true }) | |
vim.keymap.set('n', '<leader>o', function() | |
require 'telescope.builtin'.tags { only_current_buffer = true } | |
end, { silent = true }) | |
vim.keymap.set('n', 'gF', function() | |
require('telescope.builtin').grep_string {} | |
end, { silent = true }) | |
vim.keymap.set('n', 'gG', function() | |
require('telescope.builtin').live_grep {} | |
end, { silent = true }) | |
vim.keymap.set('n', '<leader>gc', function() | |
require('telescope.builtin').git_commits {} | |
end, { silent = true }) | |
vim.keymap.set('n', '<leader>gb', function() | |
require('telescope.builtin').git_branches {} | |
end, { silent = true }) | |
vim.keymap.set('n', '<leader>gs', function() | |
require('telescope.builtin').git_status {} | |
end, { silent = true }) | |
vim.keymap.set('n', '<leader>gp', function() | |
require('telescope.builtin').git_bcommits {} | |
end, { silent = true }) | |
end | |
local function configGitWorktree() | |
require("git-worktree").setup {} | |
require("telescope").load_extension("git_worktree") | |
vim.keymap.set('n', '<leader>gwl', function() | |
require('telescope').extensions.git_worktree.git_worktrees {} | |
end, { silent = true }) | |
vim.keymap.set('n', '<leader>gwc', function() | |
require('telescope').extensions.git_worktree.create_git_worktree {} | |
end, { silent = true }) | |
end | |
local function configDevIcons() | |
require 'nvim-web-devicons'.setup() | |
end | |
local function configNVimTree() | |
require 'nvim-tree'.setup { | |
diagnostics = { | |
enable = true, | |
show_on_dirs = true, | |
}, | |
update_focused_file = { | |
enable = true, | |
}, | |
} | |
vim.keymap.set('n', '<F5>', function() | |
require 'nvim-tree'.toggle(false) | |
end, { silent = false }) | |
end | |
local function configColorscheme() | |
vim.opt.background = 'light' | |
-- vim.g.edge_diagnostic_virtual_text = 'colored' | |
-- vim.cmd[[colorscheme edge]] | |
-- vim.opt.background = 'light' | |
-- require('github-theme').setup { | |
-- theme_style = "light", | |
-- } | |
-- vim.api.nvim_exec([[ | |
-- highlight LspSignatureActiveParameter gui=bold | |
-- ]], false) | |
vim.g.adwaita_mode = "light" | |
vim.cmd([[colorscheme adwaita]]) | |
vim.api.nvim_exec([[ | |
highlight LspSignatureActiveParameter gui=bold | |
]], false) | |
end | |
local function configGps() | |
require("nvim-gps").setup() | |
end | |
local function configLualine() | |
local gps = require("nvim-gps") | |
local function strip_str(len) | |
return function(str) | |
if str then | |
return str:sub(1, len) | |
end | |
return "" | |
end | |
end | |
require('lualine').setup { | |
options = { | |
theme = 'auto', | |
}, | |
sections = { | |
lualine_b = { { 'branch', fmt = strip_str(15) }, 'diff', { 'diagnostics', sources = { 'nvim_diagnostic' } } }, | |
lualine_c = { 'filename', { gps.get_location, cond = gps.is_available }, } | |
} | |
} | |
end | |
local function configOutline() | |
require('aerial').setup { | |
backends = { 'lsp' }, | |
} | |
vim.keymap.set('n', '<F2>', function() | |
require 'aerial'.toggle {} | |
end) | |
end | |
local function configIndentBlanklines() | |
vim.g.indent_blankline_use_treesitter = true | |
vim.g.indent_blankline_show_current_context = true | |
vim.g.indent_blankline_filetype_exclude = { 'help', 'packer' } | |
vim.g.indent_blankline_buftype_exclude = { 'terminal', 'nofile' } | |
end | |
local function configGitSigns() | |
require('gitsigns').setup {} | |
end | |
local function configTreesitter() | |
require 'nvim-treesitter.configs'.setup { | |
ensure_installed = { | |
"bash", "c", "cpp", "css", "dockerfile", "go", "html", | |
"java", "javascript", "json", "kotlin", "lua", "rust", "typescript", "yaml", | |
}, | |
highlight = { enable = true }, | |
textobjects = { | |
select = { | |
enable = true, | |
-- Automatically jump forward to textobj, similar to targets.vim | |
lookahead = true, | |
keymaps = { | |
-- You can use the capture groups defined in textobjects.scm | |
["af"] = "@function.outer", | |
["if"] = "@function.inner", | |
["ac"] = "@class.outer", | |
["ic"] = "@class.inner", | |
}, | |
}, | |
swap = { | |
enable = true, | |
swap_next = { | |
["<leader>a"] = "@parameter.inner", | |
}, | |
swap_previous = { | |
["<leader>A"] = "@parameter.inner", | |
}, | |
}, | |
move = { | |
enable = true, | |
set_jumps = true, -- whether to set jumps in the jumplist | |
goto_next_start = { | |
["]m"] = "@function.outer", | |
["]]"] = "@class.outer", | |
}, | |
goto_next_end = { | |
["]M"] = "@function.outer", | |
["]["] = "@class.outer", | |
}, | |
goto_previous_start = { | |
["[m"] = "@function.outer", | |
["[["] = "@class.outer", | |
}, | |
goto_previous_end = { | |
["[M"] = "@function.outer", | |
["[]"] = "@class.outer", | |
}, | |
}, | |
}, | |
textsubjects = { | |
enable = true, | |
prev_selection = ',', -- (Optional) keymap to select the previous selection | |
keymaps = { | |
['.'] = 'textsubjects-smart', | |
[';'] = 'textsubjects-container-outer', | |
}, | |
}, | |
rainbow = { | |
enable = true, | |
extended_mode = true, | |
max_file_lines = nil, | |
-- colors = {}, -- table of hex strings | |
-- termcolors = {} -- table of colour name strings | |
}, | |
} | |
end | |
local function configTSAutoTag() | |
require('nvim-ts-autotag').setup() | |
end | |
local function configLSP() | |
local nvim_lsp = require('lspconfig') | |
local show_buffer_diagnostics = function() | |
vim.diagnostic.setloclist { open = false } | |
if #vim.fn.getloclist(vim.fn.winnr()) > 0 then | |
vim.cmd [[lopen]] | |
else | |
vim.cmd [[lclose]] | |
end | |
end | |
local show_workspace_diagnostics = function() | |
local items = vim.diagnostic.toqflist(vim.diagnostic.get(nil)) | |
vim.fn.setloclist(0, {}, ' ', { title = "Workspace Diagnostics", items = items }) | |
if #items > 0 then | |
vim.cmd [[lopen]] | |
else | |
vim.cmd [[lclose]] | |
end | |
end | |
local on_attach = function(client, bufnr) | |
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') | |
local opts = { buffer = bufnr, silent = true } | |
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) | |
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) | |
vim.keymap.set('n', '<c-]>', vim.lsp.buf.definition, opts) | |
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) | |
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) | |
vim.keymap.set('n', '<c-k>', vim.lsp.buf.signature_help, opts) | |
vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, opts) | |
vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, opts) | |
vim.keymap.set('n', '<leader>wl', function() | |
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) | |
end, opts) | |
vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, opts) | |
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts) | |
vim.keymap.set('n', 'gr', function() | |
vim.lsp.buf.references({ includeDeclaration = false }) | |
end, opts) | |
vim.keymap.set('n', 'gs', vim.lsp.buf.document_symbol, opts) | |
vim.keymap.set('n', 'gW', vim.lsp.buf.workspace_symbol, opts) | |
vim.keymap.set({ 'n', 'v' }, '<leader>ca', vim.lsp.buf.code_action, opts) | |
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) | |
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) | |
vim.keymap.set('n', 'gA', function() | |
require 'telescope.builtin'.lsp_code_actions {} | |
end, opts) | |
vim.keymap.set('v', 'gA', "<cmd>'<,'>lua vim.lsp.buf.range_code_action()<CR>", opts) | |
vim.keymap.set('n', 'gp', show_buffer_diagnostics, opts) | |
vim.keymap.set('n', 'gP', show_workspace_diagnostics, opts) | |
-- | |
-- Set some keybinds conditional on server capabilities | |
if client.resolved_capabilities.document_formatting then | |
vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, opts) | |
end | |
if client.resolved_capabilities.document_range_formatting then | |
vim.keymap.set('v', '<space>f', vim.lsp.buf.range_formatting, opts) | |
end | |
-- Set autocommands conditional on server_capabilities | |
if client.resolved_capabilities.document_highlight then | |
local lsp_doc_hl_group = vim.api.nvim_create_augroup('lsp_document_highlight', { | |
clear = true, | |
}) | |
vim.api.nvim_create_autocmd('CursorHold', { | |
callback = function() | |
vim.lsp.buf.document_highlight {} | |
end, | |
pattern = '<buffer>', | |
group = lsp_doc_hl_group, | |
}) | |
vim.api.nvim_create_autocmd('CursorMoved', { | |
callback = function() | |
vim.lsp.buf.clear_references {} | |
end, | |
pattern = '<buffer>', | |
group = lsp_doc_hl_group, | |
}) | |
end | |
if client.resolved_capabilities.signature_help then | |
local lsp_sig_help_group = vim.api.nvim_create_augroup('lsp_signature_help', { | |
clear = true, | |
}) | |
vim.api.nvim_create_autocmd('CursorHoldI', { | |
callback = vim.lsp.buf.signature_help, | |
pattern = '<buffer>', | |
group = lsp_sig_help_group, | |
}) | |
end | |
require("aerial").on_attach(client, bufnr) | |
end | |
local capabilities = vim.lsp.protocol.make_client_capabilities() | |
capabilities.textDocument.completion.completionItem.snippetSupport = true | |
-- Enable the following language servers | |
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver', 'ghcide' } | |
for _, lsp in ipairs(servers) do | |
nvim_lsp[lsp].setup { on_attach = on_attach, capabilities = capabilities } | |
end | |
nvim_lsp['gopls'].setup { | |
cmd = { "gopls" }, -- , "-logfile=/tmp/gopls.log", "-rpc.trace", "--remote=auto"}, | |
on_attach = on_attach, | |
capabilities = capabilities, | |
settings = { | |
gopls = { | |
analyses = { composites = false }, | |
usePlaceholders = false, | |
gofumpt = true, | |
codelenses = { | |
gc_details = true, | |
generate = true, | |
}, | |
}, | |
}, | |
flags = { | |
debounce_text_changes = 500, | |
}, | |
} | |
nvim_lsp['jsonls'].setup { | |
cmd = { "json-languageserver" }, | |
on_attach = on_attach, | |
capabilities = capabilities, | |
} | |
nvim_lsp['pylsp'].setup { | |
cmd = { "pyls" }, | |
on_attach = on_attach, | |
capabilities = capabilities, | |
} | |
nvim_lsp.sumneko_lua.setup { | |
cmd = { "lua-language-server" }; | |
on_attach = on_attach, | |
settings = { | |
Lua = { | |
runtime = { | |
version = 'LuaJIT', | |
path = vim.split(package.path, ';'), | |
}, | |
diagnostics = { | |
globals = { 'vim' }, | |
}, | |
workspace = { | |
library = vim.api.nvim_get_runtime_file("", true), | |
}, | |
}, | |
}, | |
} | |
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with( | |
vim.lsp.handlers.hover, | |
{ | |
border = 'single', | |
} | |
) | |
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with( | |
vim.lsp.handlers.signature_help, | |
{ | |
parameters_only = true, | |
silent = true, | |
border = 'single', | |
focus = false, | |
} | |
) | |
-- Map :Format to vim.lsp.buf.formatting() | |
vim.api.nvim_create_user_command("Format", vim.lsp.buf.formatting, {}) | |
end | |
local function configFidget() | |
require "fidget".setup {} | |
end | |
local function configLuaSnip() | |
require("luasnip/loaders/from_vscode").lazy_load() | |
end | |
local function configCmp() | |
local cmp_kinds = { | |
Text = '', | |
Method = 'ƒ', | |
Function = '', | |
Constructor = '', | |
Variable = '', | |
Class = '', | |
Interface = 'ﰮ', | |
Module = '', | |
Field = '', | |
Property = '', | |
Unit = '', | |
Value = '', | |
Enum = '了', | |
Keyword = '', | |
Snippet = '', | |
Color = '', | |
File = '', | |
Folder = '', | |
EnumMember = '', | |
Constant = '', | |
Struct = '', | |
} | |
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 luasnip = require("luasnip") | |
local cmp = require 'cmp' | |
cmp.setup({ | |
snippet = { | |
expand = function(args) | |
require('luasnip').lsp_expand(args.body) | |
end, | |
}, | |
mapping = cmp.mapping.preset.insert({ | |
['<C-d>'] = 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, behavior = cmp.ConfirmBehavior.Insert }), | |
["<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() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`. | |
end | |
end, { "i", "s" }), | |
["<S-Tab>"] = cmp.mapping(function() | |
if cmp.visible() then | |
cmp.select_prev_item() | |
elseif luasnip.jumpable(-1) then | |
luasnip.jump(-1) | |
end | |
end, { "i", "s" }), | |
}), | |
sources = { | |
{ name = 'nvim_lsp' }, | |
{ name = 'luasnip' }, | |
{ name = 'path' }, | |
}, | |
formatting = { | |
format = function(_, vim_item) | |
vim_item.kind = (cmp_kinds[vim_item.kind] or '') .. ' ' .. vim_item.kind | |
return vim_item | |
end, | |
}, | |
}) | |
cmp.setup.cmdline(':', { | |
sources = { | |
{ name = 'cmdline' } | |
} | |
}) | |
cmp.setup.cmdline('/', { | |
sources = { | |
{ name = 'buffer' } | |
} | |
}) | |
end | |
local function configAutopairs() | |
require('nvim-autopairs').setup {} | |
local cmp_autopairs = require('nvim-autopairs.completion.cmp') | |
require('cmp').event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } })) | |
end | |
local function configMundo() | |
vim.keymap.set('i', '<F1>', [[<ESC>:MundoToggle<CR>]]) | |
vim.keymap.set('n', '<F1>', [[:MundoToggle<CR>]]) | |
end | |
local function configToggleTerm() | |
require "toggleterm".setup { | |
direction = 'horizontal', | |
open_mapping = [[<c-\>]], | |
shade_terminals = false, | |
} | |
end | |
local function configBQF() | |
vim.api.nvim_exec([[ | |
highlight clear BqfSign | |
highlight link BqfSign String | |
]], false) | |
end | |
local function configWhichKey() | |
require("which-key").setup {} | |
end | |
local function configGo() | |
require('go').setup { | |
goimport = 'gopls', | |
gofmt = 'gopls', | |
dap_debug = true, | |
dap_debug_keymap = true, | |
tag_transform = 'camelcase', | |
} | |
local goimport_group = vim.api.nvim_create_augroup('goimport', { clear = true }) | |
vim.api.nvim_create_autocmd('BufWritePre', { | |
callback = function() | |
local codeaction = require("go.lsp").codeaction | |
codeaction("", "source.organizeImports", 1000) | |
vim.lsp.buf.formatting_sync() | |
end, | |
pattern = '*.go', | |
group = goimport_group, | |
}) | |
end | |
local function configJDTLS() | |
local javalsp_group = vim.api.nvim_create_augroup('javalsp', { clear = true }) | |
vim.api.nvim_create_autocmd('FileType', { | |
callback = function() | |
require('jdtls').start_or_attach({ | |
cmd = { 'jdtls' }, | |
root_dir = require('jdtls.setup').find_root({ 'gradle.build', 'pom.xml' }), | |
}) | |
end, | |
pattern = 'java', | |
group = javalsp_group, | |
}) | |
end | |
local function configDAP() | |
local dap = require('dap') | |
dap.adapters.go = function(callback, _) | |
local handle | |
local port = 38697 | |
handle = vim.loop.spawn( | |
"dlv", | |
{ | |
args = { "dap", "-l", "127.0.0.1:" .. port }, | |
detached = true | |
}, | |
function(code) | |
handle:close() | |
print("Delve exited with exit code: " .. code) | |
end | |
) | |
vim.defer_fn( | |
function() | |
dap.repl.open() | |
callback({ type = "server", host = "127.0.0.1", port = port }) | |
end, | |
100) | |
end | |
-- https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_dap.md | |
dap.configurations.go = { | |
{ | |
type = "go", | |
name = "Debug", | |
request = "launch", | |
program = "${file}" | |
} | |
} | |
local opts = { silent = true } | |
vim.keymap.set('n', '<F8>', function() | |
require 'dap'.continue() | |
end, opts) | |
vim.keymap.set('n', '<F10>', function() | |
require 'dap'.step_over() | |
end, opts) | |
vim.keymap.set('n', '<F11>', function() | |
require 'dap'.step_into() | |
end, opts) | |
vim.keymap.set('n', '<F12>', function() | |
require 'dap'.step_out() | |
end, opts) | |
vim.keymap.set('n', '<leader>b', function() | |
require 'dap'.toggle_breakpoint() | |
end, opts) | |
vim.keymap.set('n', '<leader>B', function() | |
require 'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: ')) | |
end, opts) | |
vim.keymap.set('n', '<leader>lp', function() | |
require 'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: ')) | |
end, opts) | |
vim.keymap.set('n', '<leader>dr', function() | |
require 'dap'.repl.open() | |
end, opts) | |
vim.keymap.set('n', '<leader>dl', function() | |
require 'dap'.run_last() | |
end, opts) | |
end | |
local function configDAPGo() | |
require('dap-go').setup() | |
end | |
local function configVimTest() | |
vim.g['test#strategy'] = "neovim" | |
vim.g['test#go#runner'] = "richgo" | |
end | |
configToggleTerm(); | |
configTelescope(); | |
configGitWorktree(); | |
configDevIcons(); | |
configNVimTree(); | |
configColorscheme(); | |
configIndentBlanklines(); | |
configGitSigns(); | |
configTreesitter(); | |
configTSAutoTag(); | |
configLSP(); | |
configFidget(); | |
configGps(); | |
configLualine(); | |
configBQF(); | |
configWhichKey(); | |
configMundo(); | |
configVimTest(); | |
configLuaSnip(); | |
configCmp(); | |
configAutopairs(); | |
configGo(); | |
configJDTLS(); | |
configDAP(); | |
configDAPGo(); | |
-- vim:sw=2 ts=2 et |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment