-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
211 lines (168 loc) · 6.04 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
" -----------------------------------PLUGINS------------------------------------
call plug#begin()
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
Plug 'kien/ctrlp.vim'
Plug 'inkarkat/argtextobj.vim'
Plug 'puremourning/vimspector'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'morhetz/gruvbox'
Plug 'mg979/vim-visual-multi'
call plug#end()
" ----------------------------------FUNCTIONS-----------------------------------
function AddSemicolon()
execute "normal! mqA;\<esc>`q"
endfunction
function! MakeHeader(str, length)
let remaining = a:length - len(a:str)
let leftchars = remaining / 2
let rightchars = remaining - leftchars
" echom "normal! dd" . leftchars . "i-\<esc>a" . a:str . "\<esc>" . rightchars . "a\<esc>"
execute "normal! cc\<esc>" . leftchars . "i-\<esc>a" . a:str . "\<esc>" . rightchars . "a-\<esc>"
endfunction
function! Headerify()
execute "normal! cc"
let str = @"
let str = str[:-2]
call MakeHeader(str, 78)
endfunction
function ExpandForCpp()
execute "normal! cc\<esc>"
let str = @"
let str = str[:-2]
let parts = split(str)
if len(parts) ==# 2
let varname = parts[0]
let itername = parts[1]
execute "normal afor(auto " . varname . " : " . itername . " ){\<cr>"
else
let varname = parts[0]
let begin = parts[1]
let end = parts[2]
execute "normal afor(auto " . varname . "=" . begin . "; " . varname . " < " . end . "; " . varname . "++){\<cr>"
endif
endfunction
" -----------------------------------SETTINGS-----------------------------------
"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
"If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support
"(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.)
if (empty($TMUX))
if (has("nvim"))
"For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
"For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
"Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
" < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
if (has("termguicolors"))
set termguicolors
endif
endif
" configure line number
set number
set relativenumber
" tab settings
set tabstop=4
set shiftwidth=4
set expandtab
set smarttab
" leader settings
let mapleader = " "
let maplocalleader = "\\"
" statusline
set statusline=%f " Path to the file
set statusline+=%= " Switch to the right side
set statusline+=%p%{'%'} " Percent in file
set statusline+=/ " Separator
set statusline+=%L " Total lines
set statusline+=%y " Filetype of the file
" restore last position in file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" -------------------------------------KEYS-------------------------------------
" reload config
nnoremap <leader><f5> :source $MYVIMRC<cr>
"autocomplete
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
inoremap <silent><expr> <c-space> coc#refresh()
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gD :call CocAction('jumpDefinition')<CR>:vs<cr><c-o>
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
nnoremap <silent> K :call <SID>show_documentation()<CR>
"debugger
nnoremap <f5> :call vimspector#Launch()<cr>
nnoremap <f9> :call vimspector#ToggleBreakpoint()<cr>
" can't use f11 because it is used by the window manager
nnoremap <leader>dd :call vimspector#StepOver()<cr>
nnoremap <f10> :call vimspector#StepOver()<cr>
nnoremap <leader>do :call vimspector#StepOver()<cr>
nnoremap <leader>di :call vimspector#StepInto()<cr>
nnoremap <leader>ds :call vimspector#Reset()<cr>
nnoremap <leader>dc :call vimspector#Continue()<cr>
nnoremap <leader>dw :call vimspector#AddWatch()<cr>
nnoremap <leader>dW :call vimspector#DeleteWatch()<cr>
" save using ctrl+s
nnoremap <c-s> :w<cr>
" add semicolon to the end of the line
nnoremap <leader>; :call AddSemicolon()<cr>
" autoclose parens
inoremap (; ()<C-c>ha
inoremap {; {}<C-c>ha
inoremap [; []<C-c>ha
inoremap (<space> ()<C-c>ha
inoremap {<space> {}<C-c>ha
inoremap [<space> []<C-c>ha
inoremap (<cr> (<cr>)<C-c>k$o
inoremap {<cr> {<cr>}<C-c>k$o
inoremap [<cr> [<cr>]<C-c>k$o
inoremap "" ""<C-c>ha
inoremap '' ''<C-c>ha
" ctrl + backspace in insert mode
noremap! <C-BS> <C-w>
noremap! <C-h> <C-w>
" commenting
vnoremap <c-_> :Commentary<cr>
nnoremap <c-_> :Commentary<cr>
" remap arrow keys to move between splits
nnoremap <left> <c-w><left>
nnoremap <right> <c-w><right>
nnoremap <up> <c-w><up>
nnoremap <down> <c-w><down>
"use tab to switch splits
nnoremap <tab> <c-w><c-w>
" close other windows by double tapping escape
nnoremap <esc><esc> :only<cr>
" use ctrl + arrows to resize splits
nnoremap <c-up> :resize +3<cr>
nnoremap <c-down> :resize -3<cr>
nnoremap <c-left> :vertical resize -3<cr>
nnoremap <c-right> :vertical resize +3<cr>
" use ctrl + J|K to move lines
nnoremap <c-J> ddp
nnoremap <c-K> ddkP
" swtich header and source files
nnoremap <leader>ko :execute 'edit' CocRequest('clangd', 'textDocument/switchSourceHeader', {'uri': 'file://'.expand("%:p")})<cr>
" colorscheme
autocmd vimenter * ++nested colorscheme gruvbox
" visual multi keyindings
let g:VM_maps = {}
let g:VM_maps['Find Under'] = '<C-d>' " replace C-n
let g:VM_maps['Find Subword Under'] = '<C-d>' " replace visual C-n
let g:VM_maps["Toggle Mappings"] = '<CR>' " toggle VM buffer mappings
" make Y copy to the end of the line
nnoremap Y y$
" misc
nnoremap <leader>H :call Headerify()<cr>
nnoremap <leader>for :call ExpandForCpp()<cr>cc