-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
330 lines (270 loc) · 9.18 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
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
call plug#begin('~/.config/nvim/plugged')
" Plugins {
" status line
Plug 'itchyny/lightline.vim'
" Cool color theme
Plug 'arcticicestudio/nord-vim'
" Color picker & viewer
Plug 'etdev/vim-hexcolor'
" Language Sintax
Plug 'pangloss/vim-javascript'
Plug 'styled-components/vim-styled-components', { 'branch': 'main' }
Plug 'leafgarland/typescript-vim'
" GIT
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
" VIM Buffer
Plug 'bling/vim-bufferline'
" finder
Plug 'rking/ag.vim'
" text manipulation
Plug 'tpope/vim-surround'
" Manage sessions
Plug 'tpope/vim-obsession'
" Comments
Plug 'tpope/vim-commentary'
" better split navigation
Plug 'christoomey/vim-tmux-navigator'
" indentation style with config files
Plug 'editorconfig/editorconfig-vim'
" use Ranger to explore files
Plug 'francoiscabrol/ranger.vim'
Plug 'rbgrouleff/bclose.vim'
" Telescope
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-telescope/telescope-fzy-native.nvim'
" Graphql
Plug 'jparise/vim-graphql'
" JSX & Typescript
Plug 'pangloss/vim-javascript'
Plug 'leafgarland/typescript-vim'
Plug 'peitalin/vim-jsx-typescript'
" Intellisense Engine
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" .editorconfig
Plug 'editorconfig/editorconfig-vim'
" }
call plug#end()
" Automatically re-read file if a change was detected outside of vim
set autoread
" enable spell-checking
set spell
set spelllang=en
" Here comes the look
let $NVIM_TUI_ENABLE_TRUE_COLOR = 1
colorscheme nord
" line numbers
set relativenumber "show relative line numbers
set number "show current line number
set ruler "show cursor position
" automatic switch line number mode
:augroup numbertoggle
: autocmd!
: autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
: autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
:augroup END
" lightline config
let g:lightline = {
\ 'colorscheme': 'nord',
\ 'separator': { 'left': '▓▒░ ', 'right': ' ░▒▓' },
\ 'subseparator': { 'left': '¦', 'right': '¦' },
\ 'component': {
\ 'readonly': '%{&readonly?"":""}',
\ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}'
\ },
\ 'component_function': {
\ 'gitbranch': 'fugitive#head',
\ 'filename': 'LightLineFilename'
\ },
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'relativepath', 'readonly' ] ],
\ 'right': [ [ 'lineinfo' ],
\ [ 'percent' ],
\ [ 'fileformat', 'fileencoding', 'filetype' ] ]
\ },
\ }
" abbreviated path from https://github.com/itchyny/lightline.vim/issues/87#issuecomment-324988609
function! LightLineFilename()
let name = ""
let subs = split(expand('%'), "/")
let i = 1
for s in subs
let parent = name
if i == len(subs)
let name = parent . '/' . s
elseif i == 1
let name = s
else
let name = parent . '/' . strpart(s, 0, 2)
endif
let i += 1
endfor
return name
endfunction
" Get rid of disturbing sounds
set noerrorbells
" Better splitting
set splitbelow
set splitright
" Show space and tabs
set list
set listchars=tab:→\ ,nbsp:␣,trail:·,extends:»,precedes:«
" Set tabbing
set tabstop=2
set shiftwidth=2
set expandtab
" enable buffer switching without save
set hidden
" Search
set incsearch "Show search preview
set hlsearch "highlight search
"clear search highlight
nnoremap <silent> <C-space> :<C-u>nohlsearch<CR>
" Toggle Session recording with Obsession
map <silent> <leader>s :Obsession<CR>
" This hack is needded to use C-h to navigate splits in nvim see https://github.com/christoomey/vim-tmux-navigator
nnoremap <silent> <BS> :TmuxNavigateLeft<cr>
" Disable tmux navigator when zooming the Vim pane
let g:tmux_navigator_disable_when_zoomed = 1
" Key bindings
" Buffer navigation
nnoremap <silent> [b :bprevious<CR>
nnoremap <silent> ]b :bnext<CR>
nnoremap <silent> ]q :bdelete<CR>
" tab navigation
nnoremap <silent> [t :tabprev<CR>
nnoremap <silent> ]t :tabnext<CR>
nnoremap <silent> [T :tabfirst<CR>
nnoremap <silent> ]T :tablast<CR>
nnoremap <silent> tn :tabnew<CR>
nnoremap <silent> tq :tabclose<CR>
" quick list
nnoremap <silent> [c :cprev<CR>
nnoremap <silent> ]c :cnext<CR>
nnoremap <silent> [C :cfirst<CR>
nnoremap <silent> ]C :clast<CR>
"Git bindings
map <silent> <leader>ga :Git add %<CR>
map <silent> <leader>gb :Git blame<CR>
map <silent> <leader>gc :Git commit<CR>
map <silent> <leader>gl :Git log -- %<CR>
map <silent> <leader>gs :Git<CR>
" Log variable under cursor
map <silent> <leader>pl yiwovar_dump(<C-r>0);<esc>
map <silent> <leader>jl yiwoconsole.log('<C-r>0', <C-r>0);<esc>
" replace word under cursor in line
nnoremap <leader>r yiw <bar> :s/<C-r>0//g<left><left>
" replace word under cursor in buffer
nnoremap <leader>R yiw <bar> :%s/<C-r>0//g<left><left>
" replace matching word in visual selection
vnoremap <leader>r :s///g<left><left>
" find word in files
nnoremap <leader>ff yiw :tabnew \| Ag <C-r>0
nnoremap <leader>fi yiw :tabnew \| Ag <C-r>0 --ignore "bundle.js"
" close and save buffer
nnoremap <C-q> :q<CR>
nnoremap <C-s> :w!<CR>
inoremap <C-s> <esc>:w!<CR>
" move line up
nnoremap <A-j> :m .+1<CR>==
" move line down
nnoremap <A-k> :m .-2<CR>==
" move line to the marked line and indent it
nnoremap <A-m> :m 'm<CR>==
" move line to the marked line and jump back to the line after it
nnoremap <A-M> jm`k :m 'm<CR> ``
" move visual selection to the marked line
vnoremap <A-m> :m 'm<CR>gv=
" replace word with last yanked one
map <leader>ry ciw<C-r>0<ESC>
" past yanked text
inoremap <C-v> <C-r>0
" Copy to system clipboard
map <A-y> "+y
" append date at the end of the line
nnoremap <A-D> A<C-r>=strftime("%x")<CR><ESC>
nnoremap <A-d> A<C-r>=strftime("%B %d %Y")<CR><ESC>
" find lines in current buffer
nmap <A-l> :BLines<CR>
" execute q macro
vnoremap <leader>q :norm! @q<CR>
nnoremap <leader>q @q
" better diff colors
" highlight DiffAdd xxx term=bold ctermbg=12 guibg=LightCyan
" highlight DiffChange xxx term=bold ctermbg=13 guibg=LightBlue
" highlight DiffDelete xxx term=bold ctermfg=12 ctermbg=14 gui=bold guifg=Blue guibg=Red
" highlight DiffText xxx term=reverse cterm=bold ctermbg=9 gui=bold guibg=Red
" set t_Co=16
" === Coc.nvim === "
" use <tab> for trigger completion and navigate to next complete item
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
" Use Enter to confirm completion
inoremap <silent><expr> <cr> coc#pum#visible() ? coc#_select_confirm() : "\<C-g>u\<CR>"
nmap <silent> <leader>dd :call CocAction('jumpDefinition', 'split')<CR>
nmap <silent> <leader>dr :call CocAction('jumpReferences', 'tabe')<CR>
nmap <silent> <leader>di :call CocAction('jumpImplementation', 'split')<CR>
nmap <silent> <leader>f :CocCommand prettier.formatFile<CR>
nmap <leader>ac <Plug>(coc-codeaction)
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>rn <Plug>(coc-rename)
nmap <silent> K :call CocAction('doHover')<CR>
nmap <silent> [c <Plug>(coc-diagnostic-prev)
nmap <silent> ]c <Plug>(coc-diagnostic-next)
function! ShowDocIfNoDiagnostic(timer_id)
if (coc#float#has_float() == 0 && CocHasProvider('hover') == 1)
silent call CocActionAsync('doHover')
endif
endfunction
function! s:show_hover_doc()
call timer_start(500, 'ShowDocIfNoDiagnostic')
endfunction
autocmd CursorHoldI * :call <SID>show_hover_doc()
autocmd CursorHold * :call <SID>show_hover_doc()
"
" === vim-better-whitespace === "
" <leader>y - Automatically remove trailing whitespace
nmap <leader>y :StripWhitespace<CR>
" === Telescope === "
nnoremap <C-p> :lua require('telescope.builtin').git_files()<CR>
nnoremap <leader>pw :lua require('telescope.builtin').grep_string { search = vim.fn.expand("<cword>") }<CR>
nnoremap <leader>ps :lua require('telescope.builtin').grep_string({ search = vim.fn.input("Grep For > ")})<CR>
lua << EOS
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local previewers = require("telescope.previewers")
local action_state = require("telescope.actions.state")
local conf = require("telescope.config").values
local actions = require("telescope.actions")
require("telescope").setup({
defaults = {
file_sorter = require("telescope.sorters").get_fzy_sorter,
prompt_prefix = " >",
color_devicons = true,
file_previewer = require("telescope.previewers").vim_buffer_cat.new,
grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new,
qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new,
mappings = {
i = {
["<C-q>"] = actions.send_to_qflist,
},
},
},
extensions = {
fzy_native = {
override_generic_sorter = false,
override_file_sorter = true,
},
},
})
require("telescope").load_extension("fzy_native")
EOS
:set mouse=nv