Advertisement
DimaT1

init.vim

Apr 9th, 2019
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 4.32 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.  
  9. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  10. " Text, tab and indent related
  11. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  12. " Use spaces instead of tabs
  13. set expandtab
  14.  
  15. " Smart tabs
  16. set smarttab
  17.  
  18. " 1 tab == 4 spaces
  19. set shiftwidth=4
  20. set tabstop=4
  21.  
  22. " Linebreak on 500 characters
  23. set lbr
  24. set tw=500
  25.  
  26. set ai " Auto indent
  27. set si " Smart indent
  28. set wrap " Wrap lines
  29.  
  30.  
  31. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  32. " Autocompile, file format
  33. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  34. " Run golang file
  35. au FileType go map <F8> :w <CR> : !clear; go run % <CR>
  36.  
  37. " Auto pep8 for python (autopep8 is required)
  38. au FileType python map <F7> :w <CR> : !clear; autopep8 --in-place % <CR> :e <CR>
  39. " Run python3 file
  40. au FileType python map <F8> :w <CR> : !clear; python3 % <CR>
  41.  
  42. " Auto format C/C++ file (clang-format is required)
  43. au FileType c,cpp,objc map <F7> :w <CR> : !clear; clang-format % >> temp.cpp; mv temp.cpp % <CR> :e <CR>
  44. " Build & run C++ file with g++ -std=c++11
  45. au FileType cpp map <F8> :w <CR> : !clear; ~/Projects/cpp/build_n_run_cpp11.sh % <CR>
  46.  
  47. " Build & run C file with gcc -std=c99
  48. au FileType c map <F8> :w <CR> : !clear; ~/Projects/cpp/build_n_run_c99.sh % <CR>
  49. " Build & run C file with tcc
  50. au FileType c map <F9> :w <CR> : !clear; tcc -run -g % <CR>
  51.  
  52.  
  53. " Print int main() to C file
  54. function! CIntma()
  55. call append(line('^'), [ '#include <stdio.h>'
  56. \                      , ''
  57. \                      , 'int main(int argc, char *argv[]) {'])
  58. call append(line('$'), [ '    printf("Hello World");'
  59. \                      , '    return 0;'
  60. \                      , '}'])
  61. endfunction
  62. " :Intma function in .c files
  63. au FileType c command Intma :call CIntma()
  64.  
  65.  
  66. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  67. " Plugins
  68. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  69. set nocompatible              " don't remember what it actually does
  70.  
  71. " set the runtime path to include Vundle and initialize
  72. set rtp+=~/.vim/bundle/Vundle.vim
  73. call vundle#begin()
  74.  
  75. " let Vundle manage Vundle, required
  76. Plugin 'gmarik/Vundle.vim'
  77. Plugin 'Valloric/YouCompleteMe'
  78. Plugin 'jiangmiao/auto-pairs'
  79. Plugin 'scrooloose/nerdtree'
  80. Plugin 'junegunn/fzf'
  81. Plugin 'junegunn/fzf.vim'
  82.  
  83. highlight Pmenu ctermfg=0 ctermbg=15 guifg=#ffffff guibg=#707880
  84.  
  85. " All of your Plugins must be added before the following line
  86. call vundle#end()            " required
  87. filetype plugin indent on    " required
  88.  
  89.  
  90. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  91. " Other shortcuts
  92. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  93. " Open NERDTree with Ctrl-n
  94. " TODO: auto reload tree
  95. map <C-n> :NERDTreeToggle<CR>
  96.  
  97. " split screen navigation
  98. nnoremap <C-J> <C-W><C-J>
  99. nnoremap <C-K> <C-W><C-K>
  100. nnoremap <C-L> <C-W><C-L>
  101. nnoremap <C-H> <C-W><C-H>
  102.  
  103. " Smart search
  104. " silversearcher-ag required
  105. map <F4> :Ag<CR>
  106.  
  107. " Disable bells
  108. set visualbell
  109. set t_vb=
  110.  
  111. " Copy from vim - ctrl+c
  112. " Paste to vim - ctrl+p
  113. " gvim required
  114. vnoremap <C-c> "*y :let @+=@*<CR>
  115. map <C-p> "+P
  116.  
  117. " Check spelling
  118. map <F6> :setlocal spell! spelllang=en_us<CR>
  119.  
  120.  
  121. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  122. " nvim color scheme
  123. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  124. colorscheme darkblue
  125.  
  126.  
  127. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  128. " Status line
  129. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  130. set laststatus=2
  131.  
  132. function! GitBranch()
  133.   return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
  134. endfunction
  135.  
  136. function! StatuslineGit()
  137.   let l:branchname = GitBranch()
  138.   return strlen(l:branchname) > 0?'  '.l:branchname.' ':''
  139. endfunction
  140.  
  141. set statusline=
  142. " set statusline+=%#CursorColumn#
  143. " set statusline+=%1*  "switch to User1 highlight
  144. set statusline+=%#LineNr#
  145. set statusline+=\ %f
  146. set statusline+=%{StatuslineGit()}
  147. " set statusline+=%m\
  148. set statusline+=%=
  149. " set statusline+=\ %y
  150. set statusline+=%y
  151. set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
  152. set statusline+=\[%{&fileformat}\]
  153. set statusline+=\ %p%%
  154. set statusline+=\ %l:%c
  155. set statusline+=\
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement