From 0675055e493e4afe71a7e187cbfa2943fbbdc5f3 Mon Sep 17 00:00:00 2001 From: Xamora Date: Thu, 18 Jan 2024 09:54:11 +0100 Subject: [PATCH] My nvim is goated; Add console with keybinding Ctrl+Shift+Q --- init.vim | 78 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 16 deletions(-) diff --git a/init.vim b/init.vim index 989e759..0e1eee5 100644 --- a/init.vim +++ b/init.vim @@ -36,25 +36,71 @@ Plug 'norcalli/nvim-colorizer.lua' "Color Hexadecimal call plug#end() +" If there are only terminal and NerdTree, all close + autocmd bufenter * if (winnr("$") == 2 && IsNerdTreeEnabled() && g:terminal_id != -1) | qa | endif + +" Terminal + function! ToggleTerminal() + if (g:terminal_id == -1) + below split | resize 10 | term + let g:terminal_id = win_getid() + else + call win_gotoid(g:terminal_id) + let g:terminal_id = -1 + close + endif + endfunction + + let g:terminal_id = -1 + nnoremap :call ToggleTerminal() + nnoremap :echo win_getid() + " NerdTree -" Start NERDTree and put the cursor back in the other window. -autocmd VimEnter * NERDTree | wincmd p -" Exit Vim if NERDTree is the only window remaining in the only tab. -autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif +" + " Size + let g:NERDTreeDefaultSize = 20 + let g:NERDTreeWinSize=g:NERDTreeDefaultSize + " Start NERDTree and put the cursor back in the other window. + autocmd VimEnter * NERDTree | wincmd p -" Focus and unfocus -function! ToggleNERDTree() - if exists("g:NERDTree") && g:NERDTree.IsOpen() && bufname('%') =~ 'NERD_tree_' - wincmd p - else - NERDTreeFocus - endif -endfunction + function! IsNerdTreeEnabled() + return exists('t:NERDTreeBufName') && bufwinnr(t:NERDTreeBufName) != -1 + endfunction -nnoremap :call ToggleNERDTree() -nnoremap :NERDTreeToggle -nnoremap :NERDTreeFind -" Unfocus on the file open + " Add + function! AddNERDTreeSize(add) + call SetNERDTreeSize(g:NERDTreeWinSize + a:add) + endfunction + + " Set + function! SetNERDTreeSize(value) + if exists("g:NERDTree") && g:NERDTree.IsOpen() + execute 'let g:NERDTreeWinSize = ' . (a:value) + execute 'NERDTree' + wincmd p + execute 'NERDTreeFind' + endif + endfunction + + " Focus and unfocus + function! ToggleNERDTree() + if exists("g:NERDTree") && g:NERDTree.IsOpen() && bufname('%') =~ 'NERD_tree_' + wincmd p + else + NERDTreeFocus + endif + endfunction + + " Unfocus on the file open + nnoremap :call ToggleNERDTree() + nnoremap :NERDTreeToggle + nnoremap :NERDTreeFind + + " Resize NERDTree + nnoremap :call AddNERDTreeSize(2) + nnoremap :call AddNERDTreeSize(-2) + nnoremap :call SetNERDTreeSize(g:NERDTreeDefaultSize) + nnoremap :call SetNERDTreeSize(g:NERDTreeDefaultSize) " nnoremap :TagbarToggle