-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.vimrc
606 lines (539 loc) · 18.9 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
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
" vim: foldlevel=2:
" Courtsey:
" Vincent Driessen <[email protected]>
" http://nvie.com/posts/how-i-boosted-my-vim/
" Tsung-Hsiang (Sean) Chang <[email protected]>
" https://github.com/vgod/vimrc/blob/master/vimrc
" junegunn:
" https://github.com/junegunn/dotfiles/blob/master/vimrc
" https://github.com/yoshuawuyts/dotfiles
" And Vim User Manual
" Set as 'not compatible' with the old-fashion vi mode
set nocompatible
"---------------------------------------------------------------------------
" vim-plug setup
"---------------------------------------------------------------------------
" {{{
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall
endif
if filereadable(expand("~/.vim/autoload/plug.vim"))
call plug#begin('~/.vim/plugged')
" The plugins are ordered by their names
" Helper:
" grep 'Plug ' ~/.vimrc | head -32 | sort -t '/' -k 2
" asyncrun.vim
" Usecase:
" Run a build command
" 1. Async in vim
" 2. Or in toggleterm
" 3. Or in tmux
Plug 'skywind3000/asyncrun.vim'
Plug 'chazy/cscope_maps'
" diffconflicts - easily address diffconfilicts in nvim :DiffConflicts
Plug 'whiteinge/diffconflicts'
Plug 'junegunn/fzf', { 'dir': '~/.fzf'}
Plug 'junegunn/fzf.vim'
" leap.nvim - mapped to s in 'normal' mode
" Usecase:
" Jump to a location in visible buffer area - use leap
" Jump to a location in any buffer area - use native vim search
Plug 'ggandor/leap.nvim'
Plug 'itchyny/lightline.vim'
Plug 'jose-elias-alvarez/null-ls.nvim'
Plug 'neovim/nvim-lspconfig'
" nvim-miniyank block paste fix for nvim
" Usecase:
" Fix for: Block paste not working when clipboard=unnamed
" https://github.com/neovim/neovim/issues/1822
Plug 'bfredl/nvim-miniyank'
Plug 'nvim-tree/nvim-tree.lua'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'nvim-tree/nvim-web-devicons'
Plug 'nvim-lua/plenary.nvim'
" tabular - Massively useful plugin for easily aligning text
Plug 'godlygeek/tabular'
" toggleterm.nvim (c-t, esc:c-j)
" Default Alternatives
" :sp term://zsh or
" :vs term://zsh
" ESC -> <c-\><c-n>
Plug 'akinsho/toggleterm.nvim'
"Plug 'wincent/vim-clipper'
" vim-commentary map: gcc
Plug 'tpope/vim-commentary'
Plug 'derekwyatt/vim-fswitch'
Plug 'tpope/vim-fugitive'
" vim-ledger
" Provides :LedgerAlign and :LedgerAlignBuffer
" Better aligned with Tabularize
" :Tabularize /=/l12c1r0
Plug 'ledger/vim-ledger'
" vim-plugin-viewdoc - For viewing help files
Plug 'powerman/vim-plugin-viewdoc'
" vim-surround see `:help surround`
" cs'" - change ' around text to "
" ysiW) - add ) around word
Plug 'tpope/vim-surround'
Plug 'christoomey/vim-tmux-navigator'
" vim-unimpaired: Awesome bracket maps
" [q ]q :cprevious :cnext
" [n ]n Go to git/hg confict marker
" yow - toggle wrap
Plug 'tpope/vim-unimpaired'
Plug 'preservim/vimux'
" -- Snippets
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'muralisc/snippets'
" -- Colorscheme Plugins
" Some colorscheme tested and conclusion
" solarized - Good
" gruvbox - Good
" apprentice - Good
" gotham - bad for diff highlight
" dracula - bad for types
" nord - bad for diff highlight
" onedark - GOOD
" base16-solarized-dark - GOOD
" jellybeans - bad for diff
" base16-summerfruit-dark - GOOD
" catppuccin - visual highlighting is not easily visible
Plug 'altercation/vim-colors-solarized'
set background=dark
" let g:solarized_termtrans=1
" let g:solarized_termcolors=256
Plug 'chriskempson/base16-vim'
Plug 'morhetz/gruvbox'
Plug 'romainl/Apprentice'
call plug#end()
endif
" }}}
"---------------------------------------------------------------------------
" GUI settings
"---------------------------------------------------------------------------
set guioptions-=m "remove menu bar
set guioptions-=T "remove toolbar
set guioptions-=r "remove right-hand scroll bar
set guioptions-=L
"---------------------------------------------------------------------------
" Basic Settings
"---------------------------------------------------------------------------
" {{{
"
" -- Uncategorised settings
"
" Enable filetype detection
filetype on
" Enable filetype-specific indenting
filetype indent on
" Enable filetype-specific plugins
filetype plugin on
" syntax highlight
syntax on
" prevent screen flasing on multiple esc
set vb t_vb=
" set 256 colors in vim
set t_Co=256
" A little bit more time for macros
set timeoutlen=1200
" Make Esc work faster
set ttimeoutlen=50
" don't wrap lines
set nowrap
" use multiple of shiftwidth when indenting with '<' and '>'
set shiftround
" read/write a .viminfo file, don't store more than 80 lines of registers
set viminfo='500,<80
set textwidth=80
set modeline
" always use a fast terminal
set ttyfast
set nospell spelllang=en_us
" Github limit
set colorcolumn=80,132
" default split method is to split in a verical split
set diffopt+=vertical
set dictionary=/usr/share/dict/cracklib-small
" seach for tags|my-tags and bubble up till home direcotry
set tags=tags;~,my-tags;~
" to make restore_view work well
set viewoptions-=options
" allow the cursor to go in to 'invalid' places
set virtualedit=block
" enable using the mouse if terminal emulator supports it (xterm does)
set mouse=a
" Settings for choosing an EOL setting for a file
set fileformats="unix,dos,mac"
" When wrapping paragraphs, don't end lines with 1-letter words (looks stupid)
set formatoptions+=1
" dont consided zero padded numbers as octal or hex (<C-a> and <C-x> works well !! )
set nrformats=
" hide buffers instead of closing them with unwritten changes
set hidden
" reveal already opened files instead of opening new buffers
set switchbuf=useopen
"
" --- Search settings
"
" {{{
" show search matches as you type
set incsearch
" search/replace 'globally' (on a line) by default
set gdefault
" ignore case when searching
set ignorecase
" ignore case if search pattern is all lowercase, case-sensitive otherwise
set smartcase
" highlight search terms
set hlsearch
" }}}
"
" --- Vim commands
"
" {{{
" tab completion for files/buffers in vim commands like bash
set wildmenu
" Complete till the longest match in command
set wildmode=longest,full
set wildignore=*.swp,*.bak,*.pyc,*.class
set wildignore+=*/node_modules/*
" ignore case while filename complete
set wildignorecase
" don't beep
set visualbell
" don't beep
set noerrorbells
" show (partial) command at right bottom; this also shows visual selection info
set showcmd
" remember more commands and search history
set history=1000
" }}}
"
" --- Editing - Basic Settings influencing edition behavior
"
" {{{
set nofixendofline
" show invisible charecters
set list
" If 'set list' is enabled, the invisible characters are show using listchars
set listchars=tab:▸\ ,trail:·,extends:#,nbsp:·
" a tab is four spaces
set tabstop=4
" when hitting <BS>, delete 4 spaces insted of 1
set softtabstop=4
" expand tabs by default (overloadable per file type later)
set expandtab
" insert tabs on the start of a line according to shiftwidth, not tabstop
set smarttab
" number of spaces to use for autoindenting
set shiftwidth=4
" always set autoindenting on
set autoindent
" copy the previous indentation on autoindenting
set copyindent
set clipboard=unnamedplus
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
if has("unix")
let s:uname = system("uname -s")
if s:uname == "Darwin\n"
set clipboard=unnamed
endif
endif
if has('mac')
set guifont=FreeMono:h16
endif
" While pasting, if pasting in insert mode using OS/tmux paste command
" The pasted data will be auto intended giving undesired outcome.
" Either use
" normal mode paste from "+y
" Or
" press <F2> to go to 'paste' mode
" set pastetoggle=<F2>
" }}}
"
" --- UI - Settings influencing UI behaviors
"
" {{{
" Read a changed file on disk
set autoread
" set show matching parenthesis
set showmatch
" always show line numbers
set number
" relative number, dissabling use search instead of relative number
" set rnu
" Switch between relative and non relative numbers when focus is changed
" au FocusLost * :set norelativenumber
" au FocusGained * :set relativenumber
set termencoding=utf-8
set encoding=utf-8
" underline the current line, for quick orientation
set cursorline
" have a vertical line marking the cursor column
set cursorcolumn
" keep 0 lines off the edges of the screen when scrolling
set scrolloff=0
" https://shapeshed.com/vim-netrw/
" Split Vertical
let g:netrw_preview = 1
let g:netrw_winsize = 15
" always show what mode we're currently editing in
set showmode
" }}}
"
" --- Undo/'Getting lost things' settings
"
" {{{
" use many muchos levels of undo
set undolevels=1000
" do not keep backup files, it's 70's style
set nobackup
" do not write annoying intermediate swap files,
set noswapfile
" keep an undo file (undo changes after closing)
set undofile
set undodir=~/.vim/vimundo
" store swap files in one of these directories (in case swapfile is ever turned on)
set directory=~/.vim/.tmp,/tmp
" }}}
"}}} Basic Settings
" Folding Rules {{{
" enable folding
set foldenable
set foldcolumn=0 " add a fold column
set foldmethod=marker " detect triple-{ style fold markers [marker indent]
set foldlevel=99 " 0-foldall 99-unfoldall
set foldopen=block,hor,insert,jump,mark,percent,quickfix,search,tag,undo " which commands trigger auto-unfold
" }}} Folding Rules
" Editor Layout {{{
set lazyredraw " don't update the display while executing macros
set laststatus=2 " always put a status line even if one window
set cmdheight=1 " use a status bar that is 2 rows high
" }}} Editor Layout
"---------------------------------------------------------------------------
" Shortcut Mappings
"---------------------------------------------------------------------------
" {{{
" Resize
nnoremap <Up> 5<c-w>+
nnoremap <Down> 5<c-w>-
nnoremap <Right> 5<c-w>>
nnoremap <Left> 5<c-w><
" Dont move your fingers from the home row OR use ctrl-[ instead `
inoremap jj <Esc>
" Thanks to Steve Losh for this liberating tip[perl/python compatible regex]
" See http://stevelosh.com/blog/2010/09/coming-home-to-vim
nnoremap / /\v
vnoremap / /\v
" never go into Ex mode
nnoremap Q <nop>
nnoremap Y y$
" instead of scorlling to middle .. scroll almost to top
nnoremap zz zt5<C-y>
" Leader mapings
" {{{
" Change the mapleader from \ to
let mapleader="\<Space>"
let maplocalleader="\<Space>"
" Clears the search register
nnoremap <leader>n :nohlsearch<CR>
" open another file in same dir as current file, Using keymaps from spacemacs
nnoremap <leader>ff :e %:h/<C-d>
" Quit Files with leader + bd
nnoremap <leader>bd :bp\|bd #<cr>
" Easy spliting
nnoremap <leader>s :sp<CR>
nnoremap <leader>v :vs<CR>
" Fast saving
nnoremap <leader>fs :w<cr>
" After yanking in visual mode move cursor to the end of the selection
vnoremap y ygv<Esc>
" }}}
" Clipboard madness {{{
map p <Plug>(miniyank-autoput)
map P <Plug>(miniyank-autoPut)
" replace currently selected text with default register without yanking it
vnoremap <leader>P "_dP
" }}}
" }}}
" Filetype Specific Settings {{{
augroup FTOptions
autocmd!
autocmd Filetype xml,xsd,html,javascript,yaml setlocal shiftwidth=2 softtabstop=2 tabstop=2 nostartofline
autocmd FileType xdefaults setlocal commentstring=!\ %s
autocmd Filetype c,cpp,java,go setlocal foldmethod=syntax foldlevel=99 complete-=k shiftwidth=2
autocmd FileType liquid,text,txt,tex setlocal complete+=k textwidth=80
autocmd Filetype vim setlocal foldmethod=marker keywordprg=:help shiftwidth=2
autocmd Filetype sh setlocal keywordprg=man shiftwidth=2
autocmd Filetype xml,sh,vim,tex,html,lua setlocal foldmethod=marker foldlevel=99
autocmd Filetype gitcommit setlocal spell textwidth=72
autocmd FileType git,gitcommit setlocal foldmethod=syntax tw=72 cc=+1 spell
autocmd Filetype markdown setlocal iskeyword+=# textwidth=80
augroup end
augroup gitsetup
autocmd!
" Only set these commands up for git commits
autocmd FileType gitcommit
\ autocmd CursorMoved,CursorMovedI *
\ let &l:textwidth = line('.') == 1 ? 50 : ( line('.') == 2 ? 1 : 72)
augroup end
"}}} Filetype Specific Settings
"---------------------------------------------------------------------------
" Plugin Specific Settings
"---------------------------------------------------------------------------
" {{{
" --- For derekwyatt/vim-fswitch
noremap <leader>a :FSHere<CR>
" --- For junegunn/fzf.vim
let g:fzf_preview_window = []
" command! -bang -nargs=* Rg
" \ call fzf#vim#grep(
" \ 'rg --sortr path --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
" \ <bang>0 ? fzf#vim#with_preview('up:60%')
" \ : fzf#vim#with_preview('right:50%:hidden', '?'),
" \ <bang>0)
" Find in files:
nnoremap <leader>/ :Rg!
" Find in files with word under cursor
nnoremap <leader>* :Rg!<C-R><C-W>
" FZF is faster than CtrlP for finding files in Directories (pf - after projectile find, using same as spacemacs)
nnoremap <leader>pf :FZF! +s --tac <CR>
" Quick open recent file
" Previousl => :CtrlPMRUFiles <CR>, Using keymaps from spacemacs
" See: https://develop.spacemacs.org/doc/DOCUMENTATION.html
nnoremap <leader>fr :History <CR>
" --- For itchyny/lightline.vim
let g:lightline = {
\ 'colorscheme': 'ayu_dark',
\ 'component_function': {
\ 'filename': 'LightLineFilename'
\ },
\ }
function! LightLineFilename()
" Get shrinked current working directory and filename
return substitute(getcwd(), '\(/.\)\([^/]*\)' , "\\1", "g") . ' | ' . expand('%')
endfunction
" --- For nvim-tree/nvim-tree.lua
" Using same mapping as spacemacs for opening treemacs
nnoremap <leader>fn :NvimTreeFindFile<cr>
" --- For akinsho/toggleterm.nvim
if has("nvim")
hi ActiveTerminal ctermbg=232 ctermfg=251
augroup WindowManagement
autocmd!
autocmd TermOpen * call Handle_Win_Enter()
augroup END
" Change highlight group of terminal window
function! Handle_Win_Enter()
setlocal winhighlight=Normal:ActiveTerminal
endfunction
end
" --- For SirVer/ultisnips
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsListSnippets="<c-tab>"
" --- For wincent/vim-clipper
let g:ClipperPort=5556
let g:fzf_preview_window = ['right:50%', 'ctrl-/']
" --- For powerman/vim-plugin-viewdoc
let g:ViewDoc_DEFAULT = 'ViewDoc_help'
if filereadable(glob("~/.vimrc.local"))
source ~/.vimrc.local
endif
" --- For christoomey/vim-tmux-navigator
" For compatability with tmux
" Using Meta-[hjkl] mappings in tmux to move panes
let g:tmux_navigator_no_mappings = 0
" }}}
"---------------------------------------------------------------------------
" Set Colorscheme
"---------------------------------------------------------------------------
silent! colorscheme gruvbox
if &diff
colorscheme gruvbox
endif
"---------------------------------------------------------------------------
" LUA settings
"---------------------------------------------------------------------------
if has("nvim")
lua <<EOF
local opts = { noremap=true, silent=true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
local on_attach = function(client, bufnr)
-- 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
local bufopts = { noremap=true, silent=true, buffer=bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, bufopts)
end
require'lspconfig'.clangd.setup{
cmd = { "clangd", "--background-index" }
}
require("lspconfig").lua_ls.setup({
settings = {
Lua = {
telemetry = { enable = false },
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
},
},
on_attach = on_attach,
})
require("nvim-tree").setup()
require'nvim-treesitter.configs'.setup {
ensure_installed = { "c", "cpp", "lua", "rust", "python" },
ignore_install = { "javascript", "verilog" },
highlight = {
enable = true,
disable = { "java", "verilog" },
},
}
require("toggleterm").setup{
size = function(term)
if term.direction == "horizontal" then
return 15
elseif term.direction == "vertical" then
return vim.o.columns * 0.5
end
end,
open_mapping = [[<c-t>]],
shade_terminals = true,
shading_factor = 9,
persist_size = true,
direction = 'vertical',
start_in_insert = false,
}
function _G.set_terminal_keymaps()
local opts = {noremap = true}
vim.api.nvim_buf_set_keymap(0, 't', '<C-j>', [[<C-\><C-n>]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<A-h>', [[<C-\><C-n><C-W>h]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<A-j>', [[<C-\><C-n><C-W>j]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<A-k>', [[<C-\><C-n><C-W>k]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<A-l>', [[<C-\><C-n><C-W>l]], opts)
end
-- if you only want these mappings for toggle term use term://*toggleterm#* instead
vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()')
require('leap').set_default_keymaps()
-- color help from : https://vim.fandom.com/wiki/Xterm256_color_names_for_console_Vim
vim.api.nvim_set_hl(0, 'LeapLabelPrimary', { ctermbg=111, ctermfg=016 , bold = true})
vim.api.nvim_set_hl(0, 'LeapLabelSecondary', { ctermbg=046, ctermfg=016})
EOF
endif