Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.10 KB | None | 0 0
  1. set nocompatible " be iMproved, required
  2. filetype off " required
  3.  
  4. " set the runtime path to include Vundle and initialize
  5. set rtp+=~/.vim/bundle/Vundle.vim
  6. call vundle#begin()
  7.  
  8. Plugin 'VundleVim/Vundle.vim'
  9.  
  10. " General Plugins
  11. Plugin 'tpope/vim-fugitive'
  12. Plugin 'scrooloose/syntastic'
  13. Plugin 'scrooloose/nerdtree'
  14. Plugin 'tomtom/tcomment_vim'
  15. Plugin 'Valloric/YouCompleteMe' " Requires Additional Installation
  16. Plugin 'ctrlpvim/ctrlp.vim'
  17. Plugin 'vim-scripts/YankRing.vim'
  18. Plugin 'rking/ag.vim' " Requires Additional Installation
  19. Plugin 'jeetsukumaran/vim-buffergator' " Requires Additional Installation
  20.  
  21. " Javascript plugins
  22. Plugin 'pangloss/vim-javascript', { 'for': ['javascript', 'javascript.jsx'] }
  23. " Plugin 'mxw/vim-jsx', { 'for': ['javascript', 'javascript.jsx'] }
  24.  
  25. " All of your Plugins must be added before the following line
  26. call vundle#end() " required
  27. filetype plugin indent on " required
  28. " To ignore plugin indent changes, instead use:
  29. "filetype plugin on
  30.  
  31. "----------------------------
  32. """" Basic Settings""""
  33. "----------------------------
  34.  
  35. "----leader settings----
  36. let mapleader=","
  37.  
  38. "----basic settings----
  39. syntax enable
  40. set ffs=unix,dos,mac " Use Unix as the standard file type
  41. set encoding=utf8 " Set utf8 as standard encoding and en_US as the standard language
  42. " Configure backspace so it acts as it should act
  43. set backspace=2
  44. set backspace=indent,eol,start
  45. fixdel
  46.  
  47. " Turn backup off, since most stuff is in SVN, git et.c anyway...
  48. set nobackup
  49. set nowb
  50. set noswapfile
  51.  
  52. "share the main mac clipboard
  53. set clipboard=unnamed
  54.  
  55. "----search settings----
  56. set ignorecase
  57. set smartcase
  58. :set hlsearch "highlight all search results after a search
  59. " clear last seach with leader space
  60. nnoremap <leader><space> :noh<cr>
  61.  
  62. "----indent settings----
  63. set cindent
  64. set tabstop=2
  65. set shiftwidth=2
  66. set expandtab
  67. :noremap > >>
  68. :noremap < <<
  69.  
  70. "----status line----
  71. set laststatus=2 " Always show the status line
  72. highlight User1 gui=NONE guifg=#ff0000 guibg=#d0d0e0
  73. " Format the status line
  74. set statusline=\ %{HasPaste()}%F%1*%m%*%r%h\ %w\ ln%l:%c
  75. set statusline+=%#warningmsg#
  76. set statusline+=%{SyntasticStatuslineFlag()}
  77. set statusline+=%*
  78.  
  79. let g:syntastic_always_populate_loc_list = 1
  80. let g:syntastic_auto_loc_list = 1
  81. let g:syntastic_check_on_open = 1
  82. let g:syntastic_check_on_wq = 0
  83.  
  84. "----other tweaks----
  85.  
  86. " quick editing the vimrc (and sourcing it, and if you want, auto sourcing after saving)
  87. nnoremap <silent> <leader>ev :tabedit $MYVIMRC<CR>
  88. nnoremap <silent> <leader>sv :so $MYVIMRC<CR>
  89.  
  90. " for when you accidentally capitalize W when typing :w to save
  91. :command! W w
  92. :command! Q w
  93. :command! Wq wq
  94. :command! WQ wq
  95.  
  96. " Toggle paste mode on and off
  97. map <leader>pp :setlocal paste!<cr>
  98.  
  99. " Remember cursor position between vim sessions
  100. autocmd BufReadPost *
  101. \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  102. \ exe "normal! g'\"" |
  103. \ endif
  104.  
  105. map 0 ^ " Remap VIM 0 to first non-blank character
  106. autocmd BufRead * normal zz " center buffer around cursor when opening files
  107. autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o " turn of auto-comments on new-line
  108.  
  109. " Remove Error Bells
  110. set noerrorbells visualbell t_vb=
  111. if has('autocmd')
  112. autocmd GUIEnter * set visualbell t_vb=
  113. endif
  114.  
  115. " Ctrl-A to select all
  116. noremap <c-a> ggVGy
  117. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  118. " Filetype Specific
  119. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  120. "----javascript settings----
  121. let g:vimjs#casesensistive = 1
  122. let g:vimjs#smartcomplete = 1
  123. set completeopt-=preview
  124. " run vim-jsx in js files
  125. let g:jsx_ext_required = 0
  126. " autocmd FileType typescript setlocal completeopt+=
  127. let g:typescript_indent_disable = 1
  128. let g:tsuquyomi_disable_quickfix = 1
  129. let g:vim_json_syntax_conceal = 0
  130. " angular stuff
  131. let g:used_javascript_libs = 'angularjs,angularuirouter'
  132.  
  133. "----python settings----
  134. " Delete Trailing Spaces for Python
  135. autocmd BufWrite *.py :call DeleteTrailingWS()
  136.  
  137. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  138. " Appearance Specific
  139. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  140. colorscheme molokai
  141. hi Normal ctermbg=NONE
  142. :set nowrap
  143. :set textwidth=0
  144. :set wrapmargin=0
  145. set relativenumber "Relative Line Numbering"
  146. set showmatch " Show matching brackets when text indicator is over them
  147.  
  148. """"""""""""""""""""""""""""""
  149. " => Visual mode related
  150. """"""""""""""""""""""""""""""
  151. " Visual mode pressing * or # searches for the current selection
  152. " Super useful! From an idea by Michael Naumann
  153. vnoremap <silent> * :call VisualSelection('f', '')<CR>
  154. vnoremap <silent> # :call VisualSelection('b', '')<CR>
  155.  
  156. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  157. " => Moving around, tabs, windows and buffers
  158. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  159. " move by 10's with capital hjkl
  160. noremap J 10j
  161. noremap K 10k
  162. noremap H 10h
  163. noremap L 10l
  164.  
  165. "----splits----
  166. " Easier way to move between splits
  167. nnoremap <C-j> <C-W>j
  168. nnoremap <C-k> <C-W>k
  169. nnoremap <C-h> <C-W>h
  170. nnoremap <C-l> <C-W>l
  171. " Increase and Decrease Split Size
  172. nnoremap + <c-w>>
  173. nnoremap - <c-w><
  174. nnoremap <bar> <c-w>=
  175. """ ubuntu alt mappings without meta
  176. " Close the current buffer with alt q
  177. nnoremap q :bd<cr>
  178. " Close all the buffers with alt d
  179. nnoremap d :bufdo bd<cr>
  180. nnoremap l :bnext!<cr>
  181. nnoremap h :bprevious!<cr>
  182. """ mac alt mappings without meta
  183. nnoremap œa :bufdo bd<cr>
  184. nnoremap œ :bd<cr>
  185. nnoremap ¬ :bnext<cr>
  186. nnoremap ˙ :bprevious<cr>
  187. " Note Alt key mappings on mac without setting meta key
  188. nnoremap <A-q> :bufdo bd<cr>
  189. nnoremap <A-d> :bd<cr>
  190. nnoremap <A-l> :bnext<cr>
  191. nnoremap <A-h> :bprevious<cr>
  192. " Useful mappings for managing tabs
  193. map <leader>tn :tabnew<cr>
  194. map <leader>td :tabclose<cr>
  195. " Move between vim tabs better than with gt and gT
  196. nnoremap <leader>h gT
  197. nnoremap <leader>l gt
  198. " Return to last edit position when opening files (You want this!)
  199. autocmd BufReadPost *
  200. \ if line("'\"") > 0 && line("'\"") <= line("$") |
  201. \ exe "normal! g`\"" |
  202. \ endif
  203. " Remember info about open buffers on close
  204. set viminfo^=%
  205. " marks
  206. nnoremap <leader>m :marks
  207.  
  208. "----------------------------
  209. """" Plugin Specific """"
  210. "----------------------------
  211. " syntastic settings
  212. let g:syntastic_javascript_checkers = ['jshint']
  213.  
  214. " fugitive settings
  215. nnoremap <leader>ga :Gwrite<CR>
  216. nnoremap <leader>gmh :diff //2<CR>
  217. nnoremap <leader>gmt :diff //3<CR>
  218. nnoremap <leader>gmu :diffupdate<CR>
  219.  
  220. " NERDTree settings
  221. map <leader>\ :NERDTreeToggle<CR>
  222. let NERDTreeShowHidden=1
  223. let g:NERDTreeWinSize=40
  224. let g:NERDTreeAutoDeleteBuffer=1
  225. set splitright
  226. let g:NERDTreeWinPos = "left"
  227. let g:NERDTreeDirArrowExpandable = '+'
  228. let g:NERDTreeDirArrowCollapsible = '-'
  229.  
  230. " yankring settings
  231. nmap <leader>y :YRShow<CR>
  232. let g:yankring_replace_n_nkey = '≤' "next paste option
  233. let g:yankring_replace_n_pkey = '≥' "prev paste option
  234.  
  235. " ag settings
  236. " When you press gv you Ag after the selected text
  237. vnoremap <silent> gv :call VisualSelection('gv', '')<CR>
  238. " When you press <leader>r you can search and replace the selected text
  239. vnoremap <silent> <leader>r :call VisualSelection('replace', '')<CR>
  240. map <leader>cc :botright cope<cr> " When you search with Ag, display your results in cope by doing:
  241. map <leader>co ggVGy:tabnew<cr>:set syntax=qf<cr>pgg
  242. map <leader>n :cn<cr> " To go to the next search result
  243. map <leader>p :cp<cr> " To go to the previous search results
  244. map <leader>g :Ag
  245. let g:ag_results_mapping_replacements={'vertical_split_silent': 's'}
  246.  
  247. " buffergator settings
  248. nnoremap <leader>b :BuffergatorToggle<CR>
  249.  
  250. " ctrl-p settings
  251. let g:ctrlp_map = '<c-p>'
  252. nmap <leader>c :CtrlP<CR>
  253.  
  254. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  255. " => Helper functions
  256. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  257. " Delete trailing white space on save, useful for Python and CoffeeScript ;)
  258. func! DeleteTrailingWS()
  259. exe "normal mz"
  260. %s/\s\+$//ge
  261. exe "normal `z"
  262. endfunc
  263.  
  264. function! CmdLine(str)
  265. exe "menu Foo.Bar :" . a:str
  266. emenu Foo.Bar
  267. unmenu Foo
  268. endfunction
  269.  
  270. function! VisualSelection(direction, extra_filter) range
  271. let l:saved_reg = @"
  272. execute "normal! vgvy"
  273.  
  274. let l:pattern = escape(@", '\\/.*$^~[]')
  275. let l:pattern = substitute(l:pattern, "\n$", "", "")
  276.  
  277. if a:direction == 'b'
  278. execute "normal ?" . l:pattern . "^M"
  279. elseif a:direction == 'gv'
  280. call CmdLine("Ag \"" . l:pattern . "\" " )
  281. elseif a:direction == 'replace'
  282. call CmdLine("%s" . '/'. l:pattern . '/')
  283. elseif a:direction == 'f'
  284. execute "normal /" . l:pattern . "^M"
  285. endif
  286.  
  287. let @/ = l:pattern
  288. let @" = l:saved_reg
  289. endfunction
  290.  
  291.  
  292. " Returns true if paste mode is enabled
  293. function! HasPaste()
  294. if &paste
  295. return 'PASTE MODE '
  296. endif
  297. return ''
  298. endfunction
  299.  
  300. " Don't close window, when deleting a buffer
  301. command! Bclose call <SID>BufcloseCloseIt()
  302. function! <SID>BufcloseCloseIt()
  303. let l:currentBufNum = bufnr("%")
  304. let l:alternateBufNum = bufnr("#")
  305.  
  306. if buflisted(l:alternateBufNum)
  307. buffer #
  308. else
  309. bnext
  310. endif
  311.  
  312. if bufnr("%") == l:currentBufNum
  313. new
  314. endif
  315.  
  316. if buflisted(l:currentBufNum)
  317. execute("bdelete! ".l:currentBufNum)
  318. endif
  319. endfunction
  320.  
  321. " Make VIM remember position in file after reopen
  322. if has("autocmd")
  323. au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
  324. endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement