Advertisement
DimaT1

init.vim

May 14th, 2019
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 6.89 KB | None | 0 0
  1. " Auto update file when it is changed outside vim
  2. " TODO: does not work as it expected with nvim
  3. set autoread
  4.  
  5. " Aesthetic line numeration
  6. set nu rnu
  7.  
  8. " Leader Key
  9. let mapleader = ","
  10.  
  11. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  12. " Text, tab and indent related
  13. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  14. " Use spaces instead of tabs
  15. set expandtab
  16.  
  17. " Smart tabs
  18. set smarttab
  19.  
  20. " 1 tab == 4 spaces
  21. set shiftwidth=4
  22. set tabstop=4
  23.  
  24. " Linebreak on 500 characters
  25. set lbr
  26. set tw=500
  27.  
  28. set ai " Auto indent
  29. set si " Smart indent
  30. set wrap " Wrap lines
  31.  
  32.  
  33. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  34. " Autocompile, file format
  35. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  36. " Run golang file
  37. au FileType go map <F8> :w <CR> : !clear; go run % <CR>
  38.  
  39. " Auto pep8 for python (autopep8 is required)
  40. au FileType python map <F7> :w <CR> : !clear; autopep8 --in-place % <CR> :e <CR>
  41. " Run python3 file
  42. au FileType python map <F8> :w <CR> : !clear; python3 % <CR>
  43.  
  44. " Auto format C/C++ file (clang-format is required)
  45. au FileType c,cpp,objc map <F7> :w <CR> : !clear; clang-format % >> temp.cpp; mv temp.cpp % <CR> :e <CR>
  46. " Build & run C++ file with g++ -std=c++11
  47. au FileType cpp map <F8> :w <CR> : !clear; ~/Projects/cpp/build_n_run_cpp11.sh % <CR>
  48.  
  49. " Build & run C file with gcc -std=c99
  50. au FileType c map <F8> :w <CR> : !clear; ~/Projects/cpp/build_n_run_c99.sh % <CR>
  51. " Build & run C file with tcc
  52. au FileType c map <F9> :w <CR> : !clear; tcc -run -g % <CR>
  53.  
  54.  
  55. " Print int main() to C file
  56. function! CIntma()
  57. call append(line('^'), [ '#include <stdio.h>'
  58. \                      , ''
  59. \                      , 'int main(int argc, char *argv[]) {'])
  60. call append(line('$'), [ '    printf("Hello World");'
  61. \                      , '    return 0;'
  62. \                      , '}'])
  63. endfunction
  64. " :Intma function in .c files
  65. au FileType c command Intma :call CIntma()
  66.  
  67.  
  68. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  69. " Plugins
  70. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  71. set nocompatible              " don't remember what it actually does
  72.  
  73. " set the runtime path to include Vundle and initialize
  74. set rtp+=~/.vim/bundle/Vundle.vim
  75. call vundle#begin()
  76.  
  77. " let Vundle manage Vundle, required
  78. Plugin 'gmarik/Vundle.vim'
  79. Plugin 'Valloric/YouCompleteMe'
  80. Plugin 'jiangmiao/auto-pairs'
  81. Plugin 'scrooloose/nerdtree'
  82. Plugin 'junegunn/fzf'
  83. Plugin 'tpope/vim-surround'
  84. Plugin 'junegunn/fzf.vim'
  85.  
  86. highlight Pmenu ctermfg=0 ctermbg=15 guifg=#ffffff guibg=#707880
  87.  
  88. " All of your Plugins must be added before the following line
  89. call vundle#end()            " required
  90. filetype plugin indent on    " required
  91.  
  92.  
  93. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  94. " Autocomplete
  95. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  96. let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py'
  97. let g:ycm_autoclose_preview_window_after_insertion = 1
  98.  
  99. " Syntastic
  100. let g:syntastic_c_checkers=['make']
  101. let g:syntastic_always_populate_loc_list = 1
  102. let g:syntastic_check_on_open=1
  103. let g:syntastic_enable_signs=1
  104. let g:syntastic_error_symbol = '✗'
  105. let g:syntastic_warning_symbol = '⚠'
  106.  
  107.  
  108. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  109. " Other shortcuts
  110. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  111. " Open NERDTree with Ctrl-n
  112. " TODO: auto reload tree
  113. " Nwerd tree can be reloaded with r key or while reload
  114. map <C-n> :NERDTreeToggle<CR>:NERDTreeRefreshRoot<CR>
  115. let NERDTreeIgnore=['\.o$', '\.out$', '\.pyc$', '\~$']
  116.  
  117. " split screen navigation
  118. nnoremap <C-J> <C-W><C-J>
  119. nnoremap <C-K> <C-W><C-K>
  120. nnoremap <C-L> <C-W><C-L>
  121. nnoremap <C-H> <C-W><C-H>
  122.  
  123. " Smart search
  124. " silversearcher-ag required
  125. map <F4> :Ag<CR>
  126.  
  127. " Disable bells
  128. set visualbell
  129. set t_vb=
  130.  
  131. " Copy from vim - ctrl+c
  132. " Paste to vim - ctrl+p
  133. " gvim required
  134. vnoremap <C-c> "*y :let @+=@*<CR>
  135. map <C-p> "+P
  136.  
  137. " Check spelling
  138. map <F6> :setlocal spell! spelllang=en_us<CR>
  139.  
  140.  
  141. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  142. " HTML leader combinations
  143. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  144. au FileType html map <leader>b o<b></b><Space><Esc>FbT>i
  145. au FileType html map <leader>1 o<h1></h1><Esc>02f<i
  146. au FileType html map <leader>2 o<h2></h2><Esc>02f<i
  147. au FileType html map <leader>3 o<h3></h3><Esc>02f<i
  148. au FileType html map <leader>4 o<h4></h4><Esc>02f<i
  149. au FileType html map <leader>5 o<h5></h5><Esc>02f<i
  150. au FileType html map <leader>6 o<h6></h6><Esc>02f<i
  151. au FileType html map <leader>p o<p></p><Esc>02f<i
  152. au FileType html map <leader>a o<a href=""><++></a><Esc>0f"a
  153. au FileType html map <leader>im o<img src="" alt="<++>"<++>><Esc>0f"a
  154. au FileType html map <leader>it o<i></i><Esc>0f>a
  155. au FileType html map <leader>sm o<small></small><Esc>0f>a
  156. au FileType html map <leader>ma o<mark></mark><Esc>0f>a
  157. au FileType html map <leader>q o<q></q><Space><Esc>02f<i
  158. au FileType html map <leader>/ o<!--  --><Space><Esc>0f a
  159. au FileType html map <leader>ul o<ul><Enter><li></li><Enter></ul><Esc>0k2f<i
  160. au FileType html map <leader>li o<li></li><Esc>F>a
  161. au FileType html map <leader>ol o<ol><Enter><li></li><Enter></ol><Esc>0k2f<i
  162.  
  163. inoremap <leader>c <Esc>/<++><Enter>"_c4l
  164. vnoremap <leader>c <Esc>/<++><Enter>"_c4l
  165. map      <leader>c <Esc>/<++><Enter>"_c4l
  166.  
  167. inoremap <leader>d <Esc>/<++><Enter>"_d4l
  168. vnoremap <leader>d <Esc>/<++><Enter>"_d4l
  169. map      <leader>d <Esc>/<++><Enter>"_d4l
  170.  
  171. " Print main to HTML file
  172. function! HTMLma()
  173. call append(line('^'), [ '<!DOCTYPE html>'
  174. \                      , '<html>'
  175. \                      , '<head>'
  176. \                      , '<title><++></title>'
  177. \                      , '</head>'
  178. \                      , '<body>'])
  179. call append(line('$'), [ '</body>'
  180. \                      , '</html>'])
  181. endfunction
  182. " :Intma function in .c files
  183. au FileType html command Intma :call HTMLma()
  184.  
  185. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  186. " nvim color scheme
  187. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  188. colorscheme darkblue
  189.  
  190.  
  191. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  192. " Status line
  193. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  194. set laststatus=2
  195.  
  196. function! GitBranch()
  197.   return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
  198. endfunction
  199.  
  200. function! StatuslineGit()
  201.   let l:branchname = GitBranch()
  202.   return strlen(l:branchname) > 0?'  '.l:branchname.' ':''
  203. endfunction
  204.  
  205. set statusline=
  206. " set statusline+=%#CursorColumn#
  207. " set statusline+=%1*  "switch to User1 highlight
  208. set statusline+=%#LineNr#
  209. set statusline+=\ %f
  210. set statusline+=%{StatuslineGit()}
  211. " set statusline+=%m\
  212. set statusline+=%=
  213. " set statusline+=\ %y
  214. set statusline+=%y
  215. set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
  216. set statusline+=\[%{&fileformat}\]
  217. set statusline+=\ %p%%
  218. set statusline+=\ %l:%c
  219. set statusline+=\
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement