diff --git a/Installer/os_nvim_init.vim b/Installer/os_nvim_init.vim index c7bf734..83dd9b0 100644 --- a/Installer/os_nvim_init.vim +++ b/Installer/os_nvim_init.vim @@ -1,52 +1,183 @@ " Plugins " ============================================================================== call plug#begin(stdpath('config') . '/plugged') + " nerdtree provides a file tree explorer + " vim-dispatch allows running async jobs in vim (i.e. builds in the background) Plug 'https://github.com/scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } + Plug 'https://github.com/tpope/vim-dispatch' + Plug 'https://github.com/nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} + + " Fast fuzzy searcher, the .vim repository pulls in sane defaults for + " setting up fzf in vim. Plug 'https://github.com/junegunn/fzf' Plug 'https://github.com/junegunn/fzf.vim' - Plug 'https://github.com/Tetralux/odin.vim' - Plug 'https://github.com/morhetz/gruvbox' + + " nvim-lspconfig sets up sane defaults for LSP servers (i.e. clangd) + " nvim-cmp is a more powerful autocomplete engine + " LuaSnip allow writing snippets into the buffer, we can power the snippets from LSP + " cmp-nvim-lsp preset capability flags to request more powerful autocomplete from LSP server + " cmp_luasnip a LuaSnip addon that provides a completion source to nvim-cmp + " cmp-buffer provides a buffer completion source to nvim-cmp + " cmp-path provides a path completion source to nvim-cmp Plug 'https://github.com/neovim/nvim-lspconfig' - Plug 'https://github.com/tpope/vim-dispatch' + Plug 'https://github.com/hrsh7th/nvim-cmp' + Plug 'https://github.com/L3MON4D3/LuaSnip' + Plug 'https://github.com/hrsh7th/cmp-nvim-lsp' + Plug 'https://github.com/saadparwaiz1/cmp_luasnip' + Plug 'https://github.com/hrsh7th/cmp-buffer' + Plug 'https://github.com/hrsh7th/cmp-path' + + " odin for syntax highlighting + Plug 'https://github.com/Tetralux/odin.vim' + Plug 'https://github.com/sainnhe/gruvbox-material' call plug#end() -" Setup LSP +" Lua Setup " ============================================================================== lua <-,trail:■,extends:»,precedes:«') + vim.opt.number=true -- Show line numbers + vim.opt.relativenumber=true -- Show relative line numbers + vim.opt.shiftwidth=4 -- Number of spaces for each autoindent step + vim.opt.splitright=true -- Open new splits to the right of the current one + vim.opt.swapfile=false -- Disable swapfile (stores the things changed in a file) + vim.opt.textwidth=80 -- On format, format to 80 char long lines + vim.opt.visualbell=true -- Flash the screen on error + vim.opt.wrap=false -- Don't wrap lines of text automatically + + -- LSP Setup + -- =========================================================================== + -- Load the additional capabilities supported by nvim-cmp + local custom_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 custom_on_attach = function(client, bufnr) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- See `:help vim.diagnostic.*` for documentation on any of the below functions + local opts = { noremap=true, silent=true } + vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) + vim.keymap.set('n', '', vim.diagnostic.goto_next, opts) + vim.keymap.set('n', '', vim.diagnostic.goto_prev, opts) + + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'gt', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'gs', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.rename, bufopts) + end + + -- Request additional completion capabilities from the LSP server(s) + local lspconfig = require('lspconfig') + local servers = { 'clangd', } + for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { on_attach = custom_on_attach, capabilities = custom_capabilities, } + end + + -- Autocomplete Setup + -- =========================================================================== + local luasnip = require 'luasnip' + local cmp = require 'cmp' + + cmp.setup { + snippet = { + expand = function(args) luasnip.lsp_expand(args.body) end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(-1), -- Scroll the docs up by 1 line + [''] = cmp.mapping.scroll_docs(1), -- Scroll the docs down by 1 line + [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, }, + [''] = cmp.mapping(function(fallback) -- Move down the autocomplete list + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) -- Move up the autocomplete list + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), + }), + sources = { + { name = 'nvim_lsp' }, { name = 'luasnip' }, + }, + } + + -- Clangd LSP Setup + -- =========================================================================== + lspconfig.clangd.setup { + single_file_support = false, --- Don't launch LSP if the directory does not have LSP metadata + } + + require('nvim-treesitter.configs').setup { + ensure_installed = { "c", "cpp" }, -- A list of parser names, or "all" + sync_install = false, -- Install parsers synchronously (only applied to `ensure_installed`) + ignore_install = { }, -- List of parsers to ignore installing (for "all") + + highlight = { + enable = true, -- `false` will disable the whole extension + + -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to + -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is + -- the name of the parser) + -- list of language that will be disabled + disable = { }, + + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, + } EOF " Theme " ============================================================================== -let g:gruvbox_contrast_dark='hard' -let g:gruvbox_italic=0 -let g:gruvbox_bold=0 -colorscheme gruvbox +let g:gruvbox_material_background='hard' +let g:gruvbox_material_foreground='mix' +let g:gruvbox_material_disable_italic_comment=1 +let g:gruvbox_material_enable_italic=0 +let g:gruvbox_material_enable_bold=0 +let g:gruvbox_material_diagnostic_virtual_text='colored' +colorscheme gruvbox-material " Options " ============================================================================== -set autowrite " Automatically save before commands like :next and :make -set nowrap " Don't wrap lines of text automatically -set ignorecase " Search isn't case sensitive -set splitright " Open new splits to the right of the current one -set visualbell " Flash the screen on error -set expandtab " Replace tabs with spaces -set noswapfile " Disable swapfile (stores the things changed in a file) -set colorcolumn=80,100 " Set a 80 and 100 char column ruler -set cpoptions+=$ " $ as end marker for the change operator -set cursorline " Highlight current line -set linebreak " On wrapped lines, break on the wrapping word intelligently -set list " Show the 'listchar' characters on trailing spaces, tabs e.t.c -set listchars+=tab:>-,trail:■,extends:»,precedes:« -set number " Show line numbers -set relativenumber " Show relative line numbers -set shiftwidth=4 " Number of spaces for each autoindent step -set textwidth=80 " On format, format to 80 char long lines -set nohlsearch " Show EOL type and last modified timestamp, right after the filename set statusline=%<%F%h%m%r\ [%{&ff}]\ (%{strftime(\"%H:%M\ %d/%m/%Y\",getftime(expand(\"%:p\")))})%=%l,%c%V\ %P -set guifont=JetBrains_Mono:h9,Consolas:h9,InputMonoCondensed:h9 " Resize splits when the window is resized au VimResized * :wincmd = @@ -66,13 +197,6 @@ endif " Functions " ============================================================================== -" Don't show trailing spaces in insert mode -augroup trailing - au! - au InsertEnter * :set listchars-=trail:■ - au InsertLeave * :set listchars+=trail:■ -augroup END - " Increase font size using (Ctrl+Up Arrow) or (Ctrl+Down Arrow) if we are using " gvim Otherwise font size is determined in terminal nnoremap :silent! let &guifont = substitute( @@ -92,15 +216,6 @@ augroup persistent_settings au bufenter * :set formatoptions=q1j augroup end -" Return to the same line when a file is reopened -augroup line_return - au! - au BufReadPost * - \ if line("'\"") > 0 && line("'\"") <= line("$") | - \ execute 'normal! g`"zvzz' | - \ endif -augroup end - " General Key Bindings " ============================================================================== " Map Ctrl+HJKL to navigate buffer window @@ -126,13 +241,15 @@ nnoremap s :vs " Go to next error " Go to previous error -nnoremap :cn -nnoremap :cp +nnoremap :cn +nnoremap :cp " FZF " ============================================================================== -nnoremap f :FzfFiles +nnoremap f :FzfFiles +nnoremap F :FzfFiles nnoremap t :FzfTags +nnoremap r :FzfRg nnoremap r :FzfRg nnoremap b :FzfBuffers nnoremap l :FzfLines