Advertisement
yungplayz

My .vimrc

Dec 16th, 2018
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. "Personal preferences
  2. set nu
  3. syntax on
  4. set statusline+=File:\ %F
  5. set colorcolumn=81
  6. hi ColorColumn ctermbg=blue guibg=blue
  7. nmap <Space> <PageDown>
  8.  
  9. "C code indent
  10. set cindent
  11.  
  12. "Autoclose parenthesis
  13. inoremap ( ()<Esc>i
  14. inoremap [ []<Esc>i
  15. inoremap " ""<Esc>i
  16. inoremap < <><Esc>i
  17. inoremap { {<Tab><Return><BS>}<Esc>ko
  18.  
  19. "Display the cursor column
  20. set statusline+=,\ Col:\ %c
  21.  
  22. "Highlighting
  23. highlight ExtraSpaces ctermbg=red guibg=red
  24. match ExtraSpaces "\ \{2,}"
  25. autocmd BufWinEnter * syn match WSend excludenl /\s\+$/
  26. autocmd InsertEnter * syn match WSend excludenl /\s\+\%#\@!$/
  27. autocmd InsertLeave * syn match WSend excludenl /\s\+$/
  28. highlight WSend ctermbg=red guibg=red
  29.  
  30. "Backups
  31. silent !mkdir -p ~/.vim/.backup
  32. set backup
  33. set backupdir=~/.vim/.backup//
  34.  
  35. "Header
  36. imap <C-c><C-h>:call PutHeader()<CR>
  37. "autocmd BufWritePre *.c :call Update()
  38. autocmd BufWritePre *.c :call UpdateIfChanged()
  39. "autocmd BufNewFile *.c :call PutHeader()
  40.  
  41. function! Update()
  42. if &modified
  43. return 0
  44. endif
  45. let date = strftime('%Y/%m/%d')
  46. let hour = strftime('%H:%M:%S')
  47. let updated = "/* Updated: " . date . " " . hour . " by " . $USER
  48. let i = 17 - strwidth($USER)
  49. while i > 0
  50. let updated = updated . " "
  51. let i = i - 1
  52. endwhile
  53. let updated = updated . "### ########.fr */"
  54. call setline(9, updated)
  55. endfunction
  56.  
  57. function! UpdateIfChanged()
  58. if exists(v:fcs_reason)
  59. if (v:fcs_reason == 'changed')
  60. call Update()
  61. endif
  62. endif
  63. endfunction
  64.  
  65. function! GenerateHeader()
  66. let filename = expand('%:t')
  67. let author = ($USER) . " <"
  68. if exists($MAIL)
  69. author = author . ($MAIL)
  70. else
  71. author = author . "marvin@42.fr"
  72. endif
  73. author = author . ">"
  74. let created =
  75. let distance_8 = 55 - 37 - strwidth($USER)
  76. let h1 = "/* ************************************************************************** */"
  77. let h2 = "/* */"
  78. let h3 = "/* ::: :::::::: */"
  79. let h4 = "/* " . filename
  80. let i = 51 - strwidth(filename)
  81. while i > 0
  82. h4 = h4 . " "
  83. i = i - 1
  84. endwhile
  85. h4 = h4 . ":+: :+: :+: */"
  86. let h5 = "/* +:+ +:+ +:+ */"
  87. let h6 = "/* By: " . author
  88. i = 43 - strwidth(author)
  89. while i > 0
  90. h6 = h6 . " "
  91. i = i - 1
  92. endwhile
  93. h6 = h6 . "+#+ +:+ +#+ */"
  94. let h7 = "/* +#+#+#+#+#+ +#+ */"
  95. let date = strftime('%Y/%m/%d')
  96. let hour = strftime('%H:%M:%S')
  97. let created = date . " " . hour
  98. let h8 = "/* Created: " . created . " by " . ($USER)
  99. i = distance_8
  100. while i > 0
  101. h8 = h8 . " "
  102. i = i - 1
  103. endwhile
  104. h8 = h8 . "#+# #+# */"
  105. i = distance_8 - 1
  106. let h9 = "/* Updated: " . created . " by " . ($USER)
  107. while i > 0
  108. h8 = h8 . " "
  109. i = i - 1
  110. endwhile
  111. h9 = h9 . "### ########.fr */""
  112. call Udpate()
  113. let h10 = "/* */"
  114. let h11 = "/* ************************************************************************** */"
  115. let headerlist = [h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11]
  116. return (headerlist)
  117. endfunction
  118.  
  119. function Strcmp(str1, str2)
  120. if a:str1 < a:str2
  121. return -1
  122. elseif a:str1 ==# a:str2
  123. return 0
  124. else
  125. return 1
  126. endif
  127. endfunction
  128.  
  129. function PutHeader()
  130. let newheader = GenerateHeader()
  131. let h1 = get(newheader, 0, 'Cannot read line 1')
  132. let h2 = get(newheader, 1, 'Cannot read line 2')
  133. let h3 = get(newheader, 2, 'Cannot read line 3')
  134. let h4 = get(newheader, 3, 'Cannot read line 4')
  135. let h5 = get(newheader, 4, 'Cannot read line 5')
  136. let h6 = get(newheader, 5, 'Cannot read line 6')
  137. let h7 = get(newheader, 6, 'Cannot read line 7')
  138. let h8 = get(newheader, 7, 'Cannot read line 8')
  139. let h9 = get(newheader, 8, 'Cannot read line 9')
  140. let h10 = get(newheader, 9, 'Cannot read line 10')
  141. let h11 = get(newheader, 10, 'Cannot read line 11')
  142. let oh1 = getline(1)
  143. let oh2 = getline(2)
  144. let oh3 = getline(3)
  145. let oh4 = getline(4)
  146. let oh5 = getline(5)
  147. let oh6 = getline(6)
  148. let oh7 = getline(7)
  149. let oh8 = getline(8)
  150. let oh9 = getline(9)
  151. let oh10 = getline(10)
  152. let oh11 = getline(11)
  153. if ((Strcmp(h1, oh1) == 0) && (Strcmp(h2, oh2) == 0) && (Strcmp(h3, oh3) == 0)
  154. \ && (Strcmp(h4, oh4) == 0) && (Strcmp(h5, oh5) == 0) && (Strcmp(h6, oh6) == 0)
  155. \ && (Strcmp(h7, oh7) == 0) && (Strcmp(h10, oh10) == 0) && (Strcmp(h11, oh11) == 0))
  156. return 0
  157. endif
  158. call append(0, h1)
  159. call append(1, h2)
  160. call append(2, h3)
  161. call append(3, h4)
  162. call append(4, h5)
  163. call append(5, h6)
  164. call append(6, h7)
  165. call append(7, h8)
  166. call append(8, h9)
  167. call append(9, h10)
  168. call append(10, h11)
  169. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement