From 41cc0c57cde2517f774c05147e2d5bcc9813f724 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 12 Jan 2023 11:24:35 +0100 Subject: [nvim] overhaul config and plugins --- .config/nvim/init.vim | 97 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 91 insertions(+), 6 deletions(-) (limited to '.config') diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index 43fb173..de616e9 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -6,8 +6,10 @@ call plug#begin(stdpath('data') . '/plugged') Plug 'doums/darcula' -Plug 'preservim/nerdtree' Plug 'ryanoasis/vim-devicons' +Plug 'nvim-tree/nvim-web-devicons' + +Plug 'preservim/nerdtree' Plug 'Xuyuanp/nerdtree-git-plugin' Plug 'nvim-lua/plenary.nvim' @@ -23,11 +25,16 @@ Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} Plug 'lukas-reineke/indent-blankline.nvim' +Plug 'tpope/vim-surround' + Plug 'gpanders/editorconfig.nvim' Plug 'iamcco/markdown-preview.nvim', {'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']} " if install fails do `:call mkdp#util#install() manually` +Plug 'stevearc/aerial.nvim' +Plug 'numToStr/Comment.nvim' + Plug 'williamboman/mason.nvim' Plug 'williamboman/mason-lspconfig.nvim' Plug 'neovim/nvim-lspconfig' @@ -72,6 +79,23 @@ colorscheme darcula set termguicolors hi Normal guibg=NONE ctermbg=NONE +if &diff + autocmd BufEnter * if winnr('$') == 1 | quit | endif +endif + +" pdf +autocmd BufEnter *.pdf split | exe expandcmd("terminal firefox :p") | quit + +function! s:winfiletypes() + let winfiletypes = [] + for window_nr in range(1, winnr('$')) + let filetype = getbufvar(winbufnr(window_nr), '&filetype') + call add(winfiletypes, filetype) + endfor + + return winfiletypes +endfunction + " Nerdtree @@ -87,11 +111,32 @@ endif autocmd BufWinEnter * if getcmdwintype() == '' | silent NERDTreeMirror | endif autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif +" set status line on tab switch +let g:NERDTreeStatusLineTabSwitchFiletypes = ["nerdtree", "help"] +function NERDTreeStatusLineTabSwitch() + let tab_nr = tabpagenr() + let buffer_list = tabpagebuflist(tab_nr) + + " default to 2 + let meaningful_window_nr = 2 + + for buffer_nr in buffer_list + let buffer_type = getbufvar(buffer_nr, "&filetype") + if index(g:NERDTreeStatusLineTabSwitchFiletypes, buffer_type) == -1 + let meaningful_window_nr = bufwinnr(buffer_nr) + break + endif + endfor + + exe meaningful_window_nr .. "wincmd w" +endfunction +autocmd TabLeave * call NERDTreeStatusLineTabSwitch() + map NERDTreeToggle " Telescope - + nnoremap ff Telescope find_files nnoremap fg Telescope live_grep nnoremap Telescope buffers @@ -106,7 +151,7 @@ nnoremap gu GitGutterUndoHunk " Leap lua <a AerialToggle! +nnoremap fa Telescope aerial + +" add aerial to tab switch filetypes +call add(g:NERDTreeStatusLineTabSwitchFiletypes, 'aerial') + +" close Aerial and NERDTree if they are the only remaining windows +function AerialNERDTreeClose() + if winnr('$') != 2 + return + endif + + let window_filetypes = s:winfiletypes() + + if index(window_filetypes, 'aerial') != -1 && index(window_filetypes, 'nerdtree') != -1 + " one quit suffices, since aerial and nerdtree close themselves + quit + endif +endfunction +autocmd BufEnter * call AerialNERDTreeClose() + + +" Comment + +lua <