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