-- Install packer local execute = vim.api.nvim_command local install_path = vim.fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim' -- Check that packer is installed if vim.fn.empty(vim.fn.glob(install_path)) > 0 then execute('!git clone https://github.com/wbthomason/packer.nvim '..install_path) end vim.cmd [[packadd packer.nvim]] vim.api.nvim_exec([[ augroup Packer autocmd! autocmd BufWritePost plugins.lua PackerCompile augroup end ]], false) local use = require('packer').use local packer = require('packer') packer.startup(function() use { 'wbthomason/packer.nvim', opt = true } -- Package manager -- visuals use 'gruvbox-community/gruvbox' -- file management use { 'nvim-telescope/telescope.nvim', requires = { {'nvim-lua/popup.nvim'}, {'nvim-lua/plenary.nvim'}, {'nvim-treesitter/nvim-treesitter'}, } }-- search and select tool use 'preservim/nerdtree' -- editing behaviour use 'jiangmiao/auto-pairs' use 'tpope/vim-commentary' -- Easily comment/uncomment code use 'tpope/vim-surround' -- surround text objects with delimiters -- git TODO: Learn how to use use 'airblade/vim-gitgutter' use 'tpope/vim-fugitive' -- LSP use 'neovim/nvim-lspconfig' use 'nvim-lua/lsp_extensions.nvim' use 'nvim-lua/completion-nvim' -- Language specific use 'rust-lang/rust.vim' end) -- settings -- this is all of the basic vim settings local o = vim.o -- global local g = vim.g -- global 2? local wo = vim.wo -- window local local bo = vim.bo -- buffer local -- basic UI o.background = 'dark' o.termguicolors = true -- enable 24 bit colors in TUI vim.cmd('colorscheme gruvbox') vim.cmd('syntax enable') wo.number = true wo.relativenumber = true o.signcolumn = 'yes' o.splitright = true o.splitbelow = true -- text wo.wrap = false wo.foldenable = false o.mouse = 'a' -- search o.hlsearch = false o.incsearch = true o.ignorecase = true -- temporary file configuration o.swapfile = false o.undofile = true bo.undofile = true o.dir = '/tmp' o.hidden = true -- do not save when switching buffers -- LSP o.updatetime = 250 o.completeopt = 'menuone,noinsert,noselect' o.inccommand = 'nosplit' -- keybindings local map = vim.api.nvim_set_keymap g.mapleader = ' ' -- window navigation map('n', '', 'j', {noremap = true}) map('n', '', 'k', {noremap = true}) map('n', '', 'l', {noremap = true}) map('n', '', 'h', {noremap = true}) -- terminal map('t', '', '', {noremap = true}) -- NERDTree map('n', 'nt', 'NERDTreeToggle', {noremap = true}) -- Telescope map('n', '', 'Telescope find_files', {noremap = true}) -- LSP TODO: make lua instead of vimscript -- -- Use completion-nvim in every buffer vim.api.nvim_exec([[ autocmd BufEnter * lua require'completion'.on_attach() ]], false) -- Avoid showing message extra message when using completion -- -- Use and to navigate through popup menu vim.api.nvim_exec([[ inoremap pumvisible() ? "\" : "\" inoremap pumvisible() ? "\" : "\" ]], false) -- use as trigger keys vim.api.nvim_exec([[ imap (completion_smart_tab) imap (completion_smart_s_tab) ]], false) -- code shortcuts local opts = { noremap=true, silent=true } map('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) map('n', 'gd', 'lua vim.lsp.buf.definition()', opts) map('n', 'K', 'lua vim.lsp.buf.hover()', opts) -- map('n', '', 'lua vim.lsp.buf.signature_help()', opts) map('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) map('n', 'rn', 'lua vim.lsp.buf.rename()', opts) map('n', 'gr', 'lua vim.lsp.buf.references()', opts) map('n', 'd', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) map('n', '[g', 'lua vim.lsp.diagnostic.goto_prev()', opts) map('n', ']g', 'lua vim.lsp.diagnostic.goto_next()', opts) -- autocommands -- Highlight on yank vim.cmd('au TextYankPost * lua vim.highlight.on_yank {on_visual = false}' )-- disabled in visual mode -- Trim Whitespace vim.api.nvim_exec([[ fun! TrimWhitespace() let l:save = winsaveview() keeppatterns %s/\s\+$//e call winrestview(l:save) endfun augroup AUTOCOMMANDGROUP autocmd! autocmd BufWritePre * :call TrimWhitespace() augroup END ]], false) -- language server configs -- LSP settings local nvim_lsp = require('lspconfig') local on_attach = function(_client, bufnr) require'completion'.on_attach(_client) vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') local opts = { noremap=true, silent=true } vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ga', 'lua vim.lsp.buf.code_action()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) vim.api.nvim_buf_set_keymap(bufnr, 'n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) end -- Rust vim.cmd([[let g:rustfmt_autosave = 1]]) nvim_lsp['rust_analyzer'].setup { on_attach = on_attach, settings = { ["rust-analyzer"] = { cargo = { allFeatures = true }, checkOnSave = { command = "clippy" } } } } -- Enable diagnostics vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = true, signs = true, update_in_insert = true, } ) -- Show diagnostic popup on cursor hold vim.cmd([[autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics()]]) -- Enable type inlay hints vim.cmd([[autocmd CursorMoved,InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost * lua require'lsp_extensions'.inlay_hints{ prefix = '', highlight = "Comment", enabled = {"TypeHint", "ChainingHint", "ParameterHint"} }]])