诸葛孔明没灯

导航

 
  1 " Sets how many lines of history VIM has to remember
  2 set history=700
  3 
  4 " Enable filetype plugins
  5 filetype plugin on
  6 filetype indent on
  7 
  8 " Set to auto read when a file is changed from the outside
  9 set autoread
 10 
 11 " With a map leader it's possible to do extra key combinations
 12 " like <leader>w saves the current file
 13 let mapleader = ","
 14 let g:mapleader = ","
 15 
 16 " Fast saving
 17 nmap <leader>w :w!<cr>
 18 map <leader>e :e! ~/.vimrc<cr>                          " fast editing of .vimrc
 19 autocmd! bufwritepost .vimrc source ~/.vimrc            " when vimrc is edited, reload it
 20 autocmd! bufwritepost yerik_night.vim :colo yerik_night " when colorfile is edited, reload it
 21 
 22 " set indent length for html like files
 23 au FileType html,xhtml,xml setl ts=2
 24 au FileType html,xhtml,xml setl sts=2
 25 au FileType html,xhtml,xml setl sw=2
 26 
 27 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 28 " => VIM user interface
 29 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 30 " Set 7 lines to the cursor - when moving vertically using j/k
 31 set so=7
 32 
 33 " Turn on the WiLd menu
 34 set wildmenu
 35 
 36 " Ignore compiled files
 37 set wildignore=*.o,*~,*.pyc
 38 
 39 "Always show current position
 40 set ruler
 41 
 42 " Height of the command bar
 43 "set cmdheight=2
 44 
 45 " A buffer becomes hidden when it is abandoned
 46 set hid
 47 
 48 " Configure backspace so it acts as it should act
 49 set backspace=eol,start,indent
 50 set whichwrap+=<,>,h,l
 51 
 52 "show line number
 53 set nu
 54 
 55 " Ignore case when searching
 56 set ignorecase
 57 
 58 " When searching try to be smart about cases 
 59 set smartcase
 60 
 61 " Highlight search results
 62 set hlsearch
 63 
 64 " Makes search act like search in modern browsers
 65 set incsearch
 66 
 67 " Don't redraw while executing macros (good performance config)
 68 set lazyredraw
 69 
 70 " For regular expressions turn magic on
 71 set magic
 72 
 73 " Show matching brackets when text indicator is over them
 74 set showmatch
 75 " How many tenths of a second to blink when matching brackets
 76 set mat=2
 77 
 78 " No annoying sound on errors
 79 set noerrorbells
 80 set novisualbell
 81 set t_vb=
 82 set tm=500
 83 
 84 
 85 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 86 " => Colors and Fonts
 87 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 88 " Enable syntax highlighting
 89 syntax enable
 90 
 91 colorscheme desert
 92 set background=dark
 93 
 94 " Set extra options when running in GUI mode
 95 if has("gui_running")
 96     set guioptions-=T
 97     set guioptions+=e
 98     set t_Co=256
 99     set guitablabel=%M\ %t
100 endif
101 
102 " Set utf8 as standard encoding and en_US as the standard language
103 set encoding=utf8
104 
105 " Use Unix as the standard file type
106 set ffs=unix,dos,mac
107 
108 
109 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
110 " => Files, backups and undo
111 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
112 " Turn backup off, since most stuff is in SVN, git et.c anyway...
113 set nobackup
114 set nowb
115 set noswapfile
116 
117 
118 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
119 " => Text, tab and indent related
120 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
121 " Use spaces instead of tabs
122 set expandtab
123 
124 " Be smart when using tabs ;)
125 set smarttab
126 
127 " 1 tab == 4 spaces
128 set shiftwidth=4
129 set tabstop=4
130 
131 " Linebreak on 500 characters
132 set lbr
133 set tw=500
134 
135 set ai "Auto indent
136 set si "Smart indent
137 set wrap "Wrap lines
138 
139 
140 """"""""""""""""""""""""""""""
141 " => Visual mode related
142 """"""""""""""""""""""""""""""
143 " Visual mode pressing * or # searches for the current selection
144 " Super useful! From an idea by Michael Naumann
145 vnoremap <silent> * :call VisualSelection('f')<CR>
146 vnoremap <silent> # :call VisualSelection('b')<CR>
147 
148 
149 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
150 " => Moving around, tabs, windows and buffers
151 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
152 " Treat long lines as break lines (useful when moving around in them)
153 map j gj
154 map k gk
155 
156 " Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
157 map <space> /
158 map <c-space> ?
159 
160 " Disable highlight when <leader><cr> is pressed
161 map <silent> <leader><cr> :noh<cr>
162 
163 " Smart way to move between windows
164 map <C-j> <C-W>j
165 map <C-k> <C-W>k
166 map <C-h> <C-W>h
167 map <C-l> <C-W>l
168 
169 " Close the current buffer
170 map <leader>bd :Bclose<cr>
171 
172 " Close all the buffers
173 map <leader>ba :1,1000 bd!<cr>
174 
175 " Useful mappings for managing tabs
176 map <leader>tn :tabnew<cr>
177 map <leader>to :tabonly<cr>
178 map <leader>tc :tabclose<cr>
179 map <leader>tm :tabmove
180 
181 " Opens a new tab with the current buffer's path
182 " Super useful when editing files in the same directory
183 map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
184 
185 " Switch CWD to the directory of the open buffer
186 map <leader>cd :cd %:p:h<cr>:pwd<cr>
187 
188 " Specify the behavior when switching between buffers 
189 try
190   set switchbuf=useopen,usetab,newtab
191   set stal=2
192 catch
193 endtry
194 
195 " Return to last edit position when opening files (You want this!)
196 
197 autocmd BufReadPost *
198      \ if line("'\"") > 0 && line("'\"") <= line("$") |
199      \   exe "normal! g`\"" |
200      \ endif
201 " Remember info about open buffers on close
202 set viminfo^=%
203 
204 
205 """"""""""""""""""""""""""""""
206 " => Status line
207 """"""""""""""""""""""""""""""
208 " Always show the status line
209 set laststatus=2
210 
211 " Format the status line
212 set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ \ [%r%{getcwd()}%h]\ \ \ [Line:\ %l]
213 
214 
215 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
216 " => Editing mappings
217 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
218 " Remap VIM 0 to first non-blank character
219 map 0 ^
220 
221 " Move a line of text using ALT+[jk] or Comamnd+[jk] on mac
222 nmap <M-j> mz:m+<cr>`z
223 nmap <M-k> mz:m-2<cr>`z
224 vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
225 vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
226 
227 if has("mac") || has("macunix")
228   nmap <D-j> <M-j>
229   nmap <D-k> <M-k>
230   vmap <D-j> <M-j>
231   vmap <D-k> <M-k>
232 endif
233 
234 " Delete trailing white space on save, useful for Python and CoffeeScript ;)
235 func! DeleteTrailingWS()
236   exe "normal mz"
237   %s/\s\+$//ge
238   exe "normal `z"
239 endfunc
240 autocmd BufWrite *.py :call DeleteTrailingWS()
241 autocmd BufWrite *.coffee :call DeleteTrailingWS()
242 
243 
244 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
245 " => vimgrep searching and cope displaying
246 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
247 " When you press gv you vimgrep after the selected text
248 vnoremap <silent> gv :call VisualSelection('gv')<CR>
249 
250 " Open vimgrep and put the cursor in the right position
251 map <leader>g :vimgrep // **/*.<left><left><left><left><left><left><left>
252 
253 " Vimgreps in the current file
254 map <leader><space> :vimgrep // <C-R>%<C-A><right><right><right><right><right><right><right><right><right>
255 
256 " When you press <leader>r you can search and replace the selected text
257 vnoremap <silent> <leader>r :call VisualSelection('replace')<CR>
258 
259 " Do :help cope if you are unsure what cope is. It's super useful!
260 "
261 " When you search with vimgrep, display your results in cope by doing:
262 "   <leader>cc
263 "
264 " To go to the next search result do:
265 "   <leader>n
266 "
267 " To go to the previous search results do:
268 "   <leader>p
269 "
270 map <leader>cc :botright cope<cr>
271 map <leader>co ggVGy:tabnew<cr>:set syntax=qf<cr>pgg
272 map <leader>n :cn<cr>
273 map <leader>p :cp<cr>
274 
275 
276 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
277 " => Spell checking
278 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
279 " Pressing ,ss will toggle and untoggle spell checking
280 map <leader>ss :setlocal spell!<cr>
281 
282 " Shortcuts using <leader>
283 map <leader>sn ]s
284 map <leader>sp [s
285 map <leader>sa zg
286 map <leader>s? z=
287 
288 
289 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
290 " => Misc
291 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
292 " Remove the Windows ^M - when the encodings gets messed up
293 noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
294 
295 " Quickly open a buffer for scripbble
296 map <leader>q :e ~/buffer<cr>
297 
298 " Toggle paste mode on and off
299 map <leader>pp :setlocal paste!<cr>
300 
301 
302 
303 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
304 " => Helper functions
305 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
306 function! CmdLine(str)
307     exe "menu Foo.Bar :" . a:str
308     emenu Foo.Bar
309     unmenu Foo
310 endfunction
311 
312 function! VisualSelection(direction) range
313     let l:saved_reg = @"
314     execute "normal! vgvy"
315 
316     let l:pattern = escape(@", '\\/.*$^~[]')
317     let l:pattern = substitute(l:pattern, "\n$", "", "")
318 
319     if a:direction == 'b'
320         execute "normal ?" . l:pattern . "^M"
321     elseif a:direction == 'gv'
322         call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
323     elseif a:direction == 'replace'
324         call CmdLine("%s" . '/'. l:pattern . '/')
325     elseif a:direction == 'f'
326         execute "normal /" . l:pattern . "^M"
327     endif
328 
329     let @/ = l:pattern
330     let @" = l:saved_reg
331 endfunction
332 
333 
334 " Returns true if paste mode is enabled
335 function! HasPaste()
336     if &paste
337         return 'PASTE MODE  '
338     en
339     return ''
340 endfunction
341 
342 " Don't close window, when deleting a buffer
343 command! Bclose call <SID>BufcloseCloseIt()
344 function! <SID>BufcloseCloseIt()
345    let l:currentBufNum = bufnr("%")
346    let l:alternateBufNum = bufnr("#")
347 
348    if buflisted(l:alternateBufNum)
349      buffer #
350    else
351      bnext
352    endif
353 
354    if bufnr("%") == l:currentBufNum
355      new
356    endif
357 
358    if buflisted(l:currentBufNum)
359      execute("bdelete! ".l:currentBufNum)
360    endif
361 endfunction
362 """""""""""""""""""""Program C/C++ &Python"""""""""""""""""""""""""""""
363 "command -nargs=0 CC :!gcc % && ./a.out
364 "command -nargs=0 CPP : !g++ % && ./a.out
365 "command -nargs=0 PY : !python %
366 " 鎻掑叆鍖归厤鎷彿
367 inoremap ( ()<LEFT>
368 inoremap [ []<LEFT>
369 inoremap { {}<LEFT>
370 " select, copy, cut, paste
371 map <C-a> ggVG
372 map <C-c> "*y
373 map <C-x> "*x
374 map <C-p> "*p

 

posted on 2013-04-28 15:18  诸葛孔明没灯  阅读(337)  评论(0编辑  收藏  举报