/
.vimrc
253 lines (197 loc) · 6.75 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
source $VIMRUNTIME/defaults.vim
""" Basic Stuff
set nocompatible "Not entirely sure what this does, but seen it about in other examples
colorscheme slate
"Turn on syntax highlighting and smart-indent
syntax on
set number
set autoindent
set smartindent
set backspace=indent,eol,start " more powerful backspacing
"Show the status line and suler
set statusline=[%02n]\ %f\ %(\[%M%R%H]%)%=\ %4l,%02c%2V\ %P%*
set laststatus=2
set ruler
"Get rid of tabs, they're the devils work
set expandtab
set smarttab
set tabstop=4
set shiftwidth=4
"set title to show in console title bar
set title
"Do not keep a backup file!
set nobackup
""" Misc
"Auto change the directory to the current file location
" autocmd BufEnter * lcd %:p:h
" Suffixes that get lower priority when doing tab completion for filenames.
" These are files we are not likely to want to edit or read.
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc,.png,.jpg
"Set my cusom shortcut key
let mapleader=","
"Use ,s to start a spell check, hit it again to stop
set spellfile=~/.vim/dict.add
" setp pastetoggle=<F2>
"Set up window/splits key mapping for ease of use
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h
"set up search
set hlsearch
set incsearch
set ignorecase
set smartcase
let g:airline_powerline_fonts = 1
" Add optional packages.
" The matchit plugin makes the % command work better, but it is not backwards
" compatible.
if has('syntax') && has('eval')
packadd matchit
endif
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
call plug#begin('~/.vim/plugged')
" Make sure you use single quotes
" NERD tree will be loaded on the first invocation of NERDTreeToggle command
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'tomtom/tcomment_vim'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'itchyny/lightline.vim'
Plug 'sheerun/vim-polyglot'
Plug 'airblade/vim-gitgutter'
Plug 'mattn/emmet-vim'
Plug 'tomasr/molokai'
Plug 'mileszs/ack.vim'
Plug '~/code/wp-db-switch.vim'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'lifepillar/vim-solarized8'
" Plug 'w0rp/ale'
" Add plugins to &runtimepath
call plug#end()
" set background=dark
colorscheme molokai
let g:molokai_original = 1
" let g:rehash256 = 1
" set background=light
" colorscheme solarized8
"TComment config - ,cc to toggle
noremap <silent> <Leader>cc :TComment<CR>
"CTRP config
nnoremap <silent> <Leader>f :CtrlP<CR>
let g:ctrlp_extensions = ['wpdbswitch']
"turn off search highlighting with ,.
nmap <silent> <Leader>. :silent noh<CR>
" toggle spell check
nmap <Leader>s :setlocal spell! spelllang=en_gb<CR>
" attempt to figure out which media query we're in
nmap <Leader>q :call ReportMediaQuery()<CR>
" toggle paste mode
nmap <Leader>p :setlocal paste!<CR>
"let g:lightline = { 'colorscheme': 'solarized', } "vim-lightline
set laststatus=2 "vim-lightline
set noshowmode "vim-lightline
" st filetype to html for indent, set syntax back to php
function! ConfigPHPFT()
set ft=html
set syntax=php
endfunction
autocmd FileType php call ConfigPHPFT()
"fn to minify js or css - uses cleancss and uglify binaries (systemwide node
" modules on my system)
function Js_compress ()
let cwd = expand('<afile>:p:h')
let nam = expand('<afile>:t:r')
let ext = expand('<afile>:e')
if -1 == match(nam, "[\._]src$")
let minfname = nam.".min.".ext
else
let minfname = substitute(nam, "[\._]src$", "", "g").".".ext
endif
if ext == 'js' && executable('uglifyjs')
" cmd: uglifyjs nonmin.js -o newfile.min.js -m -c
let jscmd = 'uglifyjs '.cwd.'/'.nam.'.'.ext.' -o '.cwd.'/'.minfname.' -m -c '
cal system(jscmd)
" echo '> JS minified'
endif
endfunction
function Css_compress ()
let cwd = expand('<afile>:p:h')
let nam = expand('<afile>:t:r')
let ext = expand('<afile>:e')
if -1 == match(nam, "[\._]src$")
let minfname = nam.".min.".ext
else
let minfname = substitute(nam, "[\._]src$", "", "g").".".ext
endif
if ext == 'css' && executable('cleancss')
" cmd: cleancss --s1 -s --skip-rebase nonmin.css > newfile.min.css
let csscmd = 'cleancss --s1 -s --skip-rebase '.cwd.'/'.nam.'.'.ext.' > '.cwd.'/'.minfname.' '
cal system(csscmd)
" echo '> CSS minified'
endif
endfunction
function Sass_compile ()
let cwd = expand('<afile>:p:h')
let nam = expand('<afile>:t:r')
let ext = expand('<afile>:e')
if -1 == match(nam, "[\._]src$")
let cssname = nam.".css"
else
let cssname = substitute(nam, "[\._]src$", "", "g").".css"
endif
if -1 == match(nam, "[\._]src$")
let minfname = nam.".min.css"
else
let minfname = substitute(nam, "[\._]src$", "", "g").".css"
endif
if ext == 'scss' && executable('node-sass')
" cmd: node-sass input/file.scss output/file.css
let sasscmd = 'node-sass '.cwd.'/'.nam.'.'.ext.' > '.cwd.'/'.cssname.' '
cal system(sasscmd)
" echo '> SASS compiled'
if executable('cleancss')
let csscmd = 'cleancss --s1 -s --skip-rebase '.cwd.'/'.cssname.' > '.cwd.'/'.minfname.' '
cal system(csscmd)
" echo '> SASS output minified'
endif
endif
endfunction
"
" call our minification on save
" autocmd FileWritePost,BufWritePost *.js :call Js_compress()
" autocmd FileWritePost,BufWritePost *.css :call Css_compress()
" autocmd FileWritePost,BufWritePost *.scss :call Sass_compile()
" get rid of all trailing whitespace before end of buffer on before buffer
" save
function! TrimWhiteSpace()
%s/\s\+$//e
endfunction
autocmd BufWritePre *.html,*.php,*.css,*.js,*.svg :call TrimWhiteSpace()
function! ReportMediaQuery()
execute "normal! mq?@media\<CR>"
let l:lineContent = getline('.')
execute "normal! `q"
echohl WarningMsg
echo l:lineContent
echohl None
endfunction
"Highlights trailing spaces
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
" emmet config
let g:user_emmet_install_global = 0
autocmd FileType php,html,eco,css,scss EmmetInstall
" set expand key map to ',,'
let g:user_emmet_leader_key=','
"autocmd FileType $type :iabbrev <buffer> $match $replace [$additional_commands]
"type <? to get <?php [cursor]; ?>
autocmd FileType php :iabbrev <buffer> <? <?php; ?><left><left><left><left>