-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
207 lines (174 loc) · 6.3 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
" configuration file for vim
execute pathogen#infect()
" some plugins are easier to install via vim-plug
call plug#begin()
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'airblade/vim-rooter'
call plug#end()
" colors & colorscheme for lightline
syntax on
set background=dark
let g:lightline = {
\ 'colorscheme': 'PaperColor',
\ }
" enable file type detection
filetype plugin indent on
" delete all trailing whitespace
nnoremap <silent> <F3> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>
" some defaults for the editor
set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%)
set autoindent " Always set autoindenting on
set autowrite " Automatically save before commands like :next and :make
set backspace=indent,eol,start " More powerful backspacing
set history=200 " Command line history
set ignorecase " Do case insensitive matching
set incsearch " Incremental search
set modeline " Apply modelines from files
set backup " Keep a backup file
set backupdir=~/.tmp " ..and keep it out of the way
set dir=~/.tmp"
set nocompatible " Use Vim defaults instead of 100% vi compatibility
set noerrorbells " Evil
set noshowmode " Hide insert status (provided by lightline)
set ruler " Show the cursor position all the time
set scrolloff=2 " 2 lines of context at all times
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
set smartcase " Do case sensitive matching if necessary
set textwidth=0 " Don't wrap words by default
set notitle " no title in terminal
set ttyfast
set wildmenu
set wildmode=longest:list,full
set hlsearch
set pastetoggle=<F2>
set encoding=utf-8
set laststatus=2
set nocursorline
set colorcolumn=80
" read/write a .viminfo file, don't store more than 50 lines of registers
set viminfo='20,\"50
" Spaces > tabs
set expandtab
set tabstop=2
set shiftwidth=2
set smarttab
set softtabstop=2 " Makes backspace key treat four spaces like a tab
" for php files, 4 spaces
autocmd Filetype php setlocal ts=4 sw=4 sts=4 expandtab
" Suffixes that get lower priority when doing tab completion for filenames.
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc
" Map some keys to 'functions'
map <F4> <ESC>:set nopaste!<CR>
noremap gfv :vs <cfile><cr>
" open nerdtree by using Alt+1
execute "set <M-1>=\e1"
nnoremap <M-1> :NERDTreeToggle<CR>
:function! GetFileType()
: let filename = tolower(bufname('%'))
: let pos = matchend(filename, '\.') - 1
: let len = strlen(filename) - pos
: let fileType = strpart(filename, pos, len)
: return fileType
:endfunction
if v:version >= 700
" Tabs
map <C-T> :tabnew<CR>
imap <C-T> <C-O>:tabnew<CR>
else
" http://vim.sourceforge.net/tips/tip.php?tip_id=173
set wmh=0 " Minimum window height
set wmw=0 " Minimum window width
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_
nmap <C-H> <C-W>h<C-W><BAR>
nmap <C-L> <C-W>l<C-W><BAR>
endif
" No icky toolbar, menu or scrollbars in the GUI
if has('gui')
set guioptions-=m
set guioptions-=T
set guioptions-=l
set guioptions-=L
set guioptions-=r
set guioptions-=R
end
" Nice window title
if has('title') && (has('gui_running') || &title)
set titlestring=
set titlestring+=%f\ " file name
set titlestring+=%h%m%r%w " flags
endif
" Make <space> in normal mode go down a page rather than left a character
noremap <space> <C-f>
" Use default templates based on filename
let filetype = GetFileType()
let template = ''
let templateDir = '~/.vim/templates/'
if filetype == '.php'
let template = 'php'
elseif filetype == '.sh'
let template = 'bash'
endif
" Use template to build file
if template != ''
let template = templateDir . template
au BufNewFile * execute ':0r ' . template
" Remove last line if its empty
if getline(line('$')) == ''
au BufNewFile * execute ':' . line('$') . 'delete 1'
endif
" Insert script name automagically
let name = 'myscript'
au BufNewFile * silent! execute ':%s/<vi-tpl-name>/' . name . '/g'
" Insert author automatically
let author = system('finger ' . $USER . ' | grep Name | sed "s/.*Name:\ //"')
let len = strlen(author)
let author = strpart(author,0,len-1)
if author != ''
au BufNewFile * silent! execute ':%s/<vi-tpl-author>/' . author . '/g'
endif
" Insert time automagically
let time = strftime('%d\/%m\/%Y')
au BufNewFile * silent! execute ':%s/<vi-tpl-time>/' . time . '/g'
" Insert tab-settings automagically
let tabsettings = system('cat ~/.vim/templates/tabsettings')
let tabsettings = substitute(tabsettings, '\n', '\r', 'g')
au BufNewFile * silent! execute ':%s/<vi-tpl-tabsettings>\n/' . tabsettings . '/g'
endif
" Make p in Visual mode replace the selected text with the "" register.
vnoremap p <Esc>:let current_reg = @"<CR>gvdi<C-R>=current_reg<CR><Esc>
" Smartindent for Python files. Auto-indent to next level after a keyword
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
" Trim trailing whitespace in Python scripts
au BufWritePre *.py normal m`:%s/\s\+$//e ``
" Set filetypes from extension
au BufNewFile,BufRead .torsmorc* set filetype=rc
au BufNewFile,BufRead *.inc set filetype=php
au BufNewFile,BufRead *.sys set filetype=php
au BufNewFile,BufRead grub.conf set filetype=grub
if ($TERM == "rxvt-unicode") && (&termencoding == "")
set termencoding=utf-8
endif
" auto-fix annoying typos
iab teh the
command W w
command Q q
" tip from http://vim.wikia.com/wiki/Highlight_unwanted_spaces
highlight ExtraWhitespace ctermbg=darkgreen guibg=darkgreen
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
cmap w!! %!sudo tee > /dev/null %
" Set up the status line
fun! <SID>SetStatusLine()
let l:s1="%-3.3n\\ %f\\ %h%m%r%w"
let l:s2="[%{strlen(&filetype)?&filetype:'?'},%{&encoding},%{&fileformat}]"
let l:s3="%=\\ 0x%-8B\\ \\ %-14.(%l,%c%V%)\\ %<%P"
execute "set statusline=" . l:s1 . l:s2 . l:s3
endfun
call <SID>SetStatusLine()
source ~/.vim/indent/apachestyle.vim