vimrc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. " ================================================
  2. " INITIALIZATION
  3. " ================================================
  4. set nocompatible
  5. set nobackup
  6. set fileencoding=utf8 encoding=utf8
  7. set history=50 " keep 40 lines of command line history
  8. set autoindent " always set autoindenting on
  9. set incsearch " do incremental searching
  10. set autoread " auto read changed files
  11. set showcmd " display incomplete commands
  12. set number " turn on lines number
  13. set ruler " turn on status line on bottom right corner
  14. " set nofixendofline " turn off end of line on every file
  15. " set cursorline " highlight current line
  16. " set cursorcolumn " highlight current column
  17. " set ff=unix " set linebreak to return
  18. " set ffs=unix,dos
  19. set backspace=indent,eol,start
  20. set shiftwidth=4 tabstop=4 softtabstop=4 expandtab
  21. let mapleader = "," " map <leader> to for convenience
  22. autocmd FileType help wincmd L " open help window vertically on the right
  23. filetype plugin indent on
  24. if has("win32")
  25. source $VIMRUNTIME/mswin.vim
  26. nnoremap <F11> :call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0)<CR>
  27. inoremap <F11> <ESC>:call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0)<CR>a
  28. endif
  29. if has("win64")
  30. nnoremap <F11> :call libcallnr("gvimfullscreen_x64.dll", "ToggleFullScreen", 0)<CR>
  31. inoremap <F11> <ESC>:call libcallnr("gvimfullscreen_x64.dll", "ToggleFullScreen", 0)<CR>a
  32. endif
  33. if has("gui_running")
  34. set guioptions='' " remove all extra GUI components
  35. set mouse=a
  36. set lines=36 columns=128 " consistent window size
  37. winpos 200 160
  38. colorscheme solarized
  39. else
  40. color monokai
  41. endif
  42. " switch syntax highlighting on, when the terminal has colors
  43. " also switch on highlight the last used search pattern
  44. if &t_Co > 2 || has("gui_running")
  45. syntax on
  46. set hlsearch
  47. endif
  48. if has("autocmd")
  49. autocmd BufReadPost *
  50. \ if line("'\"") > 1 && line("'\"") <= line("$") |
  51. \ exe "normal! g`\"" |
  52. \ endif
  53. endif
  54. " ================================================
  55. " KEY BINDINGS
  56. " ================================================
  57. " for manipulating vimrc(valid when vimrc in $HOME dir)
  58. nnoremap <leader>ev :vsplit $MYVIMRC<CR>
  59. nmap <silent> <leader>sv :source $MYVIMRC<CR>
  60. " for managing tabs
  61. nmap <C-T> :tabnew<CR>
  62. imap <C-T> <ESC>:tabnew<CR>
  63. nmap <C-W> :tabclose<CR>
  64. imap <C-W> <ESC>:tabclose<CR>
  65. nmap <C-PageUp> :tabprevious<CR>
  66. imap <C-PageUp> <ESC>:tabprevious<CR>
  67. nmap <C-PageDown> :tabnext<CR>
  68. imap <C-PageDown> <ESC>:tabnext<CR>
  69. " toggle highlight search
  70. nmap <silent> <leader>th :set nohlsearch!<CR>
  71. " treat long lines as break lines
  72. nmap j gj
  73. nmap k gk
  74. " spell check
  75. nmap <silent> <leader>ts :setlocal spell!<CR>
  76. nmap <leader>sn ]s
  77. nmap <leader>sp [s
  78. nmap <leader>sa zg
  79. nmap <leader>ss z=
  80. " shortcuts for common tasks
  81. nmap <F1> :w<CR>
  82. imap <F1> <ESC>:w<CR>
  83. nmap <silent> <leader>q :q<CR>
  84. " simulate emacs in insert mode
  85. inoremap <C-F> <RIGHT>
  86. inoremap <C-B> <LEFT>
  87. inoremap <C-N> <DOWN>
  88. inoremap <C-P> <UP>
  89. inoremap <C-E> <END>
  90. inoremap <C-A> <HOME>
  91. " for jumping to specific window quickly
  92. noremap <C-J> <C-W>j
  93. noremap <C-K> <C-W>k
  94. noremap <C-L> <C-W>l
  95. noremap <C-H> <C-W>h
  96. " increase and decrease window size
  97. noremap <S-F8> <ESC>:vertical resize -2<CR>
  98. noremap <S-F9> <ESC>:vertical resize +2<CR>
  99. noremap <M-S-F8> <ESC>:resize -2<CR>
  100. noremap <M-S-F9> <ESC>:resize +2<CR>
  101. " ================================================
  102. " ABBREVIATIONS
  103. " ================================================
  104. iab xtime <C-R>=strftime("%Y-%m-%d %H:%M:%S")<CR>
  105. iab xdate <C-R>=strftime("%Y-%m-%d")<CR>
  106. " ================================================
  107. " PLUGINS
  108. " ================================================
  109. " pathogen
  110. execute pathogen#infect()
  111. " nerdtree
  112. let NERDTreeQuitOnOpen = 1
  113. nmap <silent> <F8> :NERDTreeToggle<CR>
  114. " tagbar
  115. nmap <silent> <F9> :TagbarToggle<CR>
  116. " lightline
  117. let g:lightline = {'colorscheme': 'solarized'}
  118. " vim-markdown
  119. au FileType md set filetype=mkd
  120. let g:vim_markdown_folding_disabled=2
  121. " calendar
  122. let g:calendar_monday = 1
  123. if has("win32")
  124. let g:calendar_diary = "D:/Backup/Calendar"
  125. else
  126. let g:calendar_diary = "~/.calendar"
  127. endif
  128. " colorizer
  129. nmap <leader>ch :ColorHighlight<CR>
  130. nmap <leader>cc :ColorClear<CR>
  131. let g:colorizer_auto_filetype='css,html,vue'
  132. " nerdcommenter
  133. let g:NERDSpaceDelims = 1 " Add spaces after comment delimiters by default
  134. " let g:NERDCompactSexyComs = 1 " Use compact syntax for prettified multi-line comments
  135. " let g:NERDDefaultAlign = 'left' " Align line-wise comment delimiters flush left instead of following code indentation
  136. " let g:NERDAltDelims_java = 1 " Set a language to use its alternate delimiters by default
  137. " let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } } " Add your own custom formats or override the defaults
  138. " let g:NERDCommentEmptyLines = 1 " Allow commenting and inverting empty lines (useful when commenting a region)
  139. let g:NERDTrimTrailingWhitespace = 1 " Enable trimming of trailing whitespace when uncommenting
  140. " vim-table-mode
  141. let g:table_mode_corner='|'
  142. nmap <silent> <leader>ttm :TableModeToggle<CR>
  143. " vim-gitgutter
  144. nmap <silent> <F10> :GitGutterToggle<CR>
  145. imap <silent> <F10> <ESC>:GitGutterToggle<CR>
  146. let g:gitgutter_enabled = 0
  147. let g:gitgutter_highlight_lines = 1
  148. let g:UltiSnipsExpandTrigger="<TAB>"
  149. let g:UltiSnipsJumpForwardTrigger="<TAB>"
  150. let g:UltiSnipsJumpBackwardTrigger="<S-TAB>"
  151. " git
  152. nmap <silent> <F4> :Gblame<CR>
  153. " switch tab width between 4(default) and 2
  154. fun! SetTabWidth()
  155. if &shiftwidth == 4
  156. let width = 2
  157. else
  158. let width = 4
  159. endif
  160. exe "set shiftwidth=" . width . " tabstop=" . width . " softtabstop=" . width . " expandtab"
  161. endfun
  162. " switch font between fixedsys and Consolas
  163. fun! SwitchFont()
  164. if &guifont == 'fixedsys'
  165. exec "set guifont=Consolas:h14:cANSI:qDRAFT"
  166. else
  167. exec "set guifont=fixedsys"
  168. endif
  169. endfun
  170. " toggle line/column highlight
  171. fun! SwitchCrossHighlight()
  172. if &cursorline == 0
  173. exec "set cursorline"
  174. exec "set cursorcolumn"
  175. else
  176. exec "set nocursorline"
  177. exec "set nocursorcolumn"
  178. endif
  179. endfunc
  180. nmap <silent> <F12> :call SetTabWidth()<CR>
  181. nmap <silent> <F10> :call SwitchFont()<CR>
  182. nmap <silent> <F5> :call SwitchCrossHighlight()<CR>
  183. " ================================================
  184. " FILE SPECIFIC CONFIGURATION
  185. " ================================================
  186. " autocmd FileType vue syntax sync fromstart " vue
  187. " let g:html_indent_inctags = "html,head,body" " html
  188. nmap <F2> :silent ! compass compile % <CR><CR>