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