-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
397 lines (329 loc) · 10.7 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
" VIM Config - Kevin Muncie
" http://vimhelp.appspot.com/
" http://learnvimscriptthehardway.stevelosh.com/
" Use `za` to toggle code folding at cursor location
" vim-plug plugin manager https://github.com/junegunn/vim-plug ---- {{{
call plug#begin()
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'kyoz/purify', { 'rtp': 'vim' }
Plug 'vim-airline/vim-airline'
Plug 'edkolev/tmuxline.vim'
Plug 'sheerun/vim-polyglot'
Plug 'tpope/vim-fugitive'
Plug 'mileszs/ack.vim'
Plug 'tpope/vim-commentary'
Plug 'ap/vim-css-color',
Plug 'luochen1990/rainbow'
Plug 'nanotech/jellybeans.vim' " Theme
Plug 'pineapplegiant/spaceduck', { 'branch': 'dev' }
Plug 'junegunn/goyo.vim'
call plug#end()
let $FZF_DEFAULT_COMMAND = 'ag --hidden -g ""'
" fzf.vim - ctrl+p for find git tracked files
nnoremap <silent> <C-p> :GFiles<CR>
" fzf.vim - ctrl+P for find in all files
nnoremap <silent> <C-P> :Files<CR>
" Customize fzf colors to match your color scheme
" - fzf#wrap translates this to a set of `--color` options
let g:fzf_colors = {
\ 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
let g:rainbow_active = 0 "0 if you want to enable it later via :RainbowToggle
" Settings for vim-ctrlspace plugin
set nocompatible
set hidden
set encoding=utf-8
set showtabline=0
let g:airline#extensions#tabline#enabled = 1 " Enable the list of buffers
let g:airline_exclude_preview = 1
let g:airline#extensions#tmuxline#enabled = 0
" }}}
" Core Display Configuration ---------------------- {{{
set title
set number relativenumber
set ruler " Cursor position
set wrap " Wrap lines
set textwidth=90
set colorcolumn=+1
set wrapmargin=0
set backspace=indent,eol,start
set guioptions=T " Enable the toolbar
set showcmd
set ttimeoutlen=50
" -- Text editing preferences
set autoindent
" https://www.reddit.com/r/vim/wiki/tabstop
set tabstop=8
set softtabstop=3
set shiftwidth=3
set expandtab
set showmatch
set omnifunc=syntaxcomplete#Complete
" -- Search preferences
set incsearch
set hlsearch
" Mac Clipboard Support
set clipboard=unnamed
if executable('ag')
let g:ackprg = 'ag --vimgrep'
endif
" Highlight nonascii characters
" https://stackoverflow.com/questions/16987362/how-to-get-vim-to-highlight-non-asc
syntax match nonascii "[^\x00-\x7F]"
highlight nonascii guibg=Red ctermbg=2
" }}}
" Core Theming ---------------------------------- {{{
" use 256 colors in Console mode if we think the terminal supports it
if &term =~? 'mlterm\|xterm'
set background=dark
set t_Co=256
endif
" Copied in from spaceduck theme readme
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
colorscheme spaceduck
let g:airline_theme='spaceduck'
autocmd FileType gitcommit set textwidth=90
" Colour the 91st column so that we don’t type over our limit
autocmd FileType gitcommit set colorcolumn=+1
" In Git commit messages, also colour the 72nd column (for titles)
autocmd FileType gitcommit set colorcolumn+=73
" }}}
" Key Mappings ----------------------- {{{
" Latex snippets
nnoremap \scrip :-1read $HOME/.vim/scriptureCitation.tex<CR>2j$i
" Open vimrc in split for quick changes
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
" Hit <leader> (should be \) + s to reload config after saving
nnoremap <leader>sv :source ~/.vimrc<CR>
" Hit ii to exit insert mode
inoremap ii <Esc>
nnoremap ii <Esc>
" Hit Ctrl+c to exit insert mode
inoremap <C-c> <Esc>
" Line movements
nnoremap H ^
nnoremap L $
" Yank till the end of the line
nnoremap Y y$
" Keep cursor centered when going through search results
nnoremap n nzzzv
nnoremap N Nzzzv
" Keep cursor in place when joining lines
nnoremap J mzJ'z
" Undo break points
inoremap , ,<c-g>u
inoremap . .<c-g>u
inoremap ! !<c-g>u
inoremap ? ?<c-g>u
inoremap { {<c-g>u
inoremap ; ;<c-g>u
" Moving text
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
inoremap <C-j> <Esc>:m .+1<CR>==
inoremap <C-k> <Esc>:m .-2<CR>==
nnoremap <leader>k :m .-2<CR>==
nnoremap <leader>j :m .+1<CR>==
" Operator-pending mappings
" <operator> inside next/last <bracket-type>
onoremap in( :<c-u>normal! f(vi(<cr>
onoremap il( :<c-u>normal! F(vi(<cr>
onoremap in{ :<c-u>normal! f{vi{<cr>
onoremap il{ :<c-u>normal! F{vi{<cr>
onoremap in[ :<c-u>normal! f[vi[<cr>
onoremap il[ :<c-u>normal! F[vi[<cr>
" Paste Toggle
noremap <F2> :set invpaste paste?<CR>
set pastetoggle=<F2>
" Disable arrow keys in Normal, Visual, and Operator-pending modes
noremap <up> <nop>
noremap <down> <nop>
noremap <left> <nop>
noremap <right> <nop>
" Disable arrow keys in Insert mode
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
" }}}
" Functions (Line Numbering, Strip Whitespace) ----------------- {{{
" Toggle between absolute and relative line numbering
" Enables relative numbers.
function! EnableRelativeNumbers() abort
set number relativenumber
endfunction
" Disables relative numbers.
function! DisableRelativeNumbers() abort
set number norelativenumber
endfunction
" NumberToggle toggles between relative and absolute line numbers
function! NumberToggle() abort
if(&relativenumber == 1)
call DisableRelativeNumbers()
let g:relativemode = 0
else
call EnableRelativeNumbers()
let g:relativemode = 1
endif
endfunction
nnoremap <C-n> :call NumberToggle()<cr>
" Removes trailing spaces
function! StripTrailingWhitespace() abort
normal mZ
let l:chars = col("$")
%s/\s\+$//e
if (line("'Z") != line(".")) || (l:chars != col("$"))
echo "Trailing whitespace stripped\n"
endif
normal `Z
endfunction
" Transform words into Arabic Blog syntax
function! ArabicSplitBlog() abort
for lnum in range(a:lastline, a:firstline, -1)
let words = split(getline(lnum))
let words_transformed = map(copy(words), '"{{< word \"\" \"" . v:val . "\" \"\" >}}"')
execute lnum . "delete"
call append(lnum-1, words_transformed)
endfor
endfunction
" Insert wrapping paragraph for Arabic stacked text, move cursor inside
function! StackedStart() abort
let s:line=line(".")
let html = "<p class=\"stackedTextContainer\" dir=\"rtl\" lang=\"ar\" xml:lang=\"ar\">\n\n</p>"
let finalHtml = split(html, "\n")
call append(s:line, finalHtml)
normal! 2j
endfunction
" Thanks to Reddit u/duppy-ta for help with this
" https://www.reddit.com/r/vim/comments/bemdz2/custom_function_inserting_a_new_line_within_text/
function! ArabicSplitHTML() abort
for lnum in range(a:lastline, a:firstline, -1)
let words = split(getline(lnum))
let htmlOne = "<span class=\"stackedText\">\n<span class=\"translatedText\" dir=\"ltr\" lang=\"en\" xml:lang=\"en\"></span>\n<span class=\"vernacularText\">"
let htmlTwo = "</span>\n<span class=\"phoneticText\" dir=\"ltr\" lang=\"en\" xml:lang=\"en\"></span>\n</span>"
let words_transformed = map(copy(words), 'htmlOne . v:val . htmlTwo')
let all_lines = split(join(words_transformed, "\n"), "\n")
execute lnum . "delete"
call append(lnum-1, all_lines)
endfor
endfunction
function! EnglishSplitBlog() abort
for lnum in range(a:lastline, a:firstline, -1)
let words = split(getline(lnum))
let words_transformed = map(copy(words), '"{{< word \"" . v:val . "\" \"\" \"\" >}}"')
execute lnum . "delete"
call append(lnum-1, words_transformed)
endfor
endfunction
function! PhoSplitBlog() abort
for lnum in range(a:lastline, a:firstline, -1)
let words = split(getline(lnum))
let words_transformed = map(copy(words), '"{{< word \"\" \"\" \"" . v:val . "\" >}}"')
execute lnum . "delete"
call append(lnum-1, words_transformed)
endfor
endfunction
" Hit F5 to clear trailing whitespace at any time
nnoremap <silent> <F5> :let _s=@/ <Bar> call StripTrailingWhitespace() <Bar> :let @/=_s <Bar> :nohl <Bar> :unlet _s <CR>
def s:GitBlameLineFunc()
var popup_win = printf("git -C %s blame -s -L %s,%s -- %s | head -c 8", expand('%:h'), line('.'), line('.'), expand('%:p'))
->system()
->printf("git -C " .. expand('%:h') .. " log --stat -1 %s")
->system()
->split("\n")
->popup_atcursor({ "padding": [0, 1, 1, 1] })
call setbufvar(winbufnr(popup_win), '&filetype', 'git')
enddef
nnoremap <silent><leader>gb :call <SID>GitBlameLineFunc()<CR>
" quickfixopenall.vim
" Author:
" Tim Dahlin
"
" Description:
" Opens all the files in the quickfix list for editing.
"
" Usage:
" 1. Perform a vimgrep search
" :vimgrep /def/ *.rb
" 2. Issue QuickFixOpenAll command
" :QuickFixOpenAll
function! QuickFixOpenAll()
if empty(getqflist())
return
endif
let s:prev_val = ""
for d in getqflist()
let s:curr_val = bufname(d.bufnr)
if (s:curr_val != s:prev_val)
exec "edit " . s:curr_val
endif
let s:prev_val = s:curr_val
endfor
endfunction
command! QuickFixOpenAll call QuickFixOpenAll()
" }}}
" Autocommands ------------------ {{{
" vimrc code folding when three curly braces are on a line
augroup filetype_vim
autocmd!
autocmd FileType vim setlocal foldmethod=marker
augroup END
" Comment a line at any time
augroup comment_line
autocmd!
autocmd FileType scss,javascript nnoremap <buffer> <localleader>c I//<esc>
augroup END
" Remove trailing write space on save
augroup white_space
autocmd!
autocmd BufWritePre * call StripTrailingWhitespace()
augroup END
" Set .md files to have proper markdown syntax highlighting
augroup markdown
autocmd!
autocmd BufNewFile,BufFilePre,BufRead *.md set filetype=markdown
augroup END
" Set .ts files to have proper markdown syntax highlighting
augroup typescript
autocmd!
autocmd BufNewFile,BufFilePre,BufRead *.ts set filetype=javascript
augroup END
" Set Silverstripe template files (.ss) to use xhtml syntax highlighting
augroup silverstripe
autocmd!
autocmd BufNewFile,BufRead *.ss set filetype=xhtml
augroup END
" }}}
" Arabic/English Quick Switching ------------------- {{{
" Switch to English - mapping
nmap <Leader>e :<C-U>call EngType()<CR>
" Switch to Arabic - mapping
nmap <Leader>a :<C-U>call AraType()<CR>
" Switch to English - function
function! EngType()
" To switch back from Arabic
set keymap= " Restore default (US) keyboard layout
set norightleft
endfunction
" Switch to Arabic - function
function! AraType()
set keymap=arabic-pc "Modified keymap. File in ~/.vim/keymap/
set rightleft
endfunction
" }}}