-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
233 lines (187 loc) · 6.9 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
set nocompatible " Vim, not Vi.
" Show 7 lines around the cursor when navigating
set so=7
" Powerline
"set guifont=PowerlineSymbols\ for\ Powerline
let g:Powerline_symbols = 'fancy'
set laststatus=2
" Disable arrow keys *shock* *horror*!
"inoremap <up> <nop>
"inoremap <down> <nop>
"inoremap <left> <nop>
"inoremap <right> <nop>
"noremap <up> <nop>
"noremap <down> <nop>
"noremap <left> <nop>
"noremap <right> <nop>
syntax on
set background=dark
"set background=light
"colorscheme solarized
colorscheme molokai
" Use pathogen to manage plugins
call pathogen#infect()
set ruler
set number
set relativenumber " Line numbers relative to your position
"set cursorline
set incsearch " Search for text as you enter it
" set tabstop=2
" set shiftwidth=2
set tabstop=4
set shiftwidth=4
set expandtab
set guifont="Source Code Pro":h14
set smartindent
set autoindent
set splitbelow " Split windows below current window
set hlsearch " Turn on search highlighting
" set nohls " Turn off search highlighting
" set winwidth=79
set foldenable
set ignorecase " Case insensitive
set smartcase " All lower case string = case-insenstive; any uppercase chars = case-senstive
:filetype plugin on " Required for snipMate
" Persistent undo, swap file directory and no backup files
set nobackup
set undofile
set undodir=~/.bin/dotfiles/vim/tmp/undo
set directory=~/.bin/dotfiles/vim/tmp/swap
" EnhancedCommentify script options
let g:EnhCommentifyRespectIndent = 'Yes'
let g:EnhCommentifyPretty = 'Yes'
let g:EnhCommentifyUseSyntax = 'Yes'
" Indent Guides options
let g:indent_guides_color_change_percent = 4 " default 10
let g:indent_guides_start_level = 2 " default 1
" Command auto-complete
set wildmenu
set wildmode=list:longest " File/dir autocomplete
" Code completion
"autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
"autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
"autocmd FileType css set omnifunc=csscomplete#CompleteCSS
"autocmd FileType php set omnifunc=phpcomplete#CompletePHP
" Set , as leader
let mapleader = ","
" Map spacebar to :
nmap <space> :
" Shortcut to htdocs folder with ,ht
nmap <leader>ht :cd /Applications/XAMPP/htdocs <CR>
" Shortcut to user dir with ,hm
nmap <leader>hm :cd ~/ <CR>
" Map ,nt and ,q to NERDTreeToggle
nmap <leader>nt :NERDTreeToggle <CR>
nmap <leader>q :NERDTreeToggle <CR>
" Show hidden files in NERDTree (except .DS_Store)
let NERDTreeShowHidden=1
let NERDTreeIgnore=['\.DS_Store$']
" Disable NERDTree showing on startup
" let NERDTreeHijackNetrw=0
" Auto change directory to that of file in the buffer
" Interferes with PeepOpen
"autocmd BufEnter * cd %:p:h
" Change splits easier with ,w
nmap <leader>w <C-W><C-W>
" Delete previous word with Ctrl+Backspace
imap <C-BS> <c-w>
" Run 'SortCSS' to alphabetise all properties
:command! SortCSS :g#\({\n\)\@<=#.,/}/sort
nnoremap <F2> :vimgrep // fuel/app/classes/**/*.php fuel/app/views/**/*.php<left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left><left>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" KEY MAPS (mostly from garybernhardt)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Make j and k work by screen line, not file line
nnoremap j gj
nnoremap k gk
" Open .vimrc file in vsp with ,ev
" nnoremap <leader>ev <C-w><C-v><C-l>:e $MYVIMRC<cr>
nnoremap <leader>ev :topleft 45 :split $MYVIMRC<cr>
" Clear search buffer on leader return
function! MapCR()
nnoremap <leader><cr> :nohlsearch<cr>
endfunction
call MapCR()
" Switch between to files
nnoremap <leader><leader> <c-^>
" Move around splits wither <c-hjkl>
nnoremap <c-h> <c-w>h
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-l> <c-w>l
" Map jj to Esc to exit out of Insert mode easier
"inoremap jj <ESC>
nmap <leader>bv :bel vsp
cmap bv bel vsp
" Save when losing focus
" au FocusLost * :wa
" Hide MacVim toolbar by default
set go-=T
" .less CSS styling
au BufNewFile,BufRead *.less set filetype=less
" Write with sudo
cmap w!! %!sudo tee > /dev/null %
" Change pwd to that of current file
cmap acd cd %:p:h
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MULTIPURPOSE TAB KEY
" Indent if we're at the beginning of a line. Else, do completion.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-n>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CUSTOM AUTOCMDS (mostly from garybernhardt)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup vimrcEx
" Clear all autocmds in the group
autocmd!
autocmd FileType text setlocal textwidth=78
" Jump to last cursor position unless it's invalid or in an event handler
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
"for ruby, autoindent with two spaces, always expand tabs
autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass,cucumber set ai sw=2 sts=2 et
autocmd FileType python set sw=4 sts=4 et
autocmd! BufRead,BufNewFile *.sass setfiletype sass
autocmd BufRead *.mkd set ai formatoptions=tcroqn2 comments=n:>
autocmd BufRead *.markdown set ai formatoptions=tcroqn2 comments=n:>
" Indent p tags
" autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif
" Don't syntax highlight markdown because it's often wrong
autocmd! FileType mkd setlocal syn=off
" Leave the return key alone when in command line windows, since it's used
" to run commands there.
autocmd! CmdwinEnter * :unmap <cr>
autocmd! CmdwinLeave * :call MapCR()
" Source .vimrc file after save
autocmd BufWritePost $MYVIMRC so $MYVIMRC
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" OPEN FILES IN DIRECTORY OF CURRENT FILE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>e :edit %%
map <leader>v :view %%
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RENAME CURRENT FILE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
map <leader>n :call RenameFile()<cr>