]> git.armaanb.net Git - dotfiles.git/blob - .config/nvim/init.lua
9708fa86a34db74c14c8382fc95c24237c27a888
[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 -- Plugins
12 local install_path = vim.fn.stdpath('data') .. '/site/pack/paqs/start/paq-nvim'
13
14 if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
15         vim.fn.system({'git', 'clone', '--depth=1',
16                 'https://github.com/savq/paq-nvim.git', install_path})
17 end
18
19 require('impatient')
20
21 require('paq') {
22         'dstein64/vim-startuptime';       -- Profile startup time
23         'editorconfig/editorconfig-vim';  -- Follow editorconfig
24         'folke/lsp-colors.nvim';          -- Add LSP colors to any theme
25         'godlygeek/tabular';              -- Line things up
26         'junegunn/fzf';                   -- Fuzzy file finding
27         'junegunn/fzf.vim';               -- Fuzzy file finding
28         'lewis6991/impatient.nvim';       -- Improve startup time
29         'lifepillar/vim-mucomplete';      -- Simple autocompletion
30         'meain/hima-vim';                 -- Nice color scheme
31         'nathom/filetype.nvim';           -- Faster filetype.vim replacement
32         'neovim/nvim-lspconfig';          -- LSP configurations
33         'norcalli/nvim-colorizer.lua';    -- Highlight css colors
34         'ntpeters/vim-better-whitespace'; -- Highlight and strip whitespace
35         'nvim-treesitter/nvim-treesitter';-- Parsing
36         'romgrk/nvim-treesitter-context'; -- Shows context for where you are
37         'savq/paq-nvim';                  -- paq manages itself
38         'tpope/vim-commentary';           -- Easily comment
39         'tpope/vim-rsi';                  -- Readline bindings
40         'tpope/vim-sensible';             -- Sensible defaults
41         'tpope/vim-speeddating';          -- Modify dates with C-a, C-x
42         'tpope/vim-surround';             -- Easily modify surrounding chars
43 }
44
45 -- Colorscheme
46 vim.opt.termguicolors = true
47 vim.g.colors_name = 'hima'
48
49 -- Easier split movement
50 map('n', '<C-h>', '<C-w><C-h>', opts)
51 map('n', '<C-j>', '<C-w><C-j>', opts)
52 map('n', '<C-k>', '<C-w><C-k>', opts)
53 map('n', '<C-l>', '<C-w><C-l>', opts)
54
55 -- Clear search highlighting
56 map('n', '<C-c>', ':noh<CR>', opts)
57
58 -- FZF
59 map('n', '<leader>ff', ':Files<CR>', opts)
60 -- TODO: Sharp corners... I can't figure this out
61
62 -- Disable keyword completion
63 map('i', '<C-n>', '<Down>', opts)
64 map('i', '<C-p>', '<Up>', opts)
65
66 -- Completion
67 vim.opt.completeopt = vim.opt.completeopt + 'menuone'
68 vim.opt.completeopt = vim.opt.completeopt - 'preview'
69 vim.opt.shortmess = vim.opt.shortmess + 'c'
70
71 -- LSP
72 local lspconfig = require('lspconfig')
73
74 local on_attach = function(client, bufnr)
75         -- Shorthand
76         local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr,
77                 ...) end
78         local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr,
79                 ...) end
80
81         -- Use omnifunc for completion
82         buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
83
84         -- Keybindings
85         buf_set_keymap('n', 'gD',
86                 '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
87         buf_set_keymap('n', 'gd',
88                 '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
89         buf_set_keymap('n', 'gr',
90                 '<cmd>lua vim.lsp.buf.references()<CR>', opts)
91         buf_set_keymap('n', 'K',
92                 '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
93         buf_set_keymap('n', '<leader>rn',
94                 '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
95         buf_set_keymap('n', '[d',
96                 '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
97         buf_set_keymap('n', ']d',
98                 '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
99         buf_set_keymap('n', '<leader>e',
100                 '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
101 end
102
103 -- Add servers
104 local servers = {
105         'clangd'
106 }
107
108 for _, server in ipairs(servers) do
109         lspconfig[server].setup {on_attach = on_attach}
110 end
111
112 vim.opt.signcolumn = 'no'
113
114 -- Jump to files with gf
115 vim.opt.hidden = true
116 vim.opt.path = vim.opt.path + '**'
117
118 -- Disable intro message
119 vim.opt.shortmess = "I"
120
121 -- Treesitter
122 require('nvim-treesitter.configs').setup {
123         ensure_installed = "maintained",
124         highlight = {
125                 enable = true,
126                 additional_vim_regex_highlighting = false,
127         },
128         incremental_selection = {
129                 enable = true,
130                 keymaps = {
131                         init_selection = "gnn",
132                         node_incremental = "grn",
133                         scope_incremental = "grc",
134                         node_decremental = "grm",
135                 },
136         },
137         indent = {
138                 enable = true
139         }
140 }
141
142 -- Folds
143 vim.opt.foldmethod = 'expr'
144 vim.opt.foldexpr = 'nvim_treesitter#foldexpr()'
145 vim.opt.foldenable = false
146 map('n', '<leader>fe', ':set foldenable<CR>', opts)
147 map('n', '<leader>fd', ':set nofoldenable<CR>', opts)