-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
296 lines (273 loc) · 8.79 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
" Make Vim more useful
set nocompatible
" Don’t add empty newlines at the end of files
set binary
set noeol
" Centralize backups, swapfiles
set backupdir=~/.vim/tmp
set directory=~/.vim/tmp
" Change leader to a comma
let g:mapleader = ","
" Change the terminal's title
set title
" Always show statusline
set laststatus=2
" Set utf-8 encoding on write
set encoding=UTF-8
set backspace=indent,eol,start
" Indentation
set tabstop=2
set shiftwidth=2
set softtabstop=2
" Indents <Tab> as spaces
set expandtab
set autoindent
set number
set ai
set si
" Highlight current line
set cursorline
" Enable word wrap
set wrap
" Case insensitive search
set ignorecase
" Smart case search if there is uppercase
set smartcase
set showcmd
" Disable beep and flashing
set vb t_vb=
" Enable listchars
set list
" Show some whitespace chars
set listchars=tab:▸·,trail:·,extends:❯,precedes:❮,nbsp:×
" Highlight matching bracket
set showmatch
" Auto read when a file is changed from the outside
set autoread
" Turn on syntax highlighting
syntax on
" Blazing fast vim
set ttimeoutlen=0
" Highlight searches
set hlsearch
" Highlight dynamically as pattern is typed
set incsearch
" Optimize for fast terminal connections
set ttyfast
" Mouse clicks
set mouse=i
"type R, then type what you're looking for, move right, and type what to replace it with
nmap R :%s///g<LEFT><LEFT><LEFT>
" ft to remove tabs
nnoremap ft :silent %s/\t/ /g
" S for saving
noremap S :update<CR>
" Q for leaving
noremap Q :q<CR>
" Make exiting to normal mode a bit easier
imap <leader><leader> <Esc>
" reload vimrc
nmap <leader>r :source ~/.vimrc<CR>
" omnifunc
filetype plugin on
set omnifunc=syntaxcomplete#Complete
set completeopt=longest,menuone
" redo
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" highlight long lines
match ErrorMsg '\%>120v.\+'
" highlight trailing whitespace
match ErrorMsg '\s\+$'
" open new files right and below
set splitbelow
set splitright
" tabs
nnoremap <C-l> :tabnew<Space>
" control + d + arrows to move from tab to tab horizontally
map <C-d><left> :tabp<cr>
map <C-d><right> :tabn<cr>
" control + e + arrows to re-arrange tab hotizontally
map <C-e><left> :tabm -1<cr>
map <C-e><right> :tabm +1<cr>
" space + s => search
noremap <space>s /
" copy selected text to clipboard
vmap <space>c :w !pbcopy<cr><cr>
" duplicate line
noremap <space>d yyp
" find word
noremap <space>f *N
" noh
noremap <space>m :noh<cr>
" replace current word
noremap <space>r :%s/\<<C-r><C-w>\>//g<left><left>
" delete word
imap <SPACE><BS> <C-W>
" disable swap file
set noswapfile
" Buffer jumps
" previous
nmap ss<left> :bp<CR>
" next
nmap ss<right> :bp<CR>
" open new tab with buffer
" :tabnew | buffer
" C-P | buffer
" open current buffer in tab
nmap ss<Space> :tab sball<CR>
" move lines
" down
nmap fj :m +1<CR>
" up
nmap fk :m -2<CR>
" join lines
" Number of lines + shift + j
" scroll cursor
" z<CR> puts current line to top of screen
" z. puts current line to center of screen
" z- puts current line to bottom of screen
" move split to tab
" <c-w>T
" prepare things for git log (space is there on purpose)
map <leader>l :! git log -p
" clear current line without removing it and swith to insert mode
" cc
" open some other buffer in vertical split
" :vert sb N
" open some other buffer in horizontal split
" :sb N
" Plugins
call plug#begin('~/.vim/bundle')
Plug 'zivyangll/git-blame.vim'
" <leader>b shows commit message in status line (you can grab commit hash and see full commit with <leader>l + paste commit hash
nnoremap <Leader>b :<C-u>call gitblame#echo()<CR>
Plug 'itchyny/lightline.vim'
" lightline
set laststatus=2
" By the way, -- INSERT -- is unnecessary anymore because the mode information is displayed in the statusline.
set noshowmode
let g:lightline = {
\ 'colorscheme': 'nord',
\ 'active': {
\ 'left': [ ['mode'], ['filename'] ],
\ 'right': [ ['percent', 'lineinfo'] ]
\ },
\ }
Plug 'scrooloose/nerdtree'
" nerdtree
" Start NERDTree when Vim is started without file arguments.
" autocmd StdinReadPre * let s:std_in=1
" autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif
" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" control o to toggle nerd tree
map <C-o> :NERDTreeToggle<CR>
" Focus on NERDTree with the currently opened file with M
noremap <silent> M :NERDTreeFind<CR>
" hides 'Press ? for help'
let NERDTreeMinimalUI=1
" shows invisibles
let g:NERDTreeShowHidden=1
" hide these files
let NERDTreeIgnore = ['\.DS_Store$']
" https://www.reddit.com/r/vim/comments/a4yzyt/g_characters_prefixing_directory_and_file_names/
let g:NERDTreeNodeDelimiter = "\u00a0"
" show on the right
let g:NERDTreeWinPos = "right"
" Shows Git status flags for files and folders in NERDTree.
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'ctrlpvim/ctrlp.vim'
" invoke with control p
let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
Plug 'scrooloose/nerdcommenter'
let g:NERDSpaceDelims = 1
" mappings
" https://github.com/scrooloose/nerdcommenter#default-mappings
Plug 'prettier/vim-prettier'
" print semicolons
let g:prettier#config#semi = 'false'
" print spaces between brackets
let g:prettier#config#bracket_spacing = 'true'
" none|es5|all
let g:prettier#config#trailing_comma = 'all'
" put > on the last line instead of new line
let g:prettier#config#jsx_bracket_same_line = 'false'
" format and save
nmap <leader>m :Prettier<CR> :update<CR>
Plug 'airblade/vim-gitgutter'
" navigate between hunks
nmap zk <Plug>(GitGutterNextHunk)
nmap zj <Plug>(GitGutterPrevHunk)
Plug 'junegunn/fzf'
"To use fzf in Vim, add the following line to your .vimrc:
set rtp+=/opt/homebrew/opt/fzf
Plug 'ervandew/supertab'
Plug 'gabrielelana/vim-markdown'
Plug 'inside/vim-search-pulse'
Plug 'arcticicestudio/nord-vim'
Plug 'leafgarland/typescript-vim'
Plug 'dense-analysis/ale'
Plug 'pechorin/any-jump.vim'
Plug 'mhinz/vim-startify'
Plug 'wsdjeg/FlyGrep.vim'
Plug 'khzaw/vim-conceal'
Plug 'frazrepo/vim-rainbow'
let g:rainbow_active = 2
Plug 'psf/black', { 'branch': 'stable' }
augroup black_on_save
autocmd!
autocmd BufWritePre *.py Black
augroup end
nnoremap <space>bb :Black<CR>
"let g:black_virtual_env = substitute(system('pipenv --venv'), '\n\+$', '', '')
let g:black_virtual_env = system('pipenv --venv')
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
" Run the following to install completion plugins
" :CocInstall coc-pyright
" :CocInstall coc-tsserver coc-json coc-html coc-css
" :CocInstall coc-go
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
" https://github.com/fatih/vim-go
" Compile your package with :GoBuild, install it with :GoInstall or test it with :GoTest. Run a single test with :GoTestFunc).
" Quickly execute your current file(s) with :GoRun.
" Improved syntax highlighting and folding.
" Debug programs with integrated delve support with :GoDebugStart.
" Completion and many other features support via gopls.
" formatting on save keeps the cursor position and undo history.
" Go to symbol/declaration with :GoDef.
" Look up documentation with :GoDoc or :GoDocBrowser.
" Easily import packages via :GoImport, remove them via :GoDrop.
" Precise type-safe renaming of identifiers with :GoRename.
" See which code is covered by tests with :GoCoverage.
" Add or remove tags on struct fields with :GoAddTags and :GoRemoveTags.
" Lint your code with :GoLint or :GoMetaLinter, run your code through :GoVet to catch static errors, or make sure errors are checked with :GoErrCheck.
" Advanced source analysis utilizing gopls, such as :GoImplements, :GoCallees, and :GoReferrers.
" ... and many more! Please see doc/vim-go.txt for more information.
" Integration with gopls.
" The gopls instance can be shared with other Vim plugins.
" Vim-go's use of gopls can be disabled and alternative tools can be used when desired.
" Integration with Tagbar via gotags.
" Integration with Ultisnips and other snippet engines.
" local
let $LOCALFILE=expand("~/.vimrc.local")
if filereadable($LOCALFILE)
source $LOCALFILE
endif
call plug#end()
colorscheme nord
" comments
" http://guns.github.io/xterm-color-table.vim/images/xterm-color-table.png
hi Comment ctermfg=147
hi NonText ctermfg=147
" https://www.reddit.com/r/vim/comments/3duumy/changing_markdown_syntax_colors/
" Drop these in your vimrc and you can do :call GetSyntax() when your cursor is over some text to see what highlight settings it belongs to.
function! GetSyntaxID()
return synID(line('.'), col('.'), 1)
endfunction
function! GetSyntaxParentID()
return synIDtrans(GetSyntaxID())
endfunction
function! GetSyntax()
echo synIDattr(GetSyntaxID(), 'name')
exec "hi ".synIDattr(GetSyntaxParentID(), 'name')
endfunction