diff --git a/nvim/.config/nvim/.gitignore b/nvim/.config/nvim/.gitignore new file mode 100644 index 0000000..00ef99c --- /dev/null +++ b/nvim/.config/nvim/.gitignore @@ -0,0 +1,2 @@ +plugin/ +!after/plugin/ diff --git a/nvim/.config/nvim/after/plugin/lsp.lua b/nvim/.config/nvim/after/plugin/lsp.lua new file mode 100644 index 0000000..13463f0 --- /dev/null +++ b/nvim/.config/nvim/after/plugin/lsp.lua @@ -0,0 +1,89 @@ +-- Custom LSP configuration +-- This cannot be done in the config function from Packer +-- because it somehow does not work well with make_client_capabilities() +require("mason-lspconfig").setup({ + ensure_installed = { "rust_analyzer" } +}) + +local opts = { noremap=true, silent=true } +vim.keymap.set('n', 'e', vim.diagnostic.open_float, 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', 'q', vim.diagnostic.setloclist, opts) + +local cmp = require 'cmp' +cmp.setup({ + mapping = { + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, { 'i', 's' }), + }, + sources = { + { name = 'nvim_lsp' }, + }, +}) + +-- Rewrite LSP capabilities (to enable completion) +local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + +-- 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) + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'f', vim.lsp.buf.formatting, bufopts) +end + +require('lspconfig')['rust_analyzer'].setup({ + on_attach = on_attach, + settings = { + ['rust_analyzer'] = { + cargo = { + autoreload = true, + buildScripts = { enable = true }, + }, + procMacro = { + enable = true, + }, + }, + }, + capabilities = capabilities, +}) + +-- TODO: Set this to OFF when neovim supports it (0.8 release probably) +-- rust_analyzer spits out spurious errors with build.rs outputs +-- likely due to a race condition between the VFS initialization and the diagnostics +vim.lsp.set_log_level("error") diff --git a/nvim/.config/nvim/ginit.vim b/nvim/.config/nvim/ginit.vim new file mode 100644 index 0000000..6f1bf80 --- /dev/null +++ b/nvim/.config/nvim/ginit.vim @@ -0,0 +1,8 @@ +" Mouse +set mouse=a + +" Set Editor Font +GuiFont! FiraCode Nerd Font Mono:h10.5:l + +" Ligature +GuiRenderLigatures 1 diff --git a/nvim/.config/nvim/init.vim b/nvim/.config/nvim/init.vim new file mode 100644 index 0000000..afa0aaa --- /dev/null +++ b/nvim/.config/nvim/init.vim @@ -0,0 +1,57 @@ +" Packer plugins +lua require('plugins') + +" Gruvbox Theme (colorscheme applied from plugins.lua) +if has('termguicolors') + set termguicolors +endif +" For dark version. +set background=dark +" We need to apply this here too to make sure the startup components work +colorscheme gruvbox + +" Miscellaneous boilerplate +set nocompatible " Disable vi compatibility +set ignorecase +set cc=128 " 128 characters +set noswapfile +set backupdir=~/.cache/nvim +set cursorline " Highlight current line +set mouse=a " Mouse +set nofixendofline +set clipboard+=unnamedplus " System clipboard + +" Default indentation +set softtabstop=4 +set tabstop=4 +set shiftwidth=4 +set expandtab +set autoindent + +" Syntax highlighting +set syntax=on + +let g:special_filetype_pattern = 'neo-tree\|toggleterm\|minimap' + +" Show line numbers on non-toolbar buffers +fun! ShowNumberIfNecessary() + if &ft =~ g:special_filetype_pattern + return + endif + setlocal nu +endfun +autocmd BufEnter * call ShowNumberIfNecessary() + +" Terminal remapping +lua << EOF +function _G.set_terminal_keymaps() + local opts = {buffer = 0} + vim.keymap.set('t', '', [[]], opts) + vim.keymap.set('t', 'jk', [[]], opts) + vim.keymap.set('t', '', [[wincmd h]], opts) + vim.keymap.set('t', '', [[wincmd j]], opts) + vim.keymap.set('t', '', [[wincmd k]], opts) + vim.keymap.set('t', '', [[wincmd l]], opts) +end +EOF +autocmd TermOpen term://* lua set_terminal_keymaps() diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua new file mode 100644 index 0000000..42040f1 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins.lua @@ -0,0 +1,128 @@ +vim.cmd [[packadd packer.nvim]] + +return require('packer').startup(function(use) + -- Packer can manage itself + use 'wbthomason/packer.nvim' + + -- LSP stuff + use { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + "neovim/nvim-lspconfig", + "hrsh7th/nvim-cmp", + "hrsh7th/cmp-nvim-lsp", + } + + -- Gruvbox theme + use { + "ellisonleao/gruvbox.nvim", + config = function() + require("gruvbox").setup({ + bold = false, + italic = true, + strikethrough = true, + overrides = { + Directory = { link = "GruvboxFg2" }, + }, + }) + vim.cmd("colorscheme gruvbox") + end, + } + + -- A way saner buffer closing implementation + use "ojroques/nvim-bufdel" + + -- Indentation guide + use "lukas-reineke/indent-blankline.nvim" + + -- Indentation autodetection + use { + "nmac427/guess-indent.nvim", + config = function() + require("guess-indent").setup() + end + } + + -- Scrollbar + use { + "petertriho/nvim-scrollbar", + config = function() + require("scrollbar").setup() + end, + } + + -- Directory tree + use { + "nvim-neo-tree/neo-tree.nvim", + branch = "v2.x", + requires = { + "nvim-lua/plenary.nvim", + "kyazdani42/nvim-web-devicons", + "MunifTanjim/nui.nvim", + }, + config = function() + require("neo-tree").setup({ + window = { + position = "left", + width = 36, + }, + }) + require("neo-tree.sources.manager").show("filesystem") + end, + } + + -- Tabs + use { + "akinsho/bufferline.nvim", tag = "v2.*", requires = "kyazdani42/nvim-web-devicons", + config = function() require("bufferline").setup({ + options = { + close_command = "BufDel %d", + right_mouse_command = "BufDel %d", + offsets = { + { + filetype = "neo-tree", + text = "Files", + highlight = "Directory", + text_align = "left", + } + }, + separator_style = "slant", + } + }) end, + } + + -- Status line + use { + "nvim-lualine/lualine.nvim", requires = { 'kyazdani42/nvim-web-devicons', opt = true }, + config = function() require("lualine").setup({ + options = { + theme = "gruvbox", + disabled_filetypes = { + statusline = { "neo-tree" }, + }, + }, + }) end, + } + + -- Terminal + use { + "akinsho/toggleterm.nvim", tag = "v2.*", + config = function() require("toggleterm").setup({ + open_mapping = [[]], + persist_size = false, + shade_terminals = false, + hide_numbers = false, + winbar = { + enabled = false, + }, + on_open = function() + -- Toggle the neo-tree file view such that it is + -- always full height; This is a dirty workaround + local manager = require('neo-tree.sources.manager') + if manager.close('filesystem') then + manager.show('filesystem') + end + end, + }) end, + } +end) diff --git a/vim/.vimrc b/vim/.vimrc index 2c186fe..52f2ff7 100644 --- a/vim/.vimrc +++ b/vim/.vimrc @@ -6,3 +6,5 @@ set shiftwidth=4 softtabstop=4 expandtab " In these files, use 2 spaces autocmd FileType sh setlocal shiftwidth=2 softtabstop=2 + +set nofixeol