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