Last active
December 13, 2021 16:11
-
-
Save aljanabim/6f7e1d212b1947ae62e22799ef707e4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " TO DOWNLOAD curl https://gist.github.com/aljanabim/6f7e1d212b1947ae62e22799ef707e4e/raw > .vimrc | |
| " Upgrade vim | |
| " 1. sudo add-apt-repository ppa:jonathonf/vim | |
| " 2. sudo apt update | |
| " 3. sudo apt install vim | |
| :syntax on | |
| " ------- | |
| " SETTING | |
| " ------- | |
| :set hlsearch " highlight all mathcing phrases | |
| :set incsearch " show partial matches for search phrases | |
| :set ic " enable ignore casing when searching | |
| :set nowrap " disable text wrapping | |
| :set nocp " disable compatible mode for auto-completion | |
| :set number " show line numbers | |
| :set relativenumber " enable relativeline number | |
| :set noswapfile " disable the swapfile | |
| :set novisualbell " no colorful flashing on error | |
| :set noerrorbells " disable bells and flashing on errors | |
| :set mouse=a " enable mouse for all modes :map <LeftMouse> <nop> incase clicks cause messups | |
| :set tabstop=4 " size of tabs is 4 | |
| :set softtabstop=4 " fix <BACKSPACE> on tabbed spaces | |
| :set shiftwidth=4 | |
| :set autoindent " enable auto indentation | |
| :set smartindent " enable language-aware indenting | |
| :set expandtab " replace tab with whitespaces | |
| :set splitright splitbelow " make sure new splits are below and to the right | |
| :set nocompatible " needed for vim-polyglot | |
| :set hid " make buffer hidden instead of deleted once off focus | |
| :set scrolloff=8 " keep 8 lines below and above the cursor | |
| " Set the vertical split character to a space (there is a single space after '\ ') | |
| :set fillchars+=vert:\ | |
| :set termwinsize=8x0 " set terminal size to take N rows and all columns (if Nx0). | |
| :set t_TI= t_TE= " disable modifyOtherKeys. Fixes wierd characters for vim-fugitive solution found at https://vi.stackexchange.com/questions/27399/whats-t-te-and-t-ti-added-by-vim-8 | |
| :set autowrite " for vim-go to make sure it auto highlights errors on GoRun and Gobuild etc" | |
| " Fix ITEM highlighting issue | |
| if exists('$TMUX') | |
| let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\" | |
| let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\" | |
| else | |
| let &t_SI = "\<Esc>]50;CursorShape=1\x7" | |
| let &t_EI = "\<Esc>]50;CursorShape=0\x7" | |
| endif | |
| ":autocmd InsertEnter * set cul " set cursor mode | |
| ":autocmd InsertLeave * set nocul " set cursor mode for leaving insert mode | |
| " ------- | |
| " PLUGINS | |
| " ------- | |
| " Install vim-plug if not found | |
| if empty(glob('~/.vim/autoload/plug.vim')) | |
| silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs | |
| \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim | |
| endif | |
| " Run PlugInstall if there are missing plugins | |
| autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) | |
| \| PlugInstall --sync | source $MYVIMRC | |
| \| endif | |
| call plug#begin('~/.vim/plugged') | |
| Plug 'vim-airline/vim-airline' | |
| Plug 'vim-airline/vim-airline-themes' | |
| Plug 'sainnhe/sonokai' | |
| Plug 'sheerun/vim-polyglot' | |
| Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } | |
| Plug 'junegunn/fzf.vim' | |
| Plug 'airblade/vim-rooter' | |
| Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' } | |
| Plug 'preservim/nerdtree' | |
| Plug 'Xuyuanp/nerdtree-git-plugin' | |
| Plug 'neoclide/coc.nvim', {'branch': 'release'} | |
| Plug 'jiangmiao/auto-pairs' | |
| Plug 'preservim/nerdcommenter' | |
| Plug 'tpope/vim-fugitive' | |
| call plug#end() | |
| " ----------- | |
| " COLORSCHEME | |
| " ----------- | |
| if has('termguicolors') | |
| set termguicolors | |
| endif | |
| " The configuration options should be placed before `colorscheme sonokai`. | |
| let g:sonokai_style = 'atlantis' | |
| let g:sonokai_enable_italic = 1 | |
| let g:sonokai_disable_italic_comment = 1 | |
| let g:sonokai_diagnostic_text_highlight = 1 | |
| let g:sonokai_diagnostic_line_highlight = 0 | |
| colorscheme sonokai | |
| " ---- | |
| " LETS | |
| " ---- | |
| let mapleader = " " | |
| " airline related | |
| let g:airline#extensions#tabline#enabled = 1 | |
| let g:airline#extensions#tabline#formatter = 'default' | |
| :let g:airline_highlighting_cache = 1 | |
| " theme related | |
| let g:airline_theme = 'sonokai' | |
| " ----------- | |
| " KEYBINDINGS | |
| " ----------- | |
| :inoremap jk <ESC> | |
| :nnoremap <silent> <esc><esc> :noh<cr> " disable search higlight until next search | |
| " buffers | |
| :map <silent> <leader>p :bp<cr> " previous buffer | |
| :map <silent> <leader>n :bn<cr> " next buffer | |
| ":map <silent> <leader>d delete buffer see DELETE BUFFER AND MAINTAIN LAYOUT | |
| :nmap <silent> <leader>v :vert sb<cr> <bar> :wincmd h<cr> <bar> <C-^> <bar> :wincmd l<cr> " open buffer in vertical split | |
| :nmap <silent> <leader>x :sb<cr> <bar> :wincmd k<cr> <bar> <C-^> <bar> :wincmd j<cr> " open buffer in horizontal split | |
| " window | |
| :nmap <silent> <C-h> :wincmd h<cr> | |
| :nmap <silent> <C-j> :wincmd j<cr> | |
| :nmap <silent> <C-k> :wincmd k<cr> | |
| :nmap <silent> <C-l> :wincmd l<cr> | |
| :nmap <silent> <leader>9 :wincmd t <bar> :wincmd K<cr> | |
| :nmap <silent> <leader>8 :wincmd t <bar> :wincmd H<cr> | |
| " tabs | |
| :nnoremap <leader>tt :tabnew<cr> | |
| :nnoremap <leader>tc :tabclose<cr> | |
| :nnoremap <leader>tn :tabnext<cr> | |
| :nnoremap <leader>tp :tabprevious<cr> | |
| " | |
| " "window resizing | |
| ":noremap <silent> <C-Left> :vertical resize -3<cr> | |
| ":noremap <silent> <C-Right> :vertical resize +3<cr> | |
| ":noremap <silent> <C-Up> :resize +3<cr> | |
| ":noremap <silent> <C-Down> :resize -3<cr> | |
| " terminal | |
| :map <leader>tb :below terminal<cr> | |
| :nmap <leader>o :FZF<cr> | |
| " NERDTree | |
| nnoremap <leader><C-b> :NERDTreeToggle<cr> | |
| nnoremap <leader><C-0> :NERDTreeFocus<cr> | |
| nnoremap <leader><C-h> :NERDTreeFind<cr> | |
| " NERDCommenter | |
| nnoremap <leader>/ :call NERDComment(0,"toggle")<cr> | |
| vnoremap <leader>/ :call NERDComment(0,"toggle")<cr> | |
| " VIM FUGITIVE | |
| nnoremap <leader>gs :Git <cr> | |
| nnoremap <leader>gps :Git push <cr> | |
| nnoremap <leader>gpl :Git pull <cr> | |
| " VIM-GO | |
| " error navigation in quickfix list | |
| map <C-n> :cnext<CR> | |
| map <C-m> :cprevious<CR> | |
| nnoremap <leader>a :cclose<CR> | |
| " running and building | |
| autocmd FileType go nmap <leader>r <Plug>(go-run) | |
| autocmd FileType go nmap <leader>t <Plug>(go-test) | |
| " run :GoBuild or :GoTestCompile based on the go file | |
| function! s:build_go_files() | |
| let l:file = expand('%') | |
| if l:file =~# '^\f\+_test\.go$' | |
| call go#test#Test(0, 1) | |
| elseif l:file =~# '^\f\+\.go$' | |
| call go#cmd#Build(0) | |
| endif | |
| endfunction | |
| autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR> | |
| " TO REMEMBER | |
| " g*cgn + . | to find and replace by occurance | |
| " <C-w> = | to make a split even | |
| " <C-w> | | to expand split vertically | |
| " <C-w> _ | to expand split horizontally | |
| " <C-v> hjkl + I + {change} + <esc><esc> | to highlight and replace in visual block mode | |
| " <C-p> or <C-n> | for auto-complete | |
| " :%s/foo/bar/g | Find each occurrence of 'foo' (in all lines), and replace it with 'bar'. | |
| " :%s/foo/bar/gc | Change each 'foo' to 'bar', but ask for confirmation first. | |
| " ----------------- | |
| " NERDTREE SETTINGS | |
| " ----------------- | |
| " Start NERDTree when Vim is started without file arguments. | |
| "autocmd StdinReadPre * let s:std_in=1 | |
| "autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif | |
| " Start NERDTree when Vim starts with a directory argument. | |
| autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') | | |
| \ execute 'NERDTree' argv()[0] | wincmd p | enew | execute 'cd '.argv()[0] | endif | |
| " 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 | |
| let g:NERDTreeGitStatusIndicatorMapCustom = { | |
| \ 'Modified' :'✹', | |
| \ 'Staged' :'✚', | |
| \ 'Untracked' :'✭', | |
| \ 'Renamed' :'➜', | |
| \ 'Unmerged' :'═', | |
| \ 'Deleted' :'✖', | |
| \ 'Dirty' :'✗', | |
| \ 'Ignored' :'☒', | |
| \ 'Clean' :'✔︎', | |
| \ 'Unknown' :'?', | |
| \ } | |
| " ------------ | |
| " FZF SETTINGS | |
| " ------------ | |
| " This is the default extra key bindings | |
| let g:fzf_action = { | |
| \ 'ctrl-t': 'tab split', | |
| \ 'ctrl-x': 'split', | |
| \ 'ctrl-v': 'vsplit' } | |
| " An action can be a reference to a function that processes selected lines | |
| function! s:build_quickfix_list(lines) | |
| call setqflist(map(copy(a:lines), '{ "filename": v:val }')) | |
| copen | |
| cc | |
| endfunction | |
| let g:fzf_action = { | |
| \ 'ctrl-q': function('s:build_quickfix_list'), | |
| \ 'ctrl-t': 'tab split', | |
| \ 'ctrl-x': 'split', | |
| \ 'ctrl-v': 'vsplit' } | |
| " Default fzf layout | |
| " - Popup window (center of the screen) | |
| "let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } } | |
| " - Popup window (center of the current window) | |
| "let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6, 'relative': v:true } } | |
| " - Popup window (anchored to the bottom of the current window) | |
| "let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6, 'relative': v:true, 'yoffset': 1.0 } } | |
| " - down / up / left / right | |
| "let g:fzf_layout = { 'down': '40%' } | |
| " - Window using a Vim command | |
| "let g:fzf_layout = { 'window': 'enew' } | |
| "let g:fzf_layout = { 'window': '-tabnew' } | |
| let g:fzf_layout = { 'window': '10new' } | |
| " Customize fzf colors to match your color scheme | |
| " - fzf#wrap translates this to a set of `--color` options | |
| let g:fzf_colors = | |
| \ { 'fg': ['fg', 'Normal'], | |
| \ 'bg': ['bg', 'Normal'], | |
| \ 'hl': ['fg', 'Comment'], | |
| \ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'], | |
| \ 'bg+': ['bg', 'CursorLine', 'CursorColumn'], | |
| \ 'hl+': ['fg', 'Statement'], | |
| \ 'info': ['fg', 'PreProc'], | |
| \ 'border': ['fg', 'Ignore'], | |
| \ 'prompt': ['fg', 'Conditional'], | |
| \ 'pointer': ['fg', 'Exception'], | |
| \ 'marker': ['fg', 'Keyword'], | |
| \ 'spinner': ['fg', 'Label'], | |
| \ 'header': ['fg', 'Comment'] } | |
| " Enable per-command history | |
| " - History files will be stored in the specified directory | |
| " - When set, CTRL-N and CTRL-P will be bound to 'next-history' and | |
| " 'previous-history' instead of 'down' and 'up'. | |
| let g:fzf_history_dir = '~/.local/share/fzf-history' | |
| " ------------ | |
| " COC SETTINGS | |
| " ------------ | |
| " | |
| " Set internal encoding of vim, not needed on neovim, since coc.nvim using some | |
| " unicode characters in the file autoload/float.vim | |
| set encoding=utf-8 | |
| " TextEdit might fail if hidden is not set. | |
| "set hidden | |
| " Some servers have issues with backup files, see #649. | |
| set nobackup | |
| set nowritebackup | |
| " Give more space for displaying messages. | |
| "set cmdheight=2 | |
| " Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable | |
| " delays and poor user experience. | |
| set updatetime=300 | |
| " Don't pass messages to |ins-completion-menu|. | |
| set shortmess+=c | |
| " Always show the signcolumn, otherwise it would shift the text each time | |
| " diagnostics appear/become resolved. | |
| if has("nvim-0.5.0") || has("patch-8.1.1564") | |
| " Recently vim can merge signcolumn and number column into one | |
| set signcolumn=number | |
| else | |
| set signcolumn=yes | |
| endif | |
| " Use tab for trigger completion with characters ahead and navigate. | |
| " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by | |
| " other plugin before putting this into your config. | |
| inoremap <silent><expr> <TAB> | |
| \ pumvisible() ? "\<C-n>" : | |
| \ <SID>check_back_space() ? "\<TAB>" : | |
| \ coc#refresh() | |
| inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>" | |
| function! s:check_back_space() abort | |
| let col = col('.') - 1 | |
| return !col || getline('.')[col - 1] =~# '\s' | |
| endfunction | |
| " Use <c-space> to trigger completion. | |
| if has('nvim') | |
| inoremap <silent><expr> <c-space> coc#refresh() | |
| else | |
| inoremap <silent><expr> <c-@> coc#refresh() | |
| endif | |
| " Make <CR> auto-select the first completion item and notify coc.nvim to | |
| " format on enter, <cr> could be remapped by other vim plugin | |
| inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() | |
| \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" | |
| " Use `[g` and `]g` to navigate diagnostics | |
| " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list. | |
| nmap <silent> [g <Plug>(coc-diagnostic-prev) | |
| nmap <silent> ]g <Plug>(coc-diagnostic-next) | |
| " GoTo code navigation. | |
| nmap <silent> gd <Plug>(coc-definition) | |
| nmap <silent> gy <Plug>(coc-type-definition) | |
| nmap <silent> gi <Plug>(coc-implementation) | |
| nmap <silent> gr <Plug>(coc-references) | |
| " Use K to show documentation in preview window. | |
| nnoremap <silent> K :call <SID>show_documentation()<CR> | |
| function! s:show_documentation() | |
| if (index(['vim','help'], &filetype) >= 0) | |
| execute 'h '.expand('<cword>') | |
| elseif (coc#rpc#ready()) | |
| call CocActionAsync('doHover') | |
| else | |
| execute '!' . &keywordprg . " " . expand('<cword>') | |
| endif | |
| endfunction | |
| " Highlight the symbol and its references when holding the cursor. | |
| autocmd CursorHold * silent call CocActionAsync('highlight') | |
| " Symbol renaming. | |
| nmap <leader>rn <Plug>(coc-rename) | |
| " Formatting selected code. | |
| xmap <leader>f <Plug>(coc-format-selected) | |
| nmap <leader>f <Plug>(coc-format-selected) | |
| augroup mygroup | |
| autocmd! | |
| " Setup formatexpr specified filetype(s). | |
| autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') | |
| " Update signature help on jump placeholder. | |
| autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') | |
| augroup end | |
| " Applying codeAction to the selected region. | |
| " Example: `<leader>aap` for current paragraph | |
| xmap <leader>a <Plug>(coc-codeaction-selected) | |
| nmap <leader>a <Plug>(coc-codeaction-selected) | |
| " Remap keys for applying codeAction to the current buffer. | |
| nmap <leader>ac <Plug>(coc-codeaction) | |
| " Apply AutoFix to problem on the current line. | |
| nmap <leader>qf <Plug>(coc-fix-current) | |
| " Map function and class text objects | |
| " NOTE: Requires 'textDocument.documentSymbol' support from the language server. | |
| xmap if <Plug>(coc-funcobj-i) | |
| omap if <Plug>(coc-funcobj-i) | |
| xmap af <Plug>(coc-funcobj-a) | |
| omap af <Plug>(coc-funcobj-a) | |
| xmap ic <Plug>(coc-classobj-i) | |
| omap ic <Plug>(coc-classobj-i) | |
| xmap ac <Plug>(coc-classobj-a) | |
| omap ac <Plug>(coc-classobj-a) | |
| " Remap <C-f> and <C-b> for scroll float windows/popups. | |
| if has('nvim-0.4.0') || has('patch-8.2.0750') | |
| nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>" | |
| nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>" | |
| inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>" | |
| inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>" | |
| vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>" | |
| vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>" | |
| endif | |
| " Use CTRL-S for selections ranges. | |
| " Requires 'textDocument/selectionRange' support of language server. | |
| nmap <silent> <C-s> <Plug>(coc-range-select) | |
| xmap <silent> <C-s> <Plug>(coc-range-select) | |
| " Add `:Format` command to format current buffer. | |
| command! -nargs=0 Format :call CocAction('format') | |
| " Add `:Fold` command to fold current buffer. | |
| command! -nargs=? Fold :call CocAction('fold', <f-args>) | |
| " Add `:OR` command for organize imports of the current buffer. | |
| command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') | |
| " Add (Neo)Vim's native statusline support. | |
| " NOTE: Please see `:h coc-status` for integrations with external plugins that | |
| " provide custom statusline: lightline.vim, vim-airline. | |
| set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} | |
| """ Mappings for CoCList | |
| """ Show all diagnostics. | |
| nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr> | |
| """ Manage extensions. | |
| ""nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr> | |
| """ Show commands. | |
| ""nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr> | |
| """ Find symbol of current document. | |
| ""nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr> | |
| """ Search workspace symbols. | |
| ""nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr> | |
| """ Do default action for next item. | |
| ""nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR> | |
| """ Do default action for previous item. | |
| ""nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR> | |
| """ Resume latest coc list. | |
| ""nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR> | |
| "" | |
| " -------------- | |
| " NERD Commenter | |
| " -------------- | |
| " Enable trimming of trailing whitespace when uncommenting | |
| " let g:NERDTrimTrailingWhitespace = 0 | |
| " Add spaces after comment delimiters by default | |
| " let g:NERDSpaceDelims = 0 | |
| " Enable NERDCommenterToggle to check all selected lines is commented or not | |
| " let g:NERDToggleCheckAllLines = 0 | |
| " --------------- | |
| " VIM-GO SETTINGS | |
| " --------------- | |
| let g:go_fmt_command = "goimports" | |
| let g:go_addtags_transform = "camelcase" | |
| "let g:go_metalinter_autosave = 1 " runs go vet, golint and errcheck | |
| "let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck'] | |
| "let g:go_metalinter_autosave_enabled = ['vet', 'golint'] | |
| " --------------------------------- | |
| " DELETE BUFFER AND MAINTAIN LAYOUT | |
| " --------------------------------- | |
| "delete the buffer; keep windows; create a scratch buffer if no buffers left | |
| function s:Kwbd(kwbdStage) | |
| if(a:kwbdStage == 1) | |
| if(&modified) | |
| let answer = confirm("This buffer has been modified. Are you sure you want to delete it?", "&Yes\n&No", 2) | |
| if(answer != 1) | |
| return | |
| endif | |
| endif | |
| if(!buflisted(winbufnr(0))) | |
| bd! | |
| return | |
| endif | |
| let s:kwbdBufNum = bufnr("%") | |
| let s:kwbdWinNum = winnr() | |
| windo call s:Kwbd(2) | |
| execute s:kwbdWinNum . 'wincmd w' | |
| let s:buflistedLeft = 0 | |
| let s:bufFinalJump = 0 | |
| let l:nBufs = bufnr("$") | |
| let l:i = 1 | |
| while(l:i <= l:nBufs) | |
| if(l:i != s:kwbdBufNum) | |
| if(buflisted(l:i)) | |
| let s:buflistedLeft = s:buflistedLeft + 1 | |
| else | |
| if(bufexists(l:i) && !strlen(bufname(l:i)) && !s:bufFinalJump) | |
| let s:bufFinalJump = l:i | |
| endif | |
| endif | |
| endif | |
| let l:i = l:i + 1 | |
| endwhile | |
| if(!s:buflistedLeft) | |
| if(s:bufFinalJump) | |
| windo if(buflisted(winbufnr(0))) | execute "b! " . s:bufFinalJump | endif | |
| else | |
| enew | |
| let l:newBuf = bufnr("%") | |
| windo if(buflisted(winbufnr(0))) | execute "b! " . l:newBuf | endif | |
| endif | |
| execute s:kwbdWinNum . 'wincmd w' | |
| endif | |
| if(buflisted(s:kwbdBufNum) || s:kwbdBufNum == bufnr("%")) | |
| execute "bd! " . s:kwbdBufNum | |
| endif | |
| if(!s:buflistedLeft) | |
| set buflisted | |
| set bufhidden=delete | |
| set buftype= | |
| setlocal noswapfile | |
| endif | |
| else | |
| if(bufnr("%") == s:kwbdBufNum) | |
| let prevbufvar = bufnr("#") | |
| if(prevbufvar > 0 && buflisted(prevbufvar) && prevbufvar != s:kwbdBufNum) | |
| b # | |
| else | |
| bn | |
| endif | |
| endif | |
| endif | |
| endfunction | |
| command! Kwbd call s:Kwbd(1) | |
| nnoremap <silent> <Plug>Kwbd :<C-u>Kwbd<CR> | |
| " Create a mapping (e.g. in your .vimrc) like this: | |
| nmap <leader>d <Plug>Kwbd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment