immersive.vim 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. " Copyright 2024 Henrique Paone
  2. "
  3. " This file is part of Vim-Immersive.
  4. "
  5. " Vim-Immersive 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-Immersive 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-Immersive. If not, see <https://www.gnu.org/licenses/>.
  16. vim9script
  17. # Immersive mode function
  18. export def Immersive()
  19. # Check if writer mode is on, by fetching the bacground color of the
  20. # separator (15 = white) and, if it's on, turns it off
  21. if matchstr(execute('hi VertSplit'), 'ctermfg=\zs\d\d') == '15'
  22. hi VertSplit ctermfg=black
  23. hi NonText ctermfg=lightblue
  24. set laststatus=1
  25. set rnu
  26. only
  27. return
  28. endif
  29. # Formating
  30. hi VertSplit ctermfg=white # Hides split separtor
  31. hi NonText ctermfg=white # Hides blank line character
  32. set laststatus=0 # Hides status line
  33. set nornu # Turn off relative numbers
  34. var Resize_window = (new: number) => {
  35. var curr = winwidth(0)
  36. var op = (curr < new) ? '>' : '<'
  37. feedkeys(abs(new - curr) .. "\<C-w>" .. op, 'x')
  38. }
  39. # Make two read-only buffers to act as margins
  40. const margin_size = (winwidth(0) - &tw) / 2
  41. var mod = (margin_size % 2 == 0) ? 0 : 1
  42. vnew | set nomodifiable | vnew | set nomodifiable
  43. Resize_window(margin_size)
  44. wincmd l
  45. Resize_window(margin_size + mod - 2)
  46. wincmd l
  47. wincmd R
  48. enddef