-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
305 lines (267 loc) · 10.2 KB
/
vimrc
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
" Use plugins
source ~/.vim/bundles.vim
set t_Co=256 " Sets terminal to use 256 colors for CSApprox
set nocompatible " No compatibility with vi to prevent plugin errors.
colorscheme gruvbox
let g:gruvbox_contrast_dark = "hard"
set background=dark
" set nonumber " Never show line numbers
set number " Always show line numbers
set ruler " Show line number in bottom-right of screen
set wrap " Wrap long lines (soft wrap)
set linebreak " Only wrap on breakat characters
set backspace=indent,eol,start " Solve backspace problems
set nolist " List disables linebreak
set nolz " No lazy redraw
" set autochdir " Always cd to the current file's directory
set hidden " Enable undo history for when you switch buffers from one file to another.
set scrolloff=1 " Always have at least one line above or below the cursor.
set tabstop=2 " Set tab width.
set softtabstop=0
set shiftwidth=2
"set noexpandtab " Switch spaces to tabs.
set expandtab " Switch tabs to spaces.
set preserveindent
set copyindent
set mouse=a " Allow mouse.
set laststatus=2 " Always show status bar.
set nofoldenable " Disable Code Folding.
syntax enable " Enable syntax highlighting
set incsearch " Go to search while typing.
set ignorecase " Searches are case insensitive unless uppercase is used.
set smartcase
set exrc " Load project specific vimrcs (for example, spaces versus tabs per project).
set secure " Prevent unwanted scripts from running in project vimrcs.
autocmd VimResized * wincmd =
"set updatetime=750
"set clipboard=unnamed " Use the system clipboard (May require Vim 7.4+).
" Easy escaping to normal model
imap jj <esc>
" Down is really the next line
nnoremap j gj
nnoremap k gk
" Prevent error with :Q instead of :q
command! -bang Q quit<bang>
command! -bang Edit edit<bang>
" Convert Spaces to Tabs for whole file.
command! -range=% -nargs=0 Space2Tab execute '<line1>,<line2>s#^\( \{'.&ts.'\}\)\+#\=repeat("\t", len(submatch(0))/' . &ts . ')'
" Allow easy copying to system clipboard.
vnoremap <C-c> "*y
" Copy file path to clipboard
nnoremap ,cp :let @+=expand("%:p")<CR>
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","
" Fast saves
nmap <leader>w :w!<cr>
" Add Persistent Undo History
if has("persistent_undo")
set undofile
set undodir=$HOME/.vim/undodir/
endif
" Auto Paste modes:
let &t_SI .= "\<Esc>[?2004h"
let &t_EI .= "\<Esc>[?2004l"
if &term =~ '^tmux'
let &t_BE="\<Esc>[?2004h"
let &t_BD="\<Esc>[?2004l"
let &t_PS="\<Esc>[200~"
let &t_PE="\<Esc>[201~"
endif
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
function! XTermPasteBegin()
set pastetoggle=<Esc>[201~
set paste
return ""
endfunction
" Plugin Settings:
" Linting
let g:ale_linters = {
\ 'php': ['php','phpcs'],
\ 'javascript': ['eslint', 'jshint'],
\ 'typescript': ['eslint'],
\ 'scss': ['stylelint']
\}
let g:ale_fixers = {
\ 'php': ['phpcbf'],
\ 'python': ['black', 'isort'],
\ 'javascript': ['eslint'],
\ 'typescript': ['eslint', 'prettier'],
\ 'typescriptreact': ['eslint', 'prettier'],
\ 'mdx': ['prettier'],
\ 'html': ['eslint'],
\ 'scss': ['stylelint']
\}
"let g:ale_linters_ignore = {
"\ 'python': ['pyright'],
"\}
"let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_text_changed = 'normal'
let g:ale_scss_stylelint_use_local_config = 1
let g:ale_linter_aliases = {'typescriptreact': 'typescript'}
let g:ale_fixer_aliases = {'typescriptreact': 'typescript'}
let g:ale_fix_on_save = 1
let g:ale_completion_autoimport = 1
" Disable auto-detection of virtualenvironments
let g:ale_virtualenv_dir_names = ['.venv']
" Environment variable ${VIRTUAL_ENV} is always used
nmap <leader>f :ALEFix<cr>
" LSP
" highlight symbol under cursor
autocmd CursorHold <buffer> silent! lua vim.lsp.buf.document_highlight()
autocmd CursorHoldI <buffer> silent! lua vim.lsp.buf.document_highlight()
autocmd CursorMoved <buffer> silent! lua vim.lsp.buf.clear_references()
" completion
set completeopt=menuone,noselect
set shortmess=filnxtToOFAc
" mappings
" See `:help vim.lsp.*` for documentation on any of the below functions
nnoremap <silent> <c-]> <cmd>lua vim.lsp.buf.definition()<cr>
" nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<cr>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<cr>
nnoremap <silent> gD <cmd>lua vim.lsp.buf.implementation()<cr>
nnoremap <silent> 1gD <cmd>lua vim.lsp.buf.type_definition()<cr>
nnoremap <silent> gn <cmd>lua vim.lsp.buf.rename()<cr>
nnoremap <silent> g0 <cmd>lua vim.lsp.buf.document_symbol()<cr>
nnoremap <silent> gW <cmd>lua vim.lsp.buf.workspace_symbol()<cr>
nnoremap <silent> ga <cmd>lua vim.lsp.buf.code_action()<cr>
" nnoremap <leader>ac <cmd>lua vim.lsp.buf.code_action()<cr>
vnoremap <silent> ga :<c-u>lua vim.lsp.buf.range_code_action()<cr>
nnoremap <silent> <c-J> <cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<cr>
nnoremap <silent> H <cmd>lua vim.lsp.diagnostic.goto_prev()<cr>
nnoremap <silent> L <cmd>lua vim.lsp.diagnostic.goto_next()<cr>
inoremap <silent> <c-s> <cmd>lua vim.lsp.buf.signature_help()<cr>
sign define LspDiagnosticsSignError text=ee texthl=LspDiagnosticsSignError
sign define LspDiagnosticsSignWarning text=ww texthl=LspDiagnosticsSignWarning
sign define LspDiagnosticsSignInformation text=ii texthl=LspDiagnosticsSignInformation
sign define LspDiagnosticsSignHint text=hh texthl=LspDiagnosticsSignHint
highlight link LspDiagnosticsFloatingError LspDiagnosticsFloatingError
highlight link NormalFloat Pmenu
highlight def link LspReference CursorLine
highlight def link LspReferenceText CursorLine
highlight def link LspReferenceWrite CursorLine
highlight def link LspReferenceRead CursorLine
" CoC
map <silent> gd <Plug>(coc-definition)
" map <silent> gy <Plug>(coc-type-definition)
" map <silent> gi <Plug>(coc-implementation)
" map <silent> gr <Plug>(coc-references)
map <leader>rn <Plug>(coc-rename)
" Remap keys for applying codeAction to the current buffer.
map <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
" map <leader>qf <Plug>(coc-fix-current)
" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Git Blame enable.
let g:blamer_enabled = 1
" Enable Git Linker (quickly copying a github/gitlab link to clipboard).
lua << EOF
require"gitlinker".setup()
require("devcontainer").setup{}
EOF
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
"inoremap <silent><expr> <TAB>
"\ pumvisible() ? "\<C-n>" :
"\ <SID>check_back_space() ? "\<TAB>" :
"\ coc#refresh()
"inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
" PHP
let PHP_removeCRwhenUnix = 1
" Only lint on save (to conserve battery life on laptops).
" Vdebug options for debugging PHP.
"if !exists('g:vdebug_options')
"let g:vdebug_options = {}
"endif
" Break on first line of file.
"let g:vdebug_options.break_on_open = 0
let g:ale_php_phpcs_options="--standard=Wpmudev-Plugins-Standard"
let g:ale_php_phpcbf_options="--standard=Wpmudev-Plugins-Standard"
" JavaScript
" Change tab widths to 2 spaces
au FileType javascript setl ts=2 sw=2 sts=2
" Use these linters/sniffers when project includes rc file.
let g:jsx_ext_required = 0
let g:closetag_filenames = "*.html,*.php"
let g:mta_filetypes = {
\ 'html' : 1,
\ 'xhtml' : 1,
\ 'xml' : 1,
\ 'javascript' : 1,
\}
" Emmet JSX Support.
let g:user_emmet_settings = {
\ 'javascript.jsx' : {
\ 'extends': 'jsx',
\ 'quote_char': "'",
\ },
\}
" Autocomplete on typing.
"let g:deoplete#enable_at_startup = 1
" Fix multithread error.
"call deoplete#custom#option('num_processes', 4)
set completeopt+=noinsert
" Disable indentline for json as it conceals double quotes.
let g:indentLine_fileTypeExclude = ['json']
set conceallevel=0 " Do not conceal double quotes in JSON, etc.
" Telescope fuzzy finder.
" Requires BurntSushi/ripgrep.
nnoremap <C-p> <cmd>Telescope find_files<cr>
" NvimTree
" Map NvimTree for easy file navigation
" nmap <leader>nt :NERDTreeToggle<cr>
nmap <leader>nt :NvimTreeToggle<cr>
set encoding=utf-8
" Commenting
" gcc/gbc or gc/gbc to comment/uncomment lines.
" Split to new tab (to open at full size).
nmap <leader>z :tab split<cr>
" DelimitMate
" Auto insert new line for brackets etc.
let delimitMate_expand_cr=1
" Airline
let g:airline_powerline_fonts = 1
" Custom Status (Airline) Options
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_buffers = 0
" Configure Ale with airline.
let g:airline#extensions#ale#enabled = 1
let g:airline_theme="base16_gruvbox_dark_pale"
" Vim-Ai
" Use Ctrl+Y to accept completion
nnoremap <leader>ch :CopilotChatToggle<cr>
xnoremap <leader>ch :CopilotChatToggle<cr>
nnoremap <leader>gf :CopilotChatFix
xnoremap <leader>gf :CopilotChatFix
:lua << END
vim.g["codegpt_openai_api_key"] = os.getenv("OPENAI_API_KEY")
vim.g["codegpt_chat_completions_url"] = "https://api.openai.com/v1/chat/completions"
vim.g["codegpt_commands_defaults"] = {
["completion"] = {
["model"] = "gpt-4"
}
}
local map = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }
map('n', '<leader>ai', '', {
noremap = true,
callback = function()
local input = vim.fn.input("Quick Chat: ")
if input ~= "" then
require("CopilotChat").ask(input, { selection = require("CopilotChat.select").buffer })
end
end,
desc = "CopilotChat - Quick chat"
})
END