forked from theniceboy/.vim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
363 lines (320 loc) · 8.57 KB
/
Copy pathvimrc
File metadata and controls
363 lines (320 loc) · 8.57 KB
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
" Forked from David Chen
" === Auto load for first time uses -> I don't install plugins here
" 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 --sync | source $MYVIMRC
" endif
" load /pack/*/opt packages at vim start
" see :help packages
" packadd! onedark.vim " it may has other prerequisites like atom color interpreter so forget it
" nvim for full configuration, vim for only plain
" === System
set nocompatible " fuk vi
filetype on " vim recognize file type
filetype indent on " indent for file type on
set indentexpr= " no indent here -> use spaces
filetype plugin on " plugin for file type on
filetype plugin indent on " indent in plugin for file type on
set mouse=a " use mouse
set clipboard=unnamed " use system clipboard
set encoding=utf-8 " use fixed encoding
colorscheme habamax " use vim color scheme
" Prevent incorrect background rendering
let &t_ut=''
" === Main code display
set number
" set relativenumber
set ruler
set cursorline
syntax enable
syntax on
" colorscheme onedark " use onedark scheme
highlight VerticalBar ctermfg=cyan
match VerticalBar /\v\|/
" fps display
function! FPS2display()
let line1 = getline(1)
let sects1 = split(line1, '||')
let sectn1 = len(sects1)
if sectn1 < 2
return
endif
let sect1 = sects1[0]
let parts1 = split(sect1, '|')
let partn1 = len(parts1)
if partn1 < 1
return
endif
let cursor0 = getpos('.')
if cursor0[1] == 1
echo
return
endif
let line0 = getline('.')
let parts0 = split(line0, '|')
let partn0 = len(parts0)
if partn0 != partn1
echo sects1[1] . " #" . (getpos('.')[1] - 1) . " | ignored"
return
endif
let cursor_sect = 0
for part0 in parts0
let cursor_sect += 1
if cursor0[2] < strlen(part0) + 2
echo sects1[1] . " #" . (cursor0[1] - 1) . " " . parts1[cursor_sect - 1]
return
endif
let cursor0[2] -= strlen(part0) + 1
endfor
echo sects1[1] . " not found"
endfunction
nnoremap cc I#<Esc> " Normal mode: Inserts # at the beginning of the current line
vnoremap cc :s/^/#/<CR>:nohlsearch<CR> " Visual mode: Inserts # to selected lines
" fps display at cursor move
augroup FPS2display0
autocmd CursorMoved * call FPS2display()
autocmd BufNewFile,BufRead *.fps set filetype=sh
augroup END
" custom
augroup MQL5
autocmd!
autocmd BufNewFile,BufRead *.mqh set filetype=cpp
autocmd BufNewFile,BufRead *.mq4 set filetype=cpp
autocmd BufNewFile,BufRead *.mq5 set filetype=cpp
augroup END
" highlights
highlight Quest ctermfg=yellow
call matchadd("Quest", "?")
highlight Excla ctermfg=red
call matchadd("Excla", "!")
" === Editor behavior
" Better tab
set expandtab
set tabstop=2
set shiftwidth=2
set softtabstop=2
set list
set listchars=tab:▸\ ,trail:▫
set scrolloff=5
" Prevent auto line split
set wrap
set tw=0
" Better backspace
set backspace=indent,eol,start
set foldmethod=indent
set foldlevel=99
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
" === Window behaviors
set splitright
set splitbelow
" === Status/command bar
set laststatus=2
set autochdir
set showcmd
set formatoptions-=tc
" Set tab autocomplete style
set wildignore=log/**,node_modules/**,target/**,tmp/**,*.rbc
set wildmenu
set wildmode=longest,list,full
" Searching options
set hlsearch
exec "nohlsearch"
set incsearch
set ignorecase
set smartcase
" === Restore Cursor Position
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" === Basic Mappings
" VITAL <LEADER> Leader key: Set <LEADER> as <SPACE>
let mapleader=" "
" Column (:) mods
map ; :
map q; q:
map <LEADER>/ :!
map <LEADER>r :r !
map <LEADER>sr :%s/
" VITAL <CR> = Ctrl+M = <Return> = <Enter> Change line key
" Save & quit
map Q :q<CR>
map W :w<CR>
" Open the vimrc file anytime
" map <LEADER>rc :e ~/.vim/vimrc<CR>
" Redo operations
noremap y <C-r>
" Undo in Insert mode
" inoremap <C-l> <C-u>
" VITAL a = add; s = insert;
noremap s i
noremap S I
" VITAL press f to copy and press h to paste
noremap f y
noremap h p
" VITAL vim script func: copy and paste with the system clipboard
func! CopyCurrentLine()
call system('echo -n ' . shellescape(getline('.')) . ' | xclip -selection clipboard')
endfunc
nnoremap <C-c> :call CopyCurrentLine()<CR>
function! CopyVisualSelection()
try
" Save the current content of register a
let a_save = @a
" Select the visual region and copy it to register a
normal! gv"ay
" Get the content of register a
let selection = @a
" Copy the content to the system clipboard using xclip
call system('echo -n ' . shellescape(selection) . ' | xclip -selection clipboard')
finally
" Restore the previous content of register a
let @a = a_save
endtry
endfunction
vnoremap <C-c> :<C-u>call CopyVisualSelection()<CR>
func! PasteFromXclip()
let lin = line(".")
exec lin . "r !xclip -o -sel clip"
endfunc
noremap <C-v> :call PasteFromXclip()<CR>
nnoremap <C-a> ggVG
nnoremap <C-s> :w<CR>
" Visual Block
nnoremap vb <C-v>
function! Forward2Spaces()
execute "'<,'>normal! I "
" Reselect the visual block
normal! gv
endfunction
xnoremap <Space> :<C-u>call Forward2Spaces()<CR>
" Search
map <LEADER><CR> :nohlsearch<CR>
noremap = nzz
noremap - Nzz
" Duplicate words
map <LEADER>fd /\(\<\w\+\>\)\_s*\1
" === Cursor Movement
" ^
" i
" < j k l >
" v
noremap i k
noremap j h
noremap k j
" I/K keys for multitimes i/k (faster navigation)
noremap I 5k
noremap J 5h
noremap K 5j
noremap L 5l
" D key: go to the start of the line
noremap D 0
" F key: go to the end of the line
noremap F $
" Faster in-line navigation by words
noremap p w
noremap o b
noremap P 5w
noremap O 5b
" Ctrl + i or k will move up/down the view port without moving the cursor
noremap <C-i> 5<C-y>
noremap <C-k> 5<C-e>
inoremap <C-i> <Esc>5<C-y>a
inoremap <C-k> <Esc>5<C-e>a
" === Window management
" Use <space> + new arrow keys for moving the cursor around windows
map <LEADER>n <C-w>w
map <LEADER>i <C-w>k
map <LEADER>k <C-w>j
map <LEADER>j <C-w>h
map <LEADER>l <C-w>l
"map <LEADER>r <C-w>r
" split the screens to up (horizontal), down (horizontal), left (vertical), right (vertical)
map gi :set nosplitbelow<CR>:split<CR>:set splitbelow<CR>
map gk :set splitbelow<CR>:split<CR>
map gj :set nosplitright<CR>:vsplit<CR>:set splitright<CR>
map gl :set splitright<CR>:vsplit<CR>
" Place the two screens up and down
noremap gu <C-w>t<C-w>K
" Place the two screens side by side
noremap gh <C-w>t<C-w>H
" Rotate screens
noremap gfu <C-w>b<C-w>K
noremap gfh <C-w>b<C-w>H
" Resize splits with arrow keys
" map <up> :res +5<CR>
" map <down> :res -5<CR>
" map <left> :vertical resize-5<CR>
" map <right> :vertical resize+5<CR>
" === Tabe management
" Create a new tabe
map tn :tabe<CR>
" Move around tabes with tj and tl
map tj :-tabnext<CR>
map tl :+tabnext<CR>
" Move the tabes with tk and ti
map tk :-tabmove<CR>
map ti :+tabmove<CR>
" === Other useful stuff
" Press space twice to jump to the next '<++>' and edit it
" map <LEADER><LEADER> <Esc>/<++><CR>:nohlsearch<CR>c4i
" Spelling Check with <space>sc
map <LEADER>sc :set spell!<CR>
noremap <C-x> ea<C-x>s
inoremap <C-x> <Esc>ea<C-x>s
" Press ` to change case (instead of ~)
map ` ~
" n key: go to the prev for /
noremap n N
" m key: go to the next for /
noremap m n
" Auto change directory to current dir
autocmd BufEnter * silent! lcd %:p:h
" Call figlet
map tx :r !figlet
" Compile function
map rn :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'cc'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'java'
exec "!javac %"
exec "!time java %<"
elseif &filetype == 'sh'
:!time bash %
elseif &filetype == 'python'
silent! exec "!clear"
exec "!time python3 %"
elseif &filetype == 'html'
exec "!firefox % &"
elseif &filetype == 'markdown'
exec "MarkdownPreview"
elseif &filetype == 'vimwiki'
exec "MarkdownPreview"
endif
endfunc
map bd :call CompileBuildrrr()<CR>
func! CompileBuildrrr()
exec "w"
if &filetype == 'vim'
exec "source $MYVIMRC"
elseif &filetype == 'markdown'
exec "echo"
endif
endfunc
" === Install Plugins with Vim-Plug -> I don't install plugin here
" call plug#begin('~/.vim/plugged')
" === This one has been switched to Vin 8 Pack installation
" Plug 'joshdick/onedark.vim'
" call plug#end()
nnoremap jf :bprev<CR>
nnoremap lf :bnext<CR>
nnoremap kf :bd<CR>