init.vim 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. " This is the font.
  2. set guifont=Consolas:h11
  3. " This is the best gvim color scheme.
  4. colorscheme evening
  5. " Beautiful syntax highlighting
  6. syntax on
  7. " Show number
  8. set number
  9. " Map leader
  10. let mapleader = ","
  11. " No backup stuff
  12. set noswapfile
  13. set nobackup
  14. " Use mouse wisely :)
  15. set mouse=a
  16. " Netrw
  17. let g:netrw_banner = 0
  18. let g:netrw_liststyle = 3
  19. let g:netrw_winsize = 30
  20. " Toggle Vexplore with Ctrl-E
  21. function! ToggleVExplorer()
  22. if exists("t:expl_buf_num")
  23. let expl_win_num = bufwinnr(t:expl_buf_num)
  24. if expl_win_num != -1
  25. let cur_win_nr = winnr()
  26. exec expl_win_num . 'wincmd w'
  27. close
  28. exec cur_win_nr . 'wincmd w'
  29. unlet t:expl_buf_num
  30. else
  31. unlet t:expl_buf_num
  32. endif
  33. else
  34. exec '1wincmd w'
  35. Vexplore
  36. let t:expl_buf_num = bufnr("%")
  37. endif
  38. endfunction
  39. map <silent> <C-E> :call ToggleVExplorer()<CR>
  40. " Flold stuff
  41. set viewoptions-=options
  42. augroup remember_folds
  43. autocmd!
  44. autocmd BufWinLeave *.* if &ft !=# 'help' | mkview | endif
  45. autocmd BufWinEnter *.* if &ft !=# 'help' | silent! loadview | endif
  46. augroup END
  47. set foldmethod=manual
  48. highlight folded guibg=darkgrey
  49. highlight folded guifg=yellow
  50. " Searching but better
  51. " Ignore case when searching
  52. set ignorecase
  53. " When searching try to be smart about cases
  54. set smartcase
  55. " Highlight search results
  56. set nohlsearch
  57. " Makes search act like search in modern browsers
  58. set incsearch
  59. " set cursorline
  60. " Gives me vertical and horizontal highlights of text.
  61. " Vertical highlight line
  62. set cursorline
  63. " Horizontal highlight line
  64. set cursorcolumn
  65. " Colors for both lines.
  66. highlight CursorLine ctermbg=Yellow cterm=bold guibg=#3b3b3b
  67. highlight CursorColumn ctermbg=Yellow cterm=bold guibg=#3b3b3b
  68. " Spell checker
  69. map <leader>s :setlocal spell! spelllang=en_us<CR>
  70. " Fix what the spell checker finds
  71. noremap <silent> <leader>fix mc1z=`c
  72. " Do space space to jump to <++>
  73. noremap <Space><Space> /<++><Enter>"_c4l
  74. " Replace stuff shortcut
  75. nnoremap S :%s##g<Left><Left>
  76. " Copy paste
  77. set nopaste
  78. set clipboard=unnamed
  79. " Show text in middle
  80. " set sidescrolloff=999
  81. " set scrolloff=999
  82. " NO BEEP
  83. " Could cause problems when use the alt key.
  84. set noerrorbells visualbell t_vb=
  85. autocmd GUIEnter * set visualbell t_vb=
  86. " Wildmenu
  87. set wildmenu
  88. set wildmode=longest,list,full
  89. " Auto remove spaces on save
  90. function! <SID>StripTrailingWhitespaces()
  91. if !&binary && &filetype != 'diff'
  92. let l:save = winsaveview()
  93. keeppatterns %s/\s\+$//e
  94. call winrestview(l:save)
  95. endif
  96. endfun
  97. autocmd BufWritePre,FileWritePre,FileAppendPre,FilterWritePre *
  98. \ :call <SID>StripTrailingWhitespaces()
  99. " Terminal commands for nvim
  100. if has('nvim')
  101. augroup vimrc_term
  102. autocmd!
  103. autocmd WinEnter term://* nohlsearch
  104. autocmd WinEnter term://* startinsert
  105. autocmd TermOpen * tnoremap <buffer> <C-w><C-h> <C-\><C-n><C-w>h
  106. autocmd TermOpen * tnoremap <buffer> <C-w><C-j> <C-\><C-n><C-w>j
  107. autocmd TermOpen * tnoremap <buffer> <C-w><C-k> <C-\><C-n><C-w>k
  108. autocmd TermOpen * tnoremap <buffer> <C-w><C-l> <C-\><C-n><C-w>l
  109. autocmd TermOpen * tnoremap <buffer> <Esc> <C-\><C-n>
  110. autocmd TermOpen * set nonumber
  111. augroup END
  112. endif
  113. " Tab stuffs
  114. set expandtab
  115. set smarttab
  116. set shiftwidth=4
  117. set tabstop=4
  118. set smartindent
  119. set backspace=indent,eol,start
  120. " Status line
  121. " Give some space before the line starts
  122. set laststatus=2
  123. " Actually start the status line parameters
  124. set statusline=
  125. " Show the file name
  126. set statusline+=\ FILE:
  127. set statusline+=\ %F
  128. " Show both the current line number and the total lines in file
  129. set statusline+=\ LINES:
  130. set statusline+=\ %l
  131. set statusline+=\ %L
  132. " Go to the right side of the status line
  133. set statusline+=%=
  134. " Show the progress percentage of where you are in the document
  135. set statusline+=%p
  136. " Open url
  137. if (has('win32') || has('win64'))
  138. nmap <F4> :exec "!start <cWORD>"<cr><cr>
  139. else
  140. nmap <F4> :exec "!open <cWORD>"<cr><cr>
  141. endif
  142. " LATEX AUTO
  143. " Makes more latex stuff work with autocmd.
  144. let g:tex_flavor ='tex'
  145. " Insert a section
  146. autocmd FileType tex inoremap ;sec \section{}<Enter><++><Enter><Esc>2kf}i
  147. " Insert a begin
  148. autocmd FileType tex inoremap ;beg \begin{DELRN}<Enter><++><Enter>\end{DELRN}<Esc>--www<Esc>:%s#DELRN##<Left>
  149. " Insert a Frame
  150. autocmd FileType tex inoremap ;fr \section{DELRN}<Enter>\begin{frame}<Enter>\frametitle{DELRN}<Enter><++><Enter>\end{frame}<Esc>
  151. " Markdown compile to PDF
  152. autocmd FileType markdown nmap <F9> :!C:\SGZ_Pro\Hobbys\Writing\Markdown\pandoc.exe -s -o %:r.pdf % <CR><CR>:!start %:r.pdf<CR><CR>
  153. " Markdown compile to HTML
  154. autocmd FileType markdown nmap <F8> :!C:\SGZ_Pro\Hobbys\Writing\Markdown\pandoc.exe -s -o %:r.html % <CR><CR>:!start %:r.html<CR><CR>
  155. " I use vim BRO! This just gives me all my recent files.
  156. command! Bro :enew | setl buftype=nofile | 0put =v:oldfiles
  157. \| nnoremap <buffer> <CR> gf | 1
  158. " Kind of a plugin I source another file to have snake game
  159. source ~\Appdata\Local\nvim/snake.vim
  160. source ~\Appdata\Local\nvim/startext.vim
  161. source ~\Appdata\Local\nvim/toc.vim