-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.vim
More file actions
465 lines (424 loc) · 14 KB
/
init.vim
File metadata and controls
465 lines (424 loc) · 14 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
call plug#begin()
Plug 'nvim-tree/nvim-web-devicons'
Plug 'nvim-tree/nvim-tree.lua'
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'qpkorr/vim-bufkill'
Plug 'dcampos/nvim-snippy'
Plug 'dcampos/cmp-snippy'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'phha/zenburn.nvim'
Plug 'vim-airline/vim-airline'
Plug 'j-hui/fidget.nvim', { 'tag': 'legacy' }
Plug 'nathanaelkane/vim-indent-guides'
Plug 'christoomey/vim-tmux-navigator'
Plug 'ojroques/vim-oscyank'
Plug 'vim-syntastic/syntastic'
Plug 'tpope/vim-fugitive'
Plug 'folke/trouble.nvim'
Plug 'MeanderingProgrammer/render-markdown.nvim'
Plug 'mfussenegger/nvim-dap'
Plug 'nvim-neotest/nvim-nio'
Plug 'rcarriga/nvim-dap-ui'
Plug 'folke/lazydev.nvim'
" Common dependency across multiple plugins
Plug 'nvim-lua/plenary.nvim'
" =====================
" Code Companion Start
" =====================
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'nvim-telescope/telescope.nvim'
Plug 'olimorris/codecompanion.nvim'
" =====================
" Copilot
" =====================
"Plug 'github/copilot.vim'
"Plug 'CopilotC-Nvim/CopilotChat.nvim'
call plug#end()
" =====================
" Behavior
" =====================
" Delete text without overwriting your register
" D to delete a whole line
" X to delete a single character or selection
nnoremap <silent> D "_dd
nnoremap <silent> X "_x
vnoremap <silent> X "_x
" Copy and paste support in unix env
set clipboard+=unnamed,unnamedplus
set iskeyword-=_
" Copy yanked text from register to clipboard
command! Y call OSCYank(getreg('+'))
" Quick resize panes with leader `\` + command
" resize current buffer by +/- 10
" resize horizontal
nnoremap <Leader>[ :vertical resize -10<cr>
nnoremap <Leader>] :vertical resize +10<cr>
" resize veritical
nnoremap <Leader>- :resize -10<cr>
nnoremap <Leader>= :resize +10<cr>
" Hack to get custom path from lua function to execute with \y
noremap <Leader>y :FileLineNum<CR>
noremap <Leader>m :Path<CR>
" Buffer swapping
map <Tab> :bn<CR>
map <S-Tab> :bp<CR>
map <C-c> :BD<CR>
" =====================
" FZF and Ag
" =====================
" :Rag allows passing a directory to :Ag
" And enables a preview window located above the search reuslts
" that is toggled on and off with `?`
"
" Usage: :Rag foo path/
map <C-p> :FZF<CR>
map <C-f> :Ag<CR>
command! -bang -nargs=+ -complete=dir Rag call fzf#vim#ag_raw(<q-args>, fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'up:50%:hidden', '?'), <bang>0)
" Ag search (silver searcher plugin)
let g:ackprg = 'ag --nogroup --nocolor --column'
" =====================
" UX / UI
" =====================
" Code folding
set foldmethod=syntax
set foldlevelstart=20
" Status bar
let g:airline#extensions#tabline#enabled = 1
" Flag trailing whitespace
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
" Syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
map <C-w> :SyntasticCheck<CR>
map <C-e> :SyntasticReset<CR>
let g:syntastic_mode_map = {"mode": "passive"}
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_python_checkers = ['pylint']
let g:syntastic_js_checkers = ['eslint']
" Syntax settings
filetype plugin indent on
syntax on
set encoding=utf-8
colorscheme zenburn
set t_Co=256
set nu
colorscheme zenburn
set cursorline
set expandtab
set showmatch
set hlsearch
set ignorecase
:highlight CursorLine ctermbg=16
:highlight Visual ctermbg=16
" File tab defaults
autocmd BufNewFile,BufRead *.py setlocal tabstop=4 softtabstop=4 shiftwidth=4 expandtab smarttab autoindent
autocmd BufNewFile,BufRead *.go setlocal tabstop=4 softtabstop=4 shiftwidth=4 smarttab autoindent noexpandtab
autocmd BufNewFile,BufRead *.js setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab autoindent
autocmd BufNewFile,BufRead *.json setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab autoindent
autocmd BufNewFile,BufRead *.jsx setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab autoindent
autocmd BufNewFile,BufRead *.tsx setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab autoindent
autocmd BufNewFile,BufRead *.ts setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab autoindent
autocmd BufNewFile,BufRead *.hbs setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab autoindent
autocmd BufNewFile,BufRead *.esj setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab autoindent
autocmd BufNewFile,BufRead *.html setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab autoindent
autocmd BufNewFile,BufRead *.scss setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab autoindent
autocmd BufNewFile,BufRead *.css setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab autoindent
autocmd BufNewFile,BufRead *.styl setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab autoindent
autocmd BufNewFile,BufRead *.vim setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab autoindent
" =====================
" Lua Configs Start
" =====================
lua << EOF
-- =====================
-- NVIM Tree
-- =====================
-- Commands
-- a: add directory or file
-- c: copy
-- p: paste
-- m: bookmark
-- o or <CR>: open
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.opt.termguicolors = true
vim.keymap.set('n', '<C-n>', ':NvimTreeToggle<CR>', { silent = true })
vim.keymap.set('n', '<Leader>v', ':NvimTreeFindFile<CR>', { silent = true })
require('nvim-tree').setup({
sort = {
sorter = 'case_sensitive',
},
view = {
width = 70,
number = true,
},
renderer = {
group_empty = true,
},
filters = {
dotfiles = false,
},
})
-- Output errors to one-of quickfix or location list (uncomment whichever you need)
-- Output errors to location list
vim.api.nvim_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', { noremap=true, silent=true })
-- Output errors to quickfix list
-- vim.api.nvim_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setqflist()<CR>', opts)
-- Fidget spinner for processing UX
require("fidget").setup {}
-- Access LSP diagnostics with `:Trouble`
require("trouble").setup {}
require('telescope').setup {}
-- Install font nerd to resolve missing icons
-- Ref: https://github.com/MeanderingProgrammer/render-markdown.nvim/wiki/Fonts#font-nerd
require('render-markdown').setup()
-- =====================
-- Custom Commands
-- =====================
-- Copy file path and line number with `:FileLineNum`
vim.api.nvim_create_user_command("FileLineNum", function()
local path = vim.fn.expand("%")
local line = vim.fn.line(".")
local out = path .. ":" .. line
vim.fn.setreg("+", out)
vim.notify('Copied "' .. out .. '" to the clipboard!')
end, {})
-- Copy file path and without number with `:Path`
vim.api.nvim_create_user_command("Path", function()
local path = vim.fn.expand("%:.:h")
vim.fn.setreg("+", path)
vim.notify('Copied "' .. path .. '" to the clipboard!')
end, {})
-- =====================
-- NVIM DAP
-- =====================
-- Usage
-- DapNew
-- DapTerminate
-- <C-b> or DapToggleBreakpoint
-- DapClearBreakpoints
-- DapStepOver
-- DapStepInto
-- DapContinue
require("dapui").setup()
require("lazydev").setup({
library = { "nvim-dap-ui" },
})
-- Map DapToggleBreakpoint to ctrl+b
vim.keymap.set('n', '<C-b>', function()
require('dap').toggle_breakpoint()
end, { noremap = true, silent = true})
local dap, dapui = require("dap"), require("dapui")
dap.adapters.delve = {
type = 'server',
port = 2345
}
dap.configurations.go = {
{
type = 'delve',
request = 'attach',
name = 'Attach to Go',
mode = 'remote',
},
}
dap.listeners.before.attach.dapui_config = function()
dapui.open()
end
dap.listeners.before.launch.dapui_config = function()
dapui.open()
end
dap.listeners.before.event_terminated.dapui_config = function()
dapui.close()
end
dap.listeners.before.event_exited.dapui_config = function()
dapui.close()
end
-- Fix dap-ui bug with nvim-tree
vim.api.nvim_create_augroup('DAP_UI_RESET', {clear = true})
local bufferNames = {}
vim.api.nvim_create_autocmd({'BufWinEnter'}, {
group = 'DAP_UI_RESET',
pattern = '*',
callback = function()
local bufferName = vim.fn.expand('%')
if dap.session() and bufferName ~= 'DAP Watches' and bufferName ~= 'DAP Stacks' and bufferName ~= 'DAP Breakpoints' and bufferName ~= 'Dap Console' and not string.find(bufferName, '%[dap%-repl%-', 1) and bufferName ~= 'Dap Hover' and bufferName ~= '[dap-terminal] Launch file' then
table.insert(bufferNames, vim.fn.expand('%:p'))
print('Buffer Name - ' .. vim.fn.expand('%'))
dapui.open({reset = true})
end
end
})
vim.api.nvim_create_autocmd({'BufUnload', 'BufHidden'}, {
group = 'DAP_UI_RESET',
pattern = '*',
callback = function(args)
if dap.session() then
for i = 1, #bufferNames do
local index = -1
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if bufferNames[i] == vim.api.nvim_buf_get_name(buf) then
index = vim.api.nvim_buf_get_number(buf)
break
end
end
vim.schedule(function ()
if vim.fn.bufwinid(index) == -1 then
table.remove(bufferNames, i)
dapui.open({reset = true})
end
end)
end
end
end
})
-- =====================
-- LSP Settings
-- =====================
-- Usage
-- `gd` - go to def
-- `gr` - find references
-- `gi` - find implementation
-- `<space>D` get defintion
-- `<space>F` formatter
local on_attach = function(client, bufnr)
local opts = { noremap=true, silent=true, buffer=bufnr }
local bufname = vim.api.nvim_buf_get_name(bufnr)
-- Detach if buffer has no filename.
if bufname == '' then
vim.defer_fn(function()
vim.lsp.buf_detach_client(bufnr, client.id)
end, 0)
return
end
vim.lsp.set_log_level("debug")
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
end
local lsp_capabilities = require('cmp_nvim_lsp').default_capabilities()
vim.lsp.config('gopls', {
cmd = {'gopls', '-remote=auto'},
on_attach = on_attach,
capabilities = lsp_capabilities,
init_options = vim.empty_dict(),
flags = {
-- Don't spam LSP with changes. Wait a second between each.
debounce_text_changes = 1000,
},
})
vim.lsp.enable('gopls')
-- =====================
-- Code Complete
-- =====================
-- Usage
-- `Shift Tab` to select a previous suggestion
-- `Tab` to select the next suggestion
-- `Control + Space` to accept the suggestion
local cmp = require 'cmp'
cmp.setup({
snippet = {
expand = function(args)
require('snippy').expand_snippet(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<c-space>"] = cmp.mapping.confirm({select = true}),
["<s-tab>"] = cmp.mapping.select_prev_item(),
["<tab>"] = cmp.mapping.select_next_item(),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'snippy' },
{ name = 'buffer' },
{ name = 'path' },
}),
})
-- =====================
-- CodeCompanion
-- =====================
-- Usage (From view mode)
-- `:CodeCompanionChat Add` - add highlighted text to an active chat
-- `:CodeCompanionChat` - open a new chat
-- `:CodeCompanionActions` - open actions modal
-- `:CodeCompanion ${prompt}` - inline prompt to modify active buffer
--
-- Usage (from chat buffer)
-- `/ <C-_>` opens a helper (from edit mode)
-- `# <C-_>` opens a variable (from edit mode)
-- `@ <C-_>` opens a tool (from edit mode)
-- `gd` - view debug info from chat (from view mode)
--
-- Ref API Key conf: https://codecompanion.olimorris.dev/getting-started.html
require("codecompanion").setup({
strategies = {
chat = {
adapter = "openai",
model = "gpt-5-mini",
},
inline = {
adapter = "openai",
model = "gpt-5-mini",
},
},
})
vim.api.nvim_create_autocmd({"BufEnter", "BufReadPost"}, {
pattern = "*CodeCompanion*",
callback = function()
vim.bo.filetype = "markdown"
local ok, md = pcall(require, "render-markdown")
if ok and md.refresh then
md.refresh()
end
end
})
-- =====================
-- Copilot
-- =====================
-- Copilot configuration and install
--
-- nvm install node
-- :Copilot setup
-- Visit https://github.com/login/device to input code
--
-- Usage Copilot Core Plugin:
-- <Leader><space> to accept copilot suggestion
-- <Leader><tab> to go to next suggestion
-- <Leader><s-tab> to go to previous suggestion
--
-- Usage Copiot Chat Plugin:
-- :CopilotChatOpen to open chat session
-- :CopilotChatReset to reset chat session
-- :CopilotChat <input>? to send message to chat
-- :CopilotChatExplain to get explanation of selection in buffer
-- :CopilotChatReview to review selected code
-- :CopilotChatFix to rewrite buggy code
-- :CopilotChatDocs to add documentation for the selection in buffer
-- :CopilotChatTests tog enerate tests for the code
--vim.g.copilot_no_tab_map = true
--vim.api.nvim_set_keymap("i", "<Leader><space>", 'copilot#Accept("<CR>")', { silent = true, expr = true })
--vim.keymap.set("i", "<Leader><tab>", '<Plug>(copilot-next)')
--vim.keymap.set("i", "<Leader><s-tab>", '<Plug>(copilot-previous)')
--require("CopilotChat").setup {
-- debug = true,
--}
EOF