]> git.armaanb.net Git - dotfiles.git/blob - .config/nvim/init.lua
nvim: use leader key
[dotfiles.git] / .config / nvim / init.lua
1 local map = vim.api.nvim_set_keymap
2 local opts = { noremap=true, silent=true }
3
4 -- General settings
5 vim.opt.mouse = 'a'
6 vim.opt.undofile = true
7 vim.opt.textwidth = 80
8 map('', 'Q', '<nop>', opts)
9 vim.g.mapleader = ' '
10
11 -- Polyglot
12 vim.g.polyglot_disabled = {'sensible'}
13
14 -- Plugins
15 local install_path = vim.fn.stdpath('data') .. '/site/pack/paqs/start/paq-nvim'
16
17 if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
18         vim.fn.system({'git', 'clone', '--depth=1',
19                 'https://github.com/savq/paq-nvim.git', install_path})
20 end
21
22 require('paq') {
23         'ap/vim-css-color';               -- Highlight css colors
24         'ctrlpvim/ctrlp.vim';             -- Fuzzy file finding
25         'editorconfig/editorconfig-vim';  -- Follow editorconfig
26         'folke/lsp-colors.nvim';          -- Add LSP colors to any theme
27         'godlygeek/tabular';              -- Line things up
28         'lifepillar/vim-mucomplete';      -- Simple autocompletion
29         'meain/hima-vim';                 -- Nice color scheme
30         'neovim/nvim-lspconfig';          -- LSP configurations
31         'ntpeters/vim-better-whitespace'; -- Highlight and strip whitespace
32         'savq/paq-nvim';                  -- paq manages itself
33         'sheerun/vim-polyglot';           -- Language pack
34         'tpope/vim-commentary';           -- Easily comment
35         'tpope/vim-rsi';                  -- Readline bindings
36         'tpope/vim-sensible';             -- Sensible defaults
37         'tpope/vim-speeddating';          -- Modify dates with C-a, C-x
38         'tpope/vim-surround';             -- Easily modify surrounding chars
39 }
40
41 -- Colorscheme
42 vim.opt.termguicolors = true
43 vim.g.colors_name = 'hima'
44
45 -- Easier split movement
46 map('n', '<C-h>', '<C-w><C-h>', opts)
47 map('n', '<C-j>', '<C-w><C-j>', opts)
48 map('n', '<C-k>', '<C-w><C-k>', opts)
49 map('n', '<C-l>', '<C-w><C-l>', opts)
50
51 -- Clear search highlighting
52 map('n', '<C-c>', ':noh<CR>', opts)
53
54 -- Completion
55 vim.opt.completeopt = vim.opt.completeopt + 'menuone'
56 vim.opt.completeopt = vim.opt.completeopt - 'preview'
57 vim.opt.shortmess = vim.opt.shortmess + 'c'
58
59 -- LSP
60 local lspconfig = require('lspconfig')
61
62 local on_attach = function(client, bufnr)
63         -- Shorthand
64         local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr,
65                 ...) end
66         local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr,
67                 ...) end
68
69         -- Use omnifunc for completion
70         buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
71
72         -- Keybindings
73         buf_set_keymap('n', 'gD',
74                 '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
75         buf_set_keymap('n', 'gd',
76                 '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
77         buf_set_keymap('n', 'gr',
78                 '<cmd>lua vim.lsp.buf.references()<CR>', opts)
79         buf_set_keymap('n', 'K',
80                 '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
81         buf_set_keymap('n', '<leader>rn',
82                 '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
83         buf_set_keymap('n', '[d',
84                 '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
85         buf_set_keymap('n', ']d',
86                 '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
87         buf_set_keymap('n', '<leader>e',
88                 '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
89 end
90
91 -- Add servers
92 local servers = {
93         'clangd'
94 }
95
96 for _, server in ipairs(servers) do
97         lspconfig[server].setup {on_attach = on_attach}
98 end
99
100 vim.opt.signcolumn = 'no'
101
102 -- Jump to files with gf
103 vim.opt.hidden = true
104 vim.opt.path = vim.opt.path + '**'