Guest User

vimrc

a guest
Sep 20th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 7.93 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. " alternatively, pass a path where Vundle should install plugins
  8. "call vundle#begin('~/some/path/here')
  9.  
  10. " let Vundle manage Vundle, required
  11. Plugin 'gmarik/Vundle.vim'
  12.  
  13. Plugin 'wojtekmach/vim-rename'
  14. Plugin 'Valloric/YouCompleteMe'
  15. Plugin 'scrooloose/nerdcommenter'
  16. Plugin 'scrooloose/nerdtree'
  17. Plugin 'ctrlpvim/ctrlp.vim'
  18. Plugin 'tpope/vim-surround'
  19. Plugin 'tpope/vim-repeat'
  20. Plugin 'tpope/vim-fugitive'
  21. Plugin 'tmhedberg/SimpylFold'
  22. Plugin 'scrooloose/syntastic'
  23. Plugin 'nathanaelkane/vim-indent-guides'
  24. Plugin 'python-mode/python-mode'
  25. " Necessary to install vim-session
  26. Plugin 'xolox/vim-misc'
  27. Plugin 'xolox/vim-session'
  28.  
  29. " All of your Plugins must be added before the following line
  30. call vundle#end()            " required
  31. filetype plugin indent on    " required
  32. " To ignore plugin indent changes, instead use:
  33. "filetype plugin on
  34. "
  35. " Brief help
  36. " :PluginList       - lists configured plugins
  37. " :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
  38. " :PluginSearch foo - searches for foo; append `!` to refresh local cache
  39. " :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
  40. "
  41. " see :h vundle for more details or wiki for FAQ
  42. " Put your non-Plugin stuff after this line
  43.  
  44. set encoding=utf-8
  45.  
  46. let mapleader=","
  47. set mouse=a
  48. set number
  49. set relativenumber
  50. set tabstop=4
  51. vmap <C-c> "+y
  52. set showtabline=1
  53. set shiftwidth=4
  54. set listchars=tab:\|\ ,trail:-
  55. set list
  56. set splitbelow
  57. set splitright
  58. set cc=80
  59. " Always show statusline
  60. set laststatus=2
  61. noremap <F2> :set tabstop=2<return>:set shiftwidth=2<return>:set expandtab<return>
  62. noremap <F3> :vsp<return>:NERDTree<return><C-w>l<return>:set showtabline=2<return>
  63. noremap <F4> :set tabstop=4<return>:set shiftwidth=4<return>:set expandtab<return>
  64. nnoremap <C-J> <C-W><C-J>
  65. nnoremap <C-K> <C-W><C-K>
  66. nnoremap <C-L> <C-W><C-L>
  67. nnoremap <C-H> <C-W><C-H>
  68.  
  69. " Dark color scheme
  70. colorscheme desertink
  71.  
  72. " Autocomplete like bash
  73. set wildmode=longest,list,full
  74. set wildmenu
  75.  
  76. " Change directory automatically
  77. set autochdir
  78.  
  79. " Replace word under cursor
  80. :nnoremap <Leader>s :%s/\<<C-r><C-w>\>/
  81.  
  82. " Necessary for NERD Commenter
  83. filetype plugin on
  84.  
  85. " Fix search/replace
  86. set ignorecase
  87. set smartcase
  88. set incsearch
  89. set showmatch
  90. set hlsearch
  91. " Unhighlight search results and close any preview buffers
  92. nnoremap <leader><space> :noh<cr><c-w>z<cr>
  93. nnoremap <tab> %
  94. vnoremap <tab> %
  95.  
  96. " Enable code folding
  97. set foldmethod=indent
  98. set foldlevel=99
  99. nnoremap <space> za
  100.  
  101. " Keep undo history
  102. set undofile
  103. set undodir=~/.vim/undo
  104.  
  105. " Reference text between the specified delimiters with the
  106. " <v/d/c/y><i/a><delimiter> idiom
  107. for char in [ '_', '.', ':', ',', ';', '/', '*', '+', '%', '-' ]
  108.   execute 'xnoremap i' . char . ' :<C-u>normal! T' . char . 'vt' . char . '<CR>'
  109.   execute 'onoremap i' . char . ' :normal vi' . char . '<CR>'
  110.   execute 'xnoremap a' . char . ' :<C-u>normal! F' . char . 'vf' . char . '<CR>'
  111.   execute 'onoremap a' . char . ' :normal va' . char . '<CR>'
  112. endfor
  113.  
  114. " In a visual selection, yank from each line until specified delimiter
  115. xno <leader>yt <esc>:call <sid>yank_before_pattern()<cr>
  116.  
  117. fu! s:yank_before_pattern() abort
  118.     let pattern = input('pattern: ')
  119.     norm! '<
  120.    if search(pattern, 'cnW', line("'>"))
  121.         exe "norm! y'>pV']:s/".pattern.".*//\<cr>gvd:noh<cr>"
  122.     endif
  123. endfu
  124.  
  125. " Set ctags file
  126. set tags=.tags;/
  127.  
  128. " Shortcuts for navigating to definitions using YouCompleteMe
  129. " Open definition in new vertical split
  130. map <leader>ds :vsp <CR>:exec("YcmCompleter GoToDefinitionElseDeclaration")<CR>
  131. " Open definition in new tab
  132. map <leader>dt :tab split<CR>:exec("YcmCompleter GoToDefinitionElseDeclaration")<CR>
  133.  
  134. " The Silver Searcher
  135. if executable('ag')
  136.   " Use ag over grep
  137.   set grepprg=ag\ --nogroup\ --nocolor
  138.  
  139.   " Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
  140.   let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
  141.  
  142.   " ag is fast enough that CtrlP doesn't need to cache
  143.   let g:ctrlp_use_caching = 0
  144. endif
  145.  
  146. " Fix order of ag results
  147. if executable('matcher')
  148.     let g:ctrlp_match_func = { 'match': 'GoodMatch' }
  149.  
  150.     function! GoodMatch(items, str, limit, mmode, ispath, crfile, regex)
  151.  
  152.       " Create a cache file if not yet exists
  153.       let cachefile = ctrlp#utils#cachedir().'/matcher.cache'
  154.       if !( filereadable(cachefile) && a:items == readfile(cachefile) )
  155.         call writefile(a:items, cachefile)
  156.       endif
  157.       if !filereadable(cachefile)
  158.         return []
  159.       endif
  160.  
  161.       " a:mmode is currently ignored. In the future, we should probably do
  162.       " something about that. the matcher behaves like "full-line".
  163.       let cmd = 'matcher --limit '.a:limit.' --manifest '.cachefile.' '
  164.       if !( exists('g:ctrlp_dotfiles') && g:ctrlp_dotfiles )
  165.         let cmd = cmd.'--no-dotfiles '
  166.       endif
  167.       let cmd = cmd.a:str
  168.  
  169.       return split(system(cmd), "\n")
  170.  
  171.     endfunction
  172. end
  173.  
  174. " Fuzzy search in buffer
  175. nnoremap <c-n> :CtrlPLine<CR>
  176.  
  177. " Session management
  178. " Save current session as default
  179. map <leader>ss :SaveSession
  180. " Open current session as default
  181. map <leader>os :OpenSession
  182. " Do not prompt to load or save the session
  183. let g:session_autoload = 'no'
  184. let g:session_autosave = 'no'
  185.  
  186. " Make fugitive open vertical splits
  187. set diffopt+=vertical
  188.  
  189. " Configure syntastic with default settings
  190. set statusline+=%#warningmsg#
  191. set statusline+=%{SyntasticStatuslineFlag()}
  192. set statusline+=%*
  193.  
  194. let g:syntastic_always_populate_loc_list = 1
  195. let g:syntastic_auto_loc_list = 1
  196. let g:syntastic_check_on_open = 1
  197. let g:syntastic_check_on_wq = 0
  198. let g:syntastic_loc_list_height=4
  199.  
  200.  
  201. " Configure Powerline
  202. python3 from powerline.vim import setup as powerline_setup
  203. python3 powerline_setup()
  204. python3 del powerline_setup
  205.  
  206.  
  207. " Configure YouCompleteMe
  208. let g:ycm_autoclose_preview_window_after_completion=1
  209. "let g:ycm_filetype_specific_completion_to_disable = {'python': 1}
  210. map <leader>g  :YcmCompleter GoToDefinitionElseDeclaration<CR>
  211.  
  212. " Display the documentation for a method using YouCompleteMe instead of pydoc
  213. nnoremap K :YcmCompleter GetDoc<CR>
  214.  
  215.  
  216. " Use ViM's old reg exp engine, since the new one is not great in some
  217. " circumstances. Experimental change.
  218. set regexpengine=1
  219.  
  220. " Use lazy redraw to attempt to improve scrolling speed. Experimental change
  221. " which many people agree should be set by default.
  222. set lazyredraw
  223.  
  224. """"""""""""""""""""""""
  225. " Python configuration "
  226. """"""""""""""""""""""""
  227. au BufNewFile,BufRead *.py
  228.     \ set tabstop=4 |
  229.     \ set softtabstop=4 |
  230.     \ set shiftwidth=4 |
  231.     \ set textwidth=79 |
  232.     \ set expandtab |
  233.     \ set autoindent |
  234.     \ set fileformat=unix
  235.  
  236. let python_highlight_all=1
  237. syntax on
  238.  
  239. " Add support to virtualenv in Python (detect whether we are in a virtual
  240. " environment and if so YouCompleteMe will do smart suggestions)
  241. py3 << EOF
  242. import os
  243. import sys
  244. if 'VIRTUAL_ENV' in os.environ:
  245.   project_base_dir = os.environ['VIRTUAL_ENV']
  246.   activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
  247.   execfile(activate_this, dict(__file__=activate_this))
  248. EOF
  249.  
  250. " python-mode
  251. let g:pymode_python='python3'
  252. " Disable rope completion, since it clashes with YouCompleteMe
  253. let g:pymode_rope=0
  254. let g:pymode_rope_completion=0
  255. let g:pymode_rope_complete_on_dot=0
  256. let g:pymode_rope_lookup_project=0
  257.  
  258. " Let syntastic run the checks for Python files when saving
  259. let g:pymode_lint_on_write=0
  260. " Disable preview of documentation when selecting an option from the
  261. " autocomplete menu
  262. set completeopt=menuone
  263.  
  264. """""""""""""""""""""""""""""""
  265. " End of Python configuration "
  266. """""""""""""""""""""""""""""""
  267.  
  268. " Flag extraneous whitespace.
  269. " This needs to come after the Python configuration.
  270. highlight BadWhitespace ctermbg=red guibg=darkred
  271. a
Add Comment
Please, Sign In to add comment