aboutsummaryrefslogtreecommitdiff
path: root/vim.dot.link/plugin/nerdtree_workarounds.vim
blob: d0d682e9fc191d5f9e963f72af2b41c1bb25ab81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
" nedtree_workaroungs.vim - NERDTree and session restoration workarounds
"
" Author: Silvio Rhatto <rhatto@riseup.net>
"

" Ensure the window has maximized height
"
" This helps restoring the window size after reopening sessions after
" switching monitors (like from laptop screen to external HDMI monitor).
"
" https://superuser.com/questions/140419/how-to-start-gvim-maximized
" https://vim.fandom.com/wiki/Maximize_or_set_initial_window_size
set lines=999

" Fix NERDTree width
"
" Useful after restoring sessions between screen size changes (such
" as when you share sessions between different computers).
function FixNERDTreeWidth()
  " Make sure NERDTree is focuses
  execute ":NERDTreeFocus"

  " Set a fixed width
  execute ":vertical resize 30"

  " Move to the left pane
  wincmd l
endfunction

" In case you want to invoke FixNERDTreeWidth explicitly
command! -bang FixNERDTreeWidth :call FixNERDTreeWidth()

" Fix NERDTree width on all tabs
function FixAllNERDTreeWidths()
  " Save the last active window
  let l:current_win = win_getid()

  tabdo :call FixNERDTreeWidth()

  " Restore the active window
  call win_gotoid(l:current_win)

  " An additional, last move to the left pane
  wincmd l
endfunction

" Fix all NERDTree widths afert session load
augroup workaround
  autocmd!
  " This tends to fire for every buffers
  "autocmd workaround SessionLoadPost * call FixAllNERDTreeWidths()

  " This seems to fire only once
  autocmd workaround VimEnter * call FixAllNERDTreeWidths()
augroup END