Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.04 KB | None | 0 0
  1. set nocompatible
  2. filetype on
  3. filetype off
  4. set encoding=utf-8
  5. let &t_Co=256
  6. set linespace=0
  7. set lazyredraw
  8. set ttyfast
  9. set autoindent " always set autoindenting on
  10. set copyindent " copy the previous indentation on autoindenting
  11. set colorcolumn=100
  12. set formatprg=par\ -w100
  13. set list
  14. set relativenumber
  15.  
  16. let mapleader = ','
  17.  
  18. " Moving lines in VISUAL mode
  19. vnoremap <C-j> :m '>+1<CR>gv=gv
  20. vnoremap <C-k> :m '<-2<CR>gv=gv
  21. noremap <leader>w :w<CR>
  22. noremap <leader>W :wq<CR>
  23. noremap <leader>q :q<CR>
  24. nnoremap <leader>Q :q!<CR>
  25. noremap <S-l> gt
  26. noremap <S-h> gT
  27.  
  28. " PACKAGE LIST
  29. " Use this variable inside your local configuration to declare
  30. " which package you would like to include
  31. "
  32. if ! exists('g:vimified_packages')
  33. let g:vimified_packages = ['general', 'fancy', 'coding', 'indent', 'golang', 'ruby', 'rails', 'rspec', 'javascript', 'colour', 'ctags']
  34. endif
  35.  
  36. " Vundle
  37. "
  38. """""""""""""""""""""""""""""""""""""""
  39. set rtp+=~/.vim/bundle/Vundle.vim
  40. call vundle#begin()
  41. Plugin 'gmarik/Vundle.vim'
  42. Plugin 'tpope/vim-sensible'
  43.  
  44. " Package: General
  45. "
  46. """""""""""""""""""""""""""""""""""""""
  47. if count(g:vimified_packages, 'general')
  48. Plugin 'vitalk/vim-simple-todo'
  49.  
  50. Plugin 'rking/ag.vim'
  51. function! AgGrep()
  52. let command = 'ag -i '.expand('<cword>')
  53. cexpr system(command)
  54. cw
  55. endfunction
  56.  
  57. function! AgVisual()
  58. normal gv"xy
  59. let command = 'ag -i '.@x
  60. cexpr system(command)
  61. cw
  62. endfunction
  63.  
  64. map <leader>a :call AgGrep()<CR>
  65. vmap <leader>a :call AgVisual()<CR>
  66.  
  67. Plugin 'tpope/vim-surround'
  68. " Add $ as a jQuery surround, _ for Underscore.js
  69. autocmd FileType javascript let b:surround_36 = "$(\r)"
  70. \ | let b:surround_95 = "_(\r)"
  71.  
  72. Plugin 'kana/vim-textobj-user'
  73. Plugin 'kana/vim-textobj-line'
  74. Plugin 'terryma/vim-multiple-cursors'
  75.  
  76. Plugin 'scrooloose/nerdtree'
  77. let NERDTreeHijackNetrw = 0
  78. let g:NERDTreeWinSize = 25
  79. let g:NERDTreeChDirMode = 2
  80. let NERDTreeShowHidden = 1
  81. map \ :NERDTreeToggle<CR>
  82. map \| :NERDTreeFind<CR>
  83.  
  84. Plugin 'ctrlpvim/ctrlp.vim'
  85. let g:ctrlp_match_window = 'bottom,order:ttb,min:1,max:10,results:10'
  86. let g:ctrlp_clear_cache_on_exit = 0
  87. let g:ctrlp_max_files = 0
  88. let g:ctrlp_prompt_mappings = {
  89. \ 'AcceptSelection("e")': ['<c-t>'],
  90. \ 'AcceptSelection("t")': ['<cr>', '<2-LeftMouse>'],
  91. \ }
  92.  
  93. nnoremap <silent> <leader>f :CtrlP<CR>
  94. noremap <leader>b :CtrlPBuffer<CR>
  95.  
  96. Plugin 'FelikZ/ctrlp-py-matcher'
  97. let g:ctrlp_match_func = { 'match': 'pymatcher#PyMatch' }
  98.  
  99. if executable('ag')
  100. " Use Ag over Grep
  101. set grepprg=ag\ --nogroup\ --nocolor
  102.  
  103. let g:ctrlp_user_command = 'ag %s -i --nocolor --nogroup --ignore ".git" --ignore ".DS_Store" --hidden -g ""'
  104. else
  105. nnoremap <silent> <leader>F :ClearCtrlPCache<CR>\|:CtrlP<CR>
  106. endif
  107.  
  108. " File Renaming (credit: garybernhardt)
  109. function! RenameFile()
  110. let old_name = expand('%')
  111. let new_name = input('New file name: ', expand('%'), 'file')
  112. if new_name != '' && new_name != old_name
  113. exec ':saveas ' . new_name
  114. exec ':silent !rm ' . old_name
  115. redraw!
  116. endif
  117. endfunction
  118. map <leader>n :call RenameFile()<cr>
  119.  
  120. " Smart Tab completion (credit: garybernhardt)
  121. function! InsertTabWrapper()
  122. let col = col('.') - 1
  123. if !col || getline('.')[col - 1] !~ '\k'
  124. return "\<tab>"
  125. else
  126. return "\<c-p>"
  127. endif
  128. endfunction
  129. " inoremap <tab> <c-r>=InsertTabWrapper()<cr>
  130. inoremap <s-tab> <c-n>
  131.  
  132. function! SetupWrapping()
  133. set wrap
  134. set wrapmargin=2
  135. set textwidth=100
  136. endfunction
  137. au BufRead,BufNewFile *.txt call SetupWrapping()
  138. au BufRead,BufNewFile *.md call SetupWrapping()
  139. endif
  140.  
  141. " Package: Fancy
  142. "
  143. """""""""""""""""""""""""""""""""""""""
  144. if count(g:vimified_packages, 'fancy')
  145. Plugin 'vim-airline/vim-airline'
  146. Plugin 'vim-airline/vim-airline-themes'
  147. Plugin 'enricobacis/vim-airline-clock'
  148. let g:airline_theme='one'
  149. let g:airline_powerline_fonts=1
  150. let g:airline#extensions#tabline#enabled = 1
  151. let g:airline#extensions#tabline#show_buffers = 0
  152. let g:airline#extensions#tabline#show_splits = 0
  153. let g:airline#extensions#tabline#show_tabs = 1
  154. let g:airline#extensions#tabline#show_tab_nr = 0
  155. let g:airline#extensions#tabline#show_tab_type = 0
  156. let g:airline#extensions#tabline#close_symbol = '×'
  157. let g:airline#extensions#tabline#show_close_button = 0
  158. endif
  159.  
  160. " Package: Coding
  161. "
  162. """""""""""""""""""""""""""""""""""""""
  163. if count(g:vimified_packages, 'coding')
  164.  
  165. Plugin 'sbdchd/neoformat'
  166. Plugin 'tpope/vim-fugitive'
  167. map <leader>g :Gblame<CR>
  168.  
  169. Plugin 'tpope/vim-commentary'
  170. xmap <leader>/ <Plug>Commentary
  171. nmap <leader>/ <Plug>CommentaryLine
  172.  
  173. Plugin 'AndrewRadev/splitjoin.vim'
  174. Plugin 'tpope/vim-endwise'
  175.  
  176. " strip trailing whitespace on save
  177. function! StripTrailingWhitespace()
  178. let save_cursor = getpos('.')
  179. %s/\s\+$//e
  180. call setpos('.', save_cursor)
  181. endfunction
  182. autocmd BufWritePre *.rb,*.yml,*.js,*jsx,*.css,*.less,*.sass,*.scss,*.html,*.xml,*.erb,*.haml,*.coffee call StripTrailingWhitespace()
  183.  
  184. Plugin 'w0rp/ale'
  185. Plugin 'MarcWeber/vim-addon-mw-utils'
  186. Plugin 'tomtom/tlib_vim'
  187. Plugin 'SirVer/ultisnips'
  188.  
  189. Plugin 'argtextobj.vim'
  190. Plugin 'terryma/vim-expand-region'
  191. Plugin 'ervandew/supertab'
  192.  
  193. Plugin 'Valloric/YouCompleteMe'
  194. " make YCM compatible with UltiSnips (using supertab)
  195. let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
  196. let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
  197. let g:SuperTabDefaultCompletionType = '<C-n>'
  198.  
  199. " better key bindings for UltiSnipsExpandTrigger
  200. let g:UltiSnipsExpandTrigger = "<tab>"
  201. let g:UltiSnipsJumpForwardTrigger = "<tab>"
  202. let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
  203. endif
  204.  
  205. " Package: Indent
  206. "
  207. """""""""""""""""""""""""""""""""""""""
  208. if count(g:vimified_packages, 'indent')
  209. Plugin 'michaeljsmith/vim-indent-object'
  210. let g:indentobject_meaningful_indentation = ['haml', 'sass', 'yaml', 'markdown']
  211.  
  212. Plugin 'Yggdroot/indentLine'
  213. let g:indentLine_fileType = ['yaml', 'coffee']
  214. endif
  215.  
  216. " Package: Go
  217. "
  218. if count(g:vimified_packages, 'golang')
  219. Plugin 'fatih/vim-go'
  220. let g:go_fmt_command = "goimports"
  221. let g:go_highlight_types = 0
  222. let g:go_highlight_functions = 0
  223. let g:go_highlight_methods = 1
  224. let g:go_metalinter_autosave = 1
  225. let g:go_auto_type_info = 1
  226. let g:go_auto_sameids = 0
  227. autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
  228. autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
  229. autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
  230. autocmd Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tab drop')
  231. noremap <C-b> :GoRun<CR>
  232. endif
  233.  
  234. " Package: Ruby
  235. "
  236. """""""""""""""""""""""""""""""""""""""
  237. if count(g:vimified_packages, 'ruby') || count(g:vimified_packages, 'rails')
  238. Plugin 'vim-ruby/vim-ruby'
  239. Plugin 'nelstrom/vim-textobj-rubyblock'
  240.  
  241. let g:textobj_rubysymbol_no_default_key_mappings = 1
  242. xmap as <Plug>(textobj-rubysymbol-a)
  243. omap as <Plug>(textobj-rubysymbol-a)
  244. xmap is <Plug>(textobj-rubysymbol-i)
  245. omap is <Plug>(textobj-rubysymbol-i)
  246. Plugin 'bootleq/vim-textobj-rubysymbol'
  247.  
  248. " set question mark to be part of a VIM word. in Ruby it is!
  249. autocmd FileType ruby set iskeyword=@,48-57,_,?,!,192-255
  250.  
  251. set wildignore+=*.gem
  252.  
  253. " ysiw# Wrap the token under the cursor in #{}
  254. " v...s# Wrap the selection in #{}
  255. let g:surround_113 = "#{\r}" " v
  256. let g:surround_35 = "#{\r}" " #
  257.  
  258. " ,# Surround a word with #{ruby interpolation}
  259. map ,# ysiw#
  260. vmap ,# c#{<C-R>"}<ESC>
  261. endif
  262.  
  263. " Package: Rails
  264. "
  265. """""""""""""""""""""""""""""""""""""""
  266. if count(g:vimified_packages, 'rails')
  267. Plugin 'tpope/vim-rails'
  268. let g:rails_ctags_arguments='--exclude=".git" --exclude="log" --exclude="doc" --exclude="spec/javascripts/helpers"'
  269.  
  270. Plugin 'othree/html5.vim'
  271.  
  272. Plugin 'plasticboy/vim-markdown'
  273. let g:vim_markdown_folding_disabled=1
  274.  
  275. autocmd FileType scss set iskeyword=@,48-57,_,-,?,!,192-255
  276.  
  277. set wildignore+=*/public/assets/**
  278. set wildignore+=*/vendor/rails/**
  279. set wildignore+=*/vendor/cache/**
  280.  
  281. " wrap selection in erb tags
  282. let g:surround_45 = "<% \r %>" " -
  283. let g:surround_61 = "<%= \r %>" " =
  284. endif
  285.  
  286. " Package: Rspec
  287. "
  288. """""""""""""""""""""""""""""""""""""""
  289. if count(g:vimified_packages, 'rspec')
  290. Plugin 'keith/rspec.vim'
  291. endif
  292.  
  293. " Package: Javascript
  294. "
  295. """""""""""""""""""""""""""""""""""""""
  296. if count(g:vimified_packages, 'javascript')
  297. Plugin 'kchmck/vim-coffee-script'
  298. Plugin 'mustache/vim-mustache-handlebars'
  299. Plugin 'pangloss/vim-javascript'
  300. Plugin 'mxw/vim-jsx'
  301. Plugin 'kana/vim-textobj-function'
  302. Plugin 'thinca/vim-textobj-function-javascript'
  303. Plugin 'mattn/emmet-vim'
  304.  
  305. let g:user_emmet_settings = {
  306. \ 'javascript.jsx' : {
  307. \ 'extends' : 'jsx',
  308. \ },
  309. \}
  310.  
  311. au BufNewFile,BufRead *.json set filetype=javascript
  312. endif
  313.  
  314. " Package: Ctags
  315. "
  316. """""""""""""""""""""""""""""""""""""""
  317. if count(g:vimified_packages, 'ctags')
  318. Plugin 'folke/AutoTag'
  319.  
  320. let g:autotagExcludeSuffixes="tml.xml.text.txt.vim"
  321. map <leader>rt :!ctags --extra=+f --exclude=.git --exclude=log --exclude=doc -R *<CR><CR>
  322. map <C-\> :tnext<CR>
  323. endif
  324.  
  325. " Package: Colour
  326. "
  327. """""""""""""""""""""""""""""""""""""""
  328. if count(g:vimified_packages, 'colour') || count(g:vimified_packages, 'color')
  329. Plugin 'rakr/vim-one', {'rtp': 'vim/'}
  330.  
  331. :hi TabLineFill term=bold cterm=bold ctermbg=237
  332. endif
  333.  
  334. call vundle#end()
  335. filetype plugin indent on
  336. syntax on
  337.  
  338. if count(g:vimified_packages, 'coding')
  339. let g:expand_region_text_objects = {
  340. \ 'iw' :0,
  341. \ 'i"' :0,
  342. \ 'i''' :0,
  343. \ 'i]' :1,
  344. \ 'ia' :0,
  345. \ 'aa' :0,
  346. \ 'ib' :1,
  347. \ 'iB' :1,
  348. \ 'il' :0
  349. \ }
  350.  
  351. if count(g:vimified_packages, 'ruby') || count(g:vimified_packages, 'rails')
  352. call expand_region#custom_text_objects('ruby', {
  353. \ 'as' :1,
  354. \ 'ir' :1,
  355. \ 'ar' :1
  356. \ })
  357. call expand_region#custom_text_objects('html', {
  358. \ 'it' :1
  359. \ })
  360. endif
  361.  
  362. if count(g:vimified_packages, 'javascript')
  363. call expand_region#custom_text_objects('javascript', {
  364. \ 'if' :1,
  365. \ 'af' :1
  366. \ })
  367. call expand_region#custom_text_objects('coffee', {
  368. \ 'ii' :1
  369. \ })
  370. endif
  371. endif
  372.  
  373. if count(g:vimified_packages, 'colour') || count(g:vimified_packages, 'color')
  374. colorscheme one
  375. set background=light
  376. endif
  377.  
  378. "
  379. " Options
  380. "
  381. """""""""""""""""""""""""""""""""""""""
  382.  
  383. set notimeout " no command timeout
  384. set expandtab " use soft tabs
  385. set tabstop=2
  386. set shiftwidth=2 " width of auto-indent
  387. set softtabstop=2
  388. set nowrap " no wrapping
  389. set textwidth=0
  390. set number " line numbers
  391. set numberwidth=4
  392. autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=2 shiftwidth=2
  393.  
  394.  
  395. " completion sources: (current file, loaded buffers, unloaded buffers, tags)
  396. set complete=.,b,u,]
  397.  
  398. set wildmode=longest,list:longest
  399. set wildignore+=*vim/backups*
  400. set wildignore+=*DS_Store*
  401. set wildignore+=tags
  402. set wildignore+=*/tmp/**
  403. set wildignore+=*/log/**
  404. set wildignore+=.git,*.rbc,*.class,.svn,*.png,*.jpg,*.gif
  405.  
  406. set list " show whitespace
  407. if has('gui_running')
  408. set listchars=trail:·
  409. else
  410. set listchars=trail:~
  411. endif
  412.  
  413. set showtabline=2 " always show tab bar
  414. set showmatch " show matching brackets
  415. set hidden " allow hidden, unsaved buffers
  416. set splitbelow " add new window towards right
  417. set splitright " add new window towards bottom
  418. set scrolloff=3 " scroll when the cursor is 3 lines from bottom
  419. set sidescroll=1
  420. set sidescrolloff=5
  421. set cursorline " highlight current line
  422.  
  423. " Turn folding off for real, hopefully
  424. set foldmethod=manual
  425. set nofoldenable
  426.  
  427. " make searches case-sensitive only if they contain upper-case characters
  428. set smartcase
  429.  
  430. " store temporary files in a central spot
  431. set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
  432. set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
  433.  
  434. " switch syntax highlighting on, when the terminal has colors
  435. if &t_Co > 2 || has('gui_running')
  436. set hlsearch
  437. endif
  438.  
  439. "
  440. " Keybindings
  441. "
  442. """""""""""""""""""""""""""""""""""""""
  443.  
  444. " clear the search buffer when hitting space
  445. :nnoremap <space> :nohlsearch<cr>
  446.  
  447. " sometimes I hold the shift too long ... just allow it
  448. cabbrev W w
  449. cabbrev Q q
  450. cabbrev Tabe tabe
  451.  
  452. " split screen
  453. :noremap <leader>v :vsp<CR>
  454. :noremap <leader>h :split<CR>
  455.  
  456. " toggle fullscreen
  457. :noremap tt :tab split<CR>
  458. :noremap ty :tabc <CR>
  459.  
  460. " opens an edit command with the path of the currently edited file filled in
  461. map <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
  462.  
  463. " opens a tab edit command with the path of the currently edited file filled in
  464. " map <Leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR>
  465.  
  466. " make Y consistent with D and C
  467. map Y y$
  468. map <silent> <leader>y :<C-u>silent '<,'>w !pbcopy<CR>
  469.  
  470. " copy current file path to system pasteboard
  471. map <leader>C :let @* = expand("%")<CR>:echo "Copied: ".expand("%")<CR>
  472.  
  473. " reload .vimrc
  474. map <leader>rv :source ~/.vimrc<CR>
  475.  
  476. " open quickfix list item in new tab
  477. nnoremap <buffer> <CR> :tabnew\|cc <C-r>=line(".")<CR><CR>
  478.  
  479. if has('gui_macvim')
  480. " Fullscreen takes up entire screen
  481. set fuoptions=maxhorz,maxvert
  482. map <D-CR> :set invfu<cr>
  483. set guifont=Source\ Code\ Pro\ Medium:h14
  484.  
  485. endif
  486.  
  487. function! OpenTodo()
  488. let todoFile = getcwd() . "/todo.txt"
  489. if filereadable(todoFile)
  490. tab drop todo.txt | tabm 0
  491. endif
  492. endfunction
  493. nnoremap <leader>t :call OpenTodo()<CR>
  494.  
  495. set listchars=tab:\|\
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement