---- Aliases ---- local cmd = vim.cmd local g = vim.g local opt = vim.opt local o = vim.o ---- General Config ---- opt.mouse = 'a' opt.tabstop = 4 opt.shiftwidth = 4 opt.number = true opt.breakindent = true --vim.o.inccomand = 'nosplit' 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 opt.showcmd = true g.mapleader = ' ' ---- Terminal ---- cmd 'autocmd TermOpen * setlocal nonumber' ---- 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.api.nvim_set_keymap(mode, lhs, rhs, options) end map('!','','') map('v','>','>gv') map('v','<','',':nohlsearch') ---- Treesitter ---- local ts = require 'nvim-treesitter.configs' ts.setup { ensure_installed = { 'bash', 'c', 'cmake', 'cpp', 'css', 'comment', 'dockerfile', 'dot', 'gitattributes', 'gitignore', 'go', 'html', 'http', 'javascript', 'json', 'kotlin', 'latex', 'lua', 'markdown', 'perl', 'php', 'python', 'rust', 'scss', 'sql', 'toml', 'typescript', 'vim', 'yaml', }, highlight = {enable = true, indent = true}} ---- 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_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 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', 'lua vim.lsp.buf.declaration()', opts) buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) buf_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', opts) buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) buf_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', opts) buf_set_keymap('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 = { 'gopls', 'kotlin_language_server', 'rust_analyzer', 'tsserver', 'pylsp' } for _, server in ipairs(servers) do lsp[server].setup { on_attach = on_attach, flags = { debounce_text_changes = 150, } } end -- Auto format on save vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.formatting_sync()]] ---- Plugins ---- ---- ale g.ale_linters = { bash = {'shellcheck'}, c = {}, cpp = {}, css = {'stylelint'}, go = {'gobuild', 'golangci-lint'}, html = {'tidy'}, javascript = {'eslint'}, python = {'flake8'}, tex = {'texlab'}, typescript = {}, vim = {'vint'}, zsh = {'shell', 'shellcheck'}, } g.ale_sign_error = '✘' g.ale_sign_warning = '▲' g.ale_set_highlights = 1 -- Go g.ale_go_golangci_lint_options = '' g.ale_go_golangci_lint_package = 1 map('n', '[W', '(ale_first)') map('n', '[w', '(ale_previous_wrap)') map('n', ']w', '(ale_next_wrap)') map('n', ']W', '(ale_last)') ---- 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}) map('n', '[c', function() if vim.wo.diff then return '[c' end vim.schedule(function() gs.prev_hunk() end) return '' end, {expr=true}) -- Actions map({'n', 'v'}, 'hs', ':Gitsigns stage_hunk') map({'n', 'v'}, 'hr', ':Gitsigns reset_hunk') map('n', 'hS', gs.stage_buffer) map('n', 'hu', gs.undo_stage_hunk) map('n', 'hR', gs.reset_buffer) map('n', 'hp', gs.preview_hunk) map('n', 'hb', function() gs.blame_line{full=true} end) map('n', 'tb', gs.toggle_current_line_blame) map('n', 'hd', gs.diffthis) map('n', 'hD', function() gs.diffthis('~') end) map('n', 'td', gs.toggle_deleted) -- Text object map({'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')