VanillaGranilla

vimrc

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