text.vim 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. " Copyright 2024 Henrique Paone
  2. "
  3. " This file is part of Vim-Markup.
  4. "
  5. " Vim-Markup is free software: you can redistribute it and/or modify it under the
  6. " terms of the GNU General Public License as published by the Free Software
  7. " Foundation, either version 3 of the License, or (at your option) any later
  8. " version.
  9. "
  10. " Vim-Markup is distributed in the hope that it will be useful, but WITHOUT ANY
  11. " WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  12. " PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. "
  14. " You should have received a copy of the GNU General Public License along with
  15. " Vim-Markup. If not, see <https://www.gnu.org/licenses/>.
  16. "------------------------------------------------------------------------------
  17. " Configuration
  18. "------------------------------------------------------------------------------
  19. " Folding
  20. set foldmethod=indent
  21. " Uses spaces instead of tabs
  22. set expandtab tabstop=2 shiftwidth=2
  23. " No autoclosing on '
  24. inoremap ' '
  25. " Formating options
  26. set fo+=t " Automatic formatting of text
  27. set fo+=n " Recognize numbered lists
  28. "-----------------------------------------------------------------------------
  29. " Toggle automatic formatting
  30. set fo-=a
  31. nnoremap <leader>f :call ToggleAutoFormat()<cr>
  32. fu! ToggleAutoFormat()
  33. if stridx(&fo, 'a') == -1
  34. set fo+=a
  35. else
  36. set fo-=a
  37. endif
  38. endf
  39. "-----------------------------------------------------------------------------
  40. " Make formatting work properly with bullet icon
  41. let &formatlistpat='^\s*\(\d\+[\]:.)}\t ]\|[•][\t ]\)\s*'
  42. "------------------------------------------------------------------------------
  43. "Special characters
  44. "------------------------------------------------------------------------------
  45. inoremap \Ep Σ
  46. inoremap \ep ε
  47. inoremap \Ee ∈
  48. inoremap \ee ϵ
  49. inoremap \delta ∆
  50. inoremap \fore ⸫
  51. inoremap \-> →
  52. inoremap \/> ↙
  53. inoremap \\> ↘
  54. inoremap \|> ↓
  55. inoremap \=> ⇒
  56. inoremap \. •<Space>
  57. inoremap \par ¶
  58. inoremap \sec §
  59. inoremap \_1 ₁
  60. inoremap \_2 ₂
  61. inoremap \^1 ¹
  62. "------------------------------------------------------------------------------
  63. " Syntax for text files
  64. "------------------------------------------------------------------------------
  65. syn match myTodo /^.*TODO:.*/
  66. hi myTodo cterm=bold ctermbg=red ctermfg=white
  67. "------------------------------------------------------------------------------
  68. " Poor man's markup
  69. "------------------------------------------------------------------------------
  70. " Only show hidden markup in insert mode
  71. setlocal conceallevel=2
  72. setlocal concealcursor=nvc
  73. " Bold
  74. syn region boldText matchgroup=boldDelim start=/\*/ end=/\*/ concealends
  75. hi boldText cterm=bold
  76. syn match escapedAsterisk /\\\*/ conceal cchar=*
  77. " Italic
  78. syn region italicText matchgroup=italicDelim start=/\// end=/\// concealends
  79. hi italicText cterm=italic
  80. syn match escapedItalic /\\\// conceal cchar=/
  81. " Underline
  82. syn region underlineText matchgroup=underlineDelim start=/_/ end=/_/ concealends
  83. hi underlineText cterm=underline
  84. syn match underlineText /\\_/ conceal cchar=_
  85. " Autoclosing markup symbols
  86. inoremap * **<left>
  87. inoremap / //<left>
  88. inoremap _ __<left>
  89. " Toggle showing concealed markup
  90. let g:conceal_on=1
  91. nnoremap <leader>m :call ToggleConceal()<cr>
  92. fu! ToggleConceal()
  93. if g:conceal_on
  94. set conceallevel=0
  95. let g:conceal_on=0
  96. else
  97. set conceallevel=2
  98. let g:conceal_on=1
  99. endif
  100. endf
  101. " Horizontal lines
  102. inoremap \hl <esc>:call FillLine('─')<cr>i
  103. inoremap \dl <esc>:call FillLine('-')<cr>i
  104. " Fills text width with passed char
  105. fu! FillLine(char)
  106. for i in range(0, &textwidth - 1)
  107. execute 'norm!i' .. a:char
  108. endfor
  109. endf