-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnvim.lua
More file actions
274 lines (227 loc) · 7.64 KB
/
nvim.lua
File metadata and controls
274 lines (227 loc) · 7.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-- https://github.com/folke/lazy.nvim
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
vim.fn.system {
'git',
'clone',
'--filter=blob:none',
'https://github.com/folke/lazy.nvim.git',
'--branch=stable',
lazypath,
}
end
vim.opt.rtp:prepend(lazypath)
require('lazy').setup({
-- Git related plugins
'tpope/vim-fugitive',
'tpope/vim-rhubarb',
-- LSP Configuration
'neovim/nvim-lspconfig',
-- Automatically add completing braces
{
'windwp/nvim-autopairs',
event = "InsertEnter",
opts = {}
},
-- Useful plugin to show you pending keybinds.
{ 'folke/which-key.nvim', opts = {} },
-- Adds git related signs to the gutter, as well as utilities for managing changes
{ 'lewis6991/gitsigns.nvim', opts = {} },
-- Color scheme
{
'hexbloom/zenburn.nvim',
branch = 'semantic-highlight-support',
lazy = false,
priority = 1000,
},
-- Set lualine as statusline
{
'nvim-lualine/lualine.nvim',
opts = {
options = {
icons_enabled = false,
component_separators = '|',
section_separators = '',
theme = 'zenburn',
},
sections = {
lualine_b = { 'filename' },
lualine_c = { 'diagnostics' },
lualine_x = { 'branch' },
lualine_y = {},
},
inactive_sections = {
lualine_x = { '' },
},
extensions = { 'nvim-tree' },
},
},
-- "gc" to comment visual regions/lines
{ 'numToStr/Comment.nvim', opts = {} },
-- Fuzzy Finder (files, lsp, etc)
{
'nvim-telescope/telescope.nvim',
dependencies = {
'nvim-lua/plenary.nvim',
},
},
-- File tree
{
'nvim-tree/nvim-tree.lua',
lazy = false,
dependencies = {
'nvim-tree/nvim-web-devicons',
},
opts = {
sort = {
sorter = "case_sensitive",
},
view = {
width = 26,
},
renderer = {
root_folder_label = false,
highlight_git = true,
indent_width = 1,
icons = {
glyphs = {
git = {
staged = "",
unstaged = "",
untracked = "",
},
},
},
},
filters = {
custom = { "^.git$" },
},
},
}
}, {})
-- [[ Setting options ]]
-- Set color scheme
vim.cmd("colorscheme zenburn")
-- Javascript highlight customization
vim.cmd("hi link javaScriptGlobal NONE")
vim.cmd("hi link javaScriptMember NONE")
-- Set highlight on search
vim.o.hlsearch = false
-- Make line numbers default
vim.wo.number = true
-- Enable mouse mode
vim.o.mouse = 'a'
-- Sync clipboard between OS and Neovim.
vim.o.clipboard = 'unnamedplus'
-- Enable break indent
vim.o.breakindent = true
-- Enable cursor highlight
vim.o.cursorline = true
-- Diable line wrapping
vim.o.wrap = false
-- Save undo history
vim.o.undofile = true
vim.o.backup = false
vim.o.writebackup = false
vim.o.swapfile = false
-- Case-insensitive searching UNLESS \C or capital in search
vim.o.ignorecase = true
vim.o.smartcase = true
-- Keep signcolumn on by default
vim.wo.signcolumn = 'yes'
-- Popup height
vim.o.pumheight = 5
-- Tabs and spaces settings
vim.o.expandtab = true
vim.o.tabstop = 4
vim.o.shiftwidth = 4
-- Decrease update time
vim.o.updatetime = 250
vim.o.timeoutlen = 300
-- Hide the command history
vim.o.showcmd = false
-- Set completeopt to have a better completion experience
vim.o.completeopt = 'menuone,noselect'
-- RGB colors in terminal
vim.o.termguicolors = true
-- Show empty space instead of ~ at the end of a buffer
vim.o.fillchars = 'eob: '
-- [[ Basic Keymaps ]]
-- Keymaps for better default experience
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
vim.keymap.set('n', 'q', '<Nop>', { silent = true })
-- Remap for dealing with word wrap
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
-- Common operations
vim.keymap.set('n', '<leader>z', ":e $MYVIMRC<cr>", { desc = 'Open NeoVim config file' })
vim.keymap.set('n', '<leader>q', ":qa<cr>", { desc = 'Quit NeoVim' })
vim.keymap.set('n', '<C-s>', ":wa<cr>", { desc = 'Save all' })
vim.keymap.set('i', '<C-s>', "<ESC>:wa<cr>")
vim.keymap.set('n', '<leader>K', ":lua vim.diagnostic.open_float()<cr>", { desc = "Open diagnostics for current line" })
-- Custom shell commands
vim.keymap.set('n', '<leader>b', ":!zig build<cr>")
vim.keymap.set('n', '<leader>p', ":!zig build run<cr>")
-- Tab autocompletion in insert mode
vim.api.nvim_exec2([[
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-n>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
]], {})
vim.keymap.set('i', '<S-tab>', "<C-p>")
-- Telescope remaps
vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' })
vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' })
vim.keymap.set('n', '<leader>/', require('telescope.builtin').current_buffer_fuzzy_find, { desc = '[/] Fuzzily search in current buffer' })
vim.keymap.set('n', '<leader>t', require('telescope.builtin').builtin, { desc = 'Search Select [T]elescope' })
vim.keymap.set('n', '<leader>F', require('telescope.builtin').find_files, { desc = 'Search all [F]iles' })
vim.keymap.set('n', '<leader>f', require('telescope.builtin').git_files, { desc = 'Search Git [f]iles' })
vim.keymap.set('n', '<leader>s', require('telescope.builtin').live_grep, { desc = '[S]earch by Grep' })
-- [[ Configure LSP ]]
-- This function gets run when an LSP connects to a particular buffer.
local on_attach = function(_, bufnr)
local nmap = function(keys, func, desc)
if desc then
desc = 'LSP: ' .. desc
end
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
end
nmap('<leader>r', vim.lsp.buf.rename, '[R]ename')
nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
-- See `:help K` for why this keymap
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
-- format on save
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
callback = function()
vim.lsp.buf.format { async = false }
end,
})
end
-- LSP clients
local capabilities = vim.lsp.protocol.make_client_capabilities()
local lspconfig = require('lspconfig')
lspconfig.clangd.setup {
on_attach = on_attach,
capabilities = capabilities,
cmd = { 'clangd', '--function-arg-placeholders=0' },
}
lspconfig.zls.setup {
on_attach = on_attach,
capabilities = capabilities,
cmd = { 'zls' },
}