---- Aliases ---- local cmd = vim.cmd local g = vim.g local opt = vim.opt ---- General Config ---- opt.mouse = 'a' opt.tabstop = 4 opt.shiftwidth = 4 opt.number = true opt.breakindent = true opt.showmatch = true opt.ignorecase = true opt.smartcase = true opt.joinspaces = false opt.showmode = false opt.hidden = true opt.backup = false opt.writebackup = false opt.swapfile = false opt.shortmess:append({ I = true }) -- whichwrap -- left/right keys can traverse up/down --opt.whichwrap = {'<','>','[',']'} opt.cmdheight = 2 opt.showcmd = true g.mapleader = ' ' ---- Terminal ---- vim.api.nvim_create_autocmd({ "TermOpen" }, { callback = function() vim.l.number = false end, }) ---- Theming ---- opt.termguicolors = true opt.background = 'dark' g.gruvbox_italic = true cmd 'colorscheme gruvbox' opt.listchars = { eol = '↲' , tab = '▶▹', nbsp = '␣', extends = '…', trail = '•'} -- vim-airline config --- g.airline_powerline_fonts = true g.airline_theme = 'powerlineish' g['airline#extensions#tabline#enabled'] = 1 g['airline#extensions#tabline#left_sep'] = ' ' g['airline#extensions#tabline#left_alt_sep'] = '|' ---- Maps ---- local function map(mode, lhs, rhs, opts) local options = {noremap = true, silent = true} if opts then options = vim.tbl_extend('force', options, opts) end vim.keymap.set(mode, lhs, rhs, options) end vim.keymap.set('!','','') vim.keymap.set('v','>','>gv') vim.keymap.set('v','<','',':nohlsearch') ---- Treesitter ---- local ts = require 'nvim-treesitter.configs' ts.setup { ensure_installed = { 'bash', 'c', 'cmake', 'comment', 'cpp', 'css', 'dockerfile', 'diff', 'dot', 'git_config', 'git_rebase', 'gitattributes', 'gitcommit', 'gitignore', 'go', 'html', 'http', 'ini', 'javascript', 'json', 'kdl', 'kotlin', 'latex', 'lua', 'make', 'markdown', 'markdown_inline', 'passwd', 'perl', 'php', 'python', 'regex', 'rust', 'scss', 'sql', 'terraform', 'toml', 'typescript', 'vim', 'yaml', }, highlight = {enable = true, indent = true}} ---- Filetypes --- vim.filetype.add({ extension = {kdl = 'kdl'} }) ---- LSP ---- local lsp = require 'lspconfig' -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer local on_lsp_attach = function(client, bufnr) vim.pretty_print(bufnr) -- See `:help vim.lsp.*` for documentation on any of the below functions vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) vim.keymap.set('n', '', 'lua vim.lsp.buf.signature_help()', opts) vim.keymap.set('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) vim.keymap.set('n', 'rn', 'lua vim.lsp.buf.rename()', opts) vim.keymap.set('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) vim.keymap.set('n', 'e', 'lua vim.diagnostic.open_float()', opts) vim.keymap.set('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) vim.keymap.set('n', ']d', 'lua vim.diagnostic.goto_next()', opts) vim.keymap.set('n', 'q', 'lua vim.diagnostic.setloclist()', opts) vim.keymap.set('n', '', 'lua vim.lsp.buf.formatting()', opts) end -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches local servers = { clangd, gopls, jsonls, kotlin_language_server, marksman, pylsp, rust_analyzer, texlab, tflint, tsserver, } -- Setup loop moved to the cmp section, since calling setup multiple times -- overrides the previous calls. -- Auto format on save vim.api.nvim_create_autocmd({ "BufWritePre" }, { callback = function() vim.lsp.buf.format() end, }) ---- Plugins ---- -- Go g.ale_go_golangci_lint_options = '' g.ale_go_golangci_lint_package = 1 ---- nvim-lint ---- local lint = require 'lint' linters = { bash = {'shellcheck'}, go = {'golangcilint',}, python = {'flake8'}, yaml = {'yamllint'}, zsh = {'shellcheck'}, } -- set linters -- lint.linters_by_ft = linters -- set autocommands -- vim.api.nvim_create_autocmd({ "BufWritePost" }, { callback = function() lint.try_lint() end, }) ---- completion-nvim local cmp = require'cmp' 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({ [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. [''] = cmp.mapping.confirm({ select = true }), }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'path' }, { name = 'buffer' }, }) }) --cmd [[autocmd FileType *\(TelescopePrompt\)\@' end, {expr=true}) vim.keymap.set('n', '[c', function() if vim.wo.diff then return '[c' end vim.schedule(function() gs.prev_hunk() end) return '' end, {expr=true}) -- Actions vim.keymap.set({'n', 'v'}, 'hs', ':Gitsigns stage_hunk') vim.keymap.set({'n', 'v'}, 'hr', ':Gitsigns reset_hunk') vim.keymap.set('n', 'hS', gs.stage_buffer) vim.keymap.set('n', 'hu', gs.undo_stage_hunk) vim.keymap.set('n', 'hR', gs.reset_buffer) vim.keymap.set('n', 'hp', gs.preview_hunk) vim.keymap.set('n', 'hb', function() gs.blame_line{full=true} end) vim.keymap.set('n', 'tb', gs.toggle_current_line_blame) vim.keymap.set('n', 'hd', gs.diffthis) vim.keymap.set('n', 'hD', function() gs.diffthis('~') end) vim.keymap.set('n', 'td', gs.toggle_deleted) -- Text object vim.keymap.set({'o', 'x'}, 'ih', ':Gitsigns select_hunk') end } ---- Comment.nvim require('Comment').setup() ---- vim-markdown g.vim_markdown_no_default_key_mappings = 1 g.vim_markdown_folding_disabled = 1 g.vim_markdown_toml_frontmatter = 1 ---- Telescope require('telescope').setup{ defaults = { file_sorter = require'telescope.sorters'.get_fzy_sorter, file_ignore_patterns = {"%.avif", "%.jpg", "%.pdf", "%.png", "%.webp"}, } } map('n', 'f', ':Telescope fd') map('n', 'b', ':Telescope buffers') map('n', '/', ':Telescope current_buffer_fuzzy_find') --map('n', '*', ':Telescope grep_string') map('n', 'g', ':Telescope live_grep') map('n', 'cg', ':Telescope grep_string') ---- nvim-dap local dap = require('dap') vim.fn.sign_define('DapBreakpoint',{ text ='🟥', texthl ='', linehl ='', numhl =''}) vim.fn.sign_define('DapStopped',{ text ='▶️', texthl ='', linehl ='', numhl =''}) -- Set keymaps to control the debugger vim.keymap.set('n', 'dc', require 'dap'.continue) vim.keymap.set('n', 'do', require 'dap'.step_over) vim.keymap.set('n', 'di', require 'dap'.step_into) vim.keymap.set('n', 'dO', require 'dap'.step_out) vim.keymap.set('n', 'db', require 'dap'.toggle_breakpoint) vim.keymap.set('n', 'dB', function() require 'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: ')) end) local dapui = require('dapui') dap.listeners.after.event_initialized["dapui_config"]=function() dapui.open() end dap.listeners.before.event_terminated["dapui_config"]=function() dapui.close() end dap.listeners.before.event_exited["dapui_config"]=function() dapui.close() end -- nvim-dap-go require('dap-go').setup()