]> git.armaanb.net Git - dotfiles.git/blob - .config/nvim/init.lua
nvim: simplify config
[dotfiles.git] / .config / nvim / init.lua
1 require('impatient')
2
3 local map = vim.api.nvim_set_keymap
4 local opts = { noremap=true, silent=true }
5
6 -- General settings
7 vim.opt.mouse = 'a'
8 vim.opt.undofile = true
9 vim.opt.textwidth = 80
10 map('', 'Q', '<nop>', opts)
11 vim.g.mapleader = ' '
12
13 -- Plugins
14 local install_path = vim.fn.stdpath('data') .. '/site/pack/paqs/start/paq-nvim'
15 if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
16         vim.fn.system({'git', 'clone', '--depth=1',
17         'https://github.com/savq/paq-nvim.git', install_path})
18 end
19
20 require('paq') {
21         'dstein64/vim-startuptime';       -- Profile startup time
22         'editorconfig/editorconfig-vim';  -- Follow editorconfig
23         'folke/lsp-colors.nvim';          -- Add LSP colors to any theme
24         'godlygeek/tabular';              -- Line things up
25         'lewis6991/impatient.nvim';       -- Improve startup time
26         'lifepillar/vim-mucomplete';      -- Simple completion
27         'meain/hima-vim';                 -- Nice color scheme
28         'nathom/filetype.nvim';           -- Faster filetype.vim replacement
29         'neovim/nvim-lspconfig';          -- LSP configurations
30         'norcalli/nvim-colorizer.lua';    -- Highlight css colors
31         'ntpeters/vim-better-whitespace'; -- Highlight and strip whitespace
32         'savq/paq-nvim';                  -- paq manages itself
33         'tpope/vim-commentary';           -- Easily comment
34         'tpope/vim-rsi';                  -- Readline bindings
35         'tpope/vim-sensible';             -- Sensible defaults
36         'tpope/vim-speeddating';          -- Modify dates with C-a, C-x
37         'tpope/vim-surround';             -- Easily modify surrounding chars
38 }
39
40 -- Colorscheme
41 vim.opt.termguicolors = true
42 vim.g.colors_name = 'hima-plain'
43
44 -- Easier split movement
45 map('n', '<C-h>', '<C-w><C-h>', opts)
46 map('n', '<C-j>', '<C-w><C-j>', opts)
47 map('n', '<C-k>', '<C-w><C-k>', opts)
48 map('n', '<C-l>', '<C-w><C-l>', opts)
49
50 -- Clear search highlighting
51 map('n', '<C-c>', ':noh<CR>', opts)
52
53 -- Disable keyword completion
54 map('i', '<C-n>', '<Down>', opts)
55 map('i', '<C-p>', '<Up>', opts)
56
57 -- Completion
58 vim.opt.completeopt = vim.opt.completeopt + 'menuone'
59 vim.opt.completeopt = vim.opt.completeopt - 'preview'
60 vim.opt.shortmess = vim.opt.shortmess + 'c'
61
62 -- LSP
63 local lspconfig = require('lspconfig')
64
65 local on_attach = function(client, bufnr)
66         -- Shorthand
67         local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr,
68                 ...) end
69         local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr,
70                 ...) end
71
72         -- Use omnifunc for completion
73         buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
74
75         -- Keybindings
76         buf_set_keymap('n', 'gD',
77                 '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
78         buf_set_keymap('n', 'gd',
79                 '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
80         buf_set_keymap('n', 'gr',
81                 '<cmd>lua vim.lsp.buf.references()<CR>', opts)
82         buf_set_keymap('n', 'K',
83                 '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
84         buf_set_keymap('n', '<leader>rn',
85                 '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
86         buf_set_keymap('n', '[d',
87                 '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
88         buf_set_keymap('n', ']d',
89                 '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
90         buf_set_keymap('n', '<leader>e',
91                 '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
92 end
93
94 -- Add servers
95 local servers = {
96         'clangd',
97         'racket_langserver',
98 }
99
100 for _, server in ipairs(servers) do
101         lspconfig[server].setup {on_attach = on_attach}
102 end
103
104 vim.opt.signcolumn = 'no'
105
106 -- Jump to files with gf
107 vim.opt.hidden = true
108 vim.opt.path = vim.opt.path + '**'
109
110 -- Disable intro message
111 vim.opt.shortmess = vim.opt.shortmess + 'I'
112
113 -- Highlight on yank
114 vim.cmd([[
115 augroup highlight_yank
116     autocmd!
117     au TextYankPost * silent! lua vim.highlight.on_yank{timeout=200}
118 augroup END
119 ]])
120
121 -- Do not source the default filetype.vim (uses nathom/filetype.nvim instead)
122 vim.g.did_load_filetypes = 1