-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
246 lines (205 loc) · 7.47 KB
/
init.vim
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
set path+=**
" Nice menu when typing `:find *.py`
set wildmode=longest,list,full
set wildmenu
" Ignore files
set wildignore+=*.pyc
set wildignore+=*_build/*
set wildignore+=**/coverage/*
set wildignore+=**node_modules/*
set wildignore+=**/android/*
set wildignore+=**/ios/*
set wildignore+=**/.git/*
set relativenumber
call plug#begin('~/.vim/plugged')
" temp
Plug 'ThePrimeagen/vim-be-good'
" themes
Plug 'gruvbox-community/gruvbox'
Plug 'folke/tokyonight.nvim', { 'branch': 'main' }
Plug 'rebelot/kanagawa.nvim'
Plug 'maxmellon/vim-jsx-pretty'
Plug 'wuelnerdotexe/vim-astro'
Plug 'catppuccin/nvim', {'as': 'catppuccin'}
" lsp Plugins
" for typescript, see: https://jose-elias-alvarez.medium.com/configuring-neovims-lsp-client-for-typescript-development-5789d58ea9c
Plug 'neovim/nvim-lspconfig'
Plug 'jose-elias-alvarez/null-ls.nvim'
Plug 'jose-elias-alvarez/nvim-lsp-ts-utils'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/nvim-cmp'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'onsails/lspkind-nvim'
Plug 'github/copilot.vim'
Plug 'nvim-lua/lsp_extensions.nvim'
Plug 'darrikonn/vim-gofmt'
Plug 'simrat39/symbols-outline.nvim'
" telescope requirements...
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-telescope/telescope-fzy-native.nvim'
Plug 'ThePrimeagen/harpoon'
Plug 'flazz/vim-colorschemes'
" prettier
Plug 'sbdchd/neoformat'
" commenting
Plug 'tpope/vim-commentary'
" floating terminal windows
Plug 'voldikss/vim-floaterm'
" .NET c#
" Plug 'OmniSharp/omnisharp-vim'
" Plug 'dense-analysis/ale'
call plug#end()
" set default colorscheme/theme
colorscheme gruvbox
if executable('rg')
let g:rg_derive_root='true'
endif
let loaded_matchparen = 1
let mapleader = " "
" let g:OmniSharp_server_stdio = 1
" let g:OmniSharp_server_use_mono = 0
" let g:ale_linters = {
" \ 'cs': ['OmniSharp']
" \}
map <C-s> <C-w>
" stop c commands from yanking
nnoremap c "_c
xnoremap c "_c
nnoremap <silent> Q <nop>
nnoremap <leader>pp <cmd>Telescope find_files<cr>
nnoremap <leader>ff <cmd>Telescope live_grep<cr>
nnoremap <leader>rr <cmd>Telescope resume<cr>
nnoremap <leader>ww <cmd>Telescope grep_string<cr>
vnoremap <leader>vv "zy:Telescope live_grep default_text=<C-r>z<cr>
nnoremap <silent> <C-t> :silent !tmux neww tmux-sessionizer<CR>
nmap <leader><Tab> <c-^><cr>
nnoremap <leader>vwh :h <C-R>=expand("<cword>")<CR><CR>
nnoremap <leader>bs /<C-R>=escape(expand("<cWORD>"), "/")<CR><CR>
nnoremap <leader>pv :Ex<CR>
nnoremap <Leader><CR> :so ~/.config/nvim/init.vim<CR>
nnoremap <Leader>+ :vertical resize +5<CR>
nnoremap <Leader>- :vertical resize -5<CR>
nnoremap <Leader>rp :resize 100<CR>
nnoremap <Leader>ee oif err != nil {<CR>log.Fatalf("%+v\n", err)<CR>}<CR><esc>kkI<esc>
nnoremap <Leader>cpu a%" PRIu64 "<esc>
nnoremap <leader>s :%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>
nnoremap <leader>gt <Plug>PlenaryTestFile
nnoremap <leader>m :lua require("harpoon.mark").add_file()<CR>
nnoremap <leader>h :lua require("harpoon.ui").toggle_quick_menu()<CR>
nnoremap <leader>gll :let g:_search_term = expand("%")<CR><bar>:Gclog -- %<CR>:call search(g:_search_term)<CR>
nnoremap <leader>gln :cnext<CR>:call search(_search_term)<CR>
nnoremap <leader>glp :cprev<CR>:call search(_search_term)<CR>
nnoremap <leader>nf :!./scripts/format.py %
nnoremap <leader>lg <cmd>FloatermNew --autoclose=2 --height=0.9 --width=0.9 lazygit<cr>
nnoremap <leader>x :silent !chmod +x %<CR>
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
nnoremap Y yg$
nnoremap n nzzzv
nnoremap N Nzzzv
nnoremap J mzJ`z
" greatest remap ever
xnoremap <leader>p "_dP
" next greatest remap ever : asbjornHaland
nnoremap <leader>y "+y
vnoremap <leader>y "+y
nnoremap <leader>Y gg"+yG
nnoremap <leader>d "_d
vnoremap <leader>d "_d
inoremap <C-c> <esc>
inoremap <expr> <cr> coc#pum#visible() ? coc#pum#confirm() : "\<CR>"
fun! EmptyRegisters()
let regs=split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-"', '\zs')
for r in regs
call setreg(r, [])
endfor
endfun
" ES
com! W w
nmap <leader>nn :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
augroup highlight_yank
autocmd!
autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank({timeout = 40})
augroup END
" augroup fmt
" autocmd!
" autocmd BufWritePre * undojoin | Neoformat
" augroup END
" custom gitlense setup, see https://dev.to/jamestthompson3/neovim-tip-gitlens-31ml
lua vim.api.nvim_command [[autocmd CursorHold * lua require'utils'.blameVirtText()]]
lua vim.api.nvim_command [[autocmd CursorMoved * lua require'utils'.clearBlameVirtText()]]
lua vim.api.nvim_command [[autocmd CursorMovedI * lua require'utils'.clearBlameVirtText()]]
hi! link GitLens Comment
lua << EOF
local lspconfig = require("lspconfig")
local null_ls = require("null-ls")
require('telescope').setup{ defaults = { file_ignore_patterns = {"node_modules"}, path_display = {"shorten"} } }
local buf_map = function(bufnr, mode, lhs, rhs, opts)
vim.api.nvim_buf_set_keymap(
bufnr,
mode,
lhs,
rhs,
opts or
{
silent = true
}
)
end
local on_attach = function(client, bufnr)
vim.cmd("command! LspDef lua vim.lsp.buf.definition()")
vim.cmd("command! LspFormatting lua vim.lsp.buf.formatting()")
vim.cmd("command! LspCodeAction lua vim.lsp.buf.code_action()")
vim.cmd("command! LspHover lua vim.lsp.buf.hover()")
vim.cmd("command! LspRename lua vim.lsp.buf.rename()")
vim.cmd("command! LspRefs lua vim.lsp.buf.references()")
vim.cmd("command! LspTypeDef lua vim.lsp.buf.type_definition()")
vim.cmd("command! LspImplementation lua vim.lsp.buf.implementation()")
vim.cmd("command! LspDiagPrev lua vim.diagnostic.goto_prev()")
vim.cmd("command! LspDiagNext lua vim.diagnostic.goto_next()")
vim.cmd("command! LspDiagLine lua vim.diagnostic.open_float()")
vim.cmd("command! LspSignatureHelp lua vim.lsp.buf.signature_help()")
buf_map(bufnr, "n", "gd", ":LspDef<CR>")
buf_map(bufnr, "n", "gr", ":LspRename<CR>")
buf_map(bufnr, "n", "gy", ":LspTypeDef<CR>")
buf_map(bufnr, "n", "K", ":LspHover<CR>")
buf_map(bufnr, "n", "[a", ":LspDiagPrev<CR>")
buf_map(bufnr, "n", "]a", ":LspDiagNext<CR>")
buf_map(bufnr, "n", "ga", ":LspCodeAction<CR>")
buf_map(bufnr, "n", "<Leader>a", ":LspDiagLine<CR>")
buf_map(bufnr, "i", "<C-x><C-x>", "<cmd> LspSignatureHelp<CR>")
if client.resolved_capabilities.document_formatting then
vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()")
end
end
lspconfig.tsserver.setup(
{
on_attach = function(client, bufnr)
client.resolved_capabilities.document_formatting = false
client.resolved_capabilities.document_range_formatting = false
local ts_utils = require("nvim-lsp-ts-utils")
ts_utils.setup({})
ts_utils.setup_client(client)
buf_map(bufnr, "n", "gs", ":TSLspOrganize<CR>")
buf_map(bufnr, "n", "gi", ":TSLspRenameFile<CR>")
buf_map(bufnr, "n", "go", ":TSLspImportAll<CR>")
on_attach(client, bufnr)
end
}
)
null_ls.setup(
{
sources = {
null_ls.builtins.diagnostics.eslint_d,
null_ls.builtins.code_actions.eslint_d,
null_ls.builtins.formatting.prettier
},
on_attach = on_attach
}
)
EOF