From 7f053fcb8eab062296a9c422061384b64ce1248a Mon Sep 17 00:00:00 2001 From: bretello Date: Sun, 6 Dec 2020 01:30:51 +0100 Subject: [PATCH] vim: rewrite config - abandon amix's vimrc (thanks for all the fish) - use vim-plug (https://github.com/junegunn/vim-plug) to manage plugins - move config from `my_configs.vim` to `vimrc` - update install script accordingly --- README.md | 4 +- install.sh | 18 +- my_configs.vim | 179 ------------------- vimrc | 458 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 466 insertions(+), 193 deletions(-) delete mode 100644 my_configs.vim create mode 100644 vimrc diff --git a/README.md b/README.md index 479be71..942361f 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ A set of zsh dotfiles based on antibody and oh-my-zsh │ │   ├── startup │ │   ├── 11-autoreload.py │ │   └── README -│ ├── my_configs.vim -│ │ └── vim (sourced by amix's vimrc) +│ ├── vimrc +│ │ └── powered by `vim-plug` │ ├── twilight256.vim │ │ └── vim's colorscheme │ └── pdbrc.py diff --git a/install.sh b/install.sh index c6c0a99..ff92670 100755 --- a/install.sh +++ b/install.sh @@ -25,21 +25,15 @@ function setup_git { } function install_vimrc { - # Install vimrc from github.com/amix/vimrc - git clone "https://github.com/amix/vimrc.git" "$HOME/.vim_runtime" && sh "$HOME/.vim_runtime/install_awesome_vimrc.sh" || return 1 + # TODO: check if vim-plug is installed + if [ -f "$HOME/.vimrc" ]; then + mv "$HOME/.vimrc"{,.bak} && echo "Backed up old vimrc" + fi + ln -s "$DOTFILES/.vimrc" "$HOME/.vimrc" } function setup_ackrc { - ln -s "$DOTFILES/ackrc" "~/.ackrc" -} - -function setup_vim { - # Install vim awesomerc (git amix/vimrc) - install_vimrc && echo "Installed vim awesome rc" || echo "Failed to install vim awesome rc" - ln -s "$DOTFILES/my_configs.vim" "$HOME/.vim_runtime/my_configs.vim" - mkdir -p ~/.vim_runtime/my_plugins/twilight/colors - ln -s "$DOTFILES/twilight256.vim" ~/.vim_runtime/my_plugins/twilight/colors/ - (cd ~/.vim_runtime/my_plugins && git add -f * && git commit -m "bretello dotfiles") + ln -s "$DOTFILES/ackrc" "$HOME/.ackrc" } function setup_ipython { diff --git a/my_configs.vim b/my_configs.vim deleted file mode 100644 index 0cb3fb7..0000000 --- a/my_configs.vim +++ /dev/null @@ -1,179 +0,0 @@ -" colorscheme peaksea -colorscheme twilight256 - -let g:ale_set_balloons = 1 - - -set mouse=a relativenumber number foldmethod=indent nofoldenable "without nofoldenable all folds are closed at startup" -set foldlevelstart=3 -set ttymouse=xterm2 " fix mouse when used in tmux/byobu https://unix.stackexchange.com/q/50733 - -set splitbelow splitright -set autoread -set nowrap - -" ALE configuration -let g:ale_fixers_aliases = {'vue': ['vue', 'javascript']} - -let g:ale_fixers = { - \ '*': ['remove_trailing_lines', 'trim_whitespace'], - \ 'bash': ['shfmt'], - \ 'json': ['prettier'], - \ 'cpp': ['clang-format'], - \ 'css': ['prettier'], - \ 'html': ['prettier'], - \ 'markdown': ['prettier'], - \ 'java': ['eclipselsp'], - \ 'yaml': ['prettier'], - \ 'python': ['black', 'isort'], - \ 'go': ['gofmt', "goimports"], - \ 'rust': ['rustfmt'], - \ "javascript": ["prettier", "eslint"], - \ "vue": ["prettier", "eslint"] -\} - -let g:ale_python_bandit_options = "-c banditrc" -let g:ale_python_pylint_options = "--rcfile pylintrc --disable=W0511" -let g:ale_cpp_clang_options = '-std=c++17 -Wall -Wpedantic' -let g:ale_cpp_gcc_options = '-std=c++17 -Wall -Wpedantic' -let g:ale_cpp_cc_options = '-std=c++17 -Wall -Wpedantic' - - -let g:ale_linter_aliases = {'vue': ['vue', 'javascript']} -let g:ale_linters = { - \ 'bash': ['bashlint', "shellcheck"], - \ 'python': ['pyls', 'pylint', 'bandit', 'mypy'], - \ 'go': ['gopls', 'gobuild'], - \ 'rust': ['analyzer', 'rustc'], - \ 'yaml': ['yamllint'], - \ 'javascript': ["yarn lint", "eslint", "vls"] -\} - -let g:ack_default_options = " --cc --cpp --shell --python --html --js --vue" - -let g:ale_set_quickfix=1 -let g:ale_set_loclist=0 -let g:ale_open_list = 1 -let g:ale_keep_list_window_open = 1 - -let g:ale_lint_on_save = 1 -let g:ale_fix_on_save = 1 -let g:ale_completion_enabled = 1 -" let g:ale_completion_autoimport = 1 - -nmap - -packadd termdebug - -" Fix some gitgutter stuff -let g:gitgutter_enabled = 1 -let g:gitgutter_override_sign_column_highlight = 0 -highlight clear SignColumn -highlight GitGutterAdd ctermfg=2 -highlight GitGutterChange ctermfg=3 -highlight GitGutterDelete ctermfg=1 -highlight GitGutterChangeDelete ctermfg=4 - -" Highlight all instances of word under cursor, when idle. -" Useful when studying strange source code. -" Type z/ to toggle highlighting on/off. -nnoremap z/ :if AutoHighlightToggle()set hlsendif -function! AutoHighlightToggle() - let @/ = '' - if exists('#auto_highlight') - au! auto_highlight - augroup! auto_highlight - setl updatetime=4000 - echo 'Highlight current word: off' - return 0 - else - augroup auto_highlight - au! - au CursorHold * let @/ = '\V\<'.escape(expand(''), '\').'\>' - augroup end - setl updatetime=500 - echo 'Highlight current word: ON' - return 1 - endif -endfunction - -" A friggin python breakpoint. Invoke with @b -let @b = 'A breakpoint()€ýajkj0' - -let g:ctrlp_custom_ignore = { - \ 'dir': '\v(target|build|dist|.venv)$', - \ } - " \ 'file': '\v\.(exe|so|dll)$', - " \ 'link': 'some_bad_symbolic_links', -let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard'] - -nnoremap mk :bel copensilent (cargo run) !redraw! - -autocmd FileType yaml setlocal shiftwidth=2 softtabstop=2 expandtab -autocmd FileType yml setlocal shiftwidth=2 softtabstop=2 expandtab - -" Improve vimdiff colors -highlight DiffAdd cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red -highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red -highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red -highlight DiffText cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red - - -function! WinZoomToggle() abort - if ! exists('w:WinZoomIsZoomed') - let w:WinZoomIsZoomed = 0 - endif - if w:WinZoomIsZoomed == 0 - let w:WinZoomOldWidth = winwidth(0) - let w:WinZoomOldHeight = winheight(0) - wincmd _ - wincmd | - let w:WinZoomIsZoomed = 1 - elseif w:WinZoomIsZoomed == 1 - execute "resize " . w:WinZoomOldHeight - execute "vertical resize " . w:WinZoomOldWidth - let w:WinZoomIsZoomed = 0 - endif -endfunction - -nnoremap wz :call WinZoomToggle() - -nnoremap / :G -nnoremap C :close -nnoremap B :Bclose -nnoremap k :Ack -nnoremap g :Git -nnoremap gd :Git diff -nnoremap gp :Git push -nnoremap gpf :Git push --force-with-lease -nnoremap M :Git commit -nnoremap u :GitGutterBufferToggle -nnoremap L :GitGutterLineHighlightsToggle - -nmap (ale_previous_wrap) -nmap (ale_next_wrap) - -nmap sv :ALEGoToDefinition -vsplit -nmap sh :ALEGoToDefinition -split -nmap st :ALEGoToDefinition -tab -nmap A :ALEGoToDefinition -nmap n :ALEFindReferences -nmap h :ALEHover -nmap r :ALERename -nmap t :CtrlPTag -nmap \ :Explore -" Add shortcuts to yank/paste to unnamed/unnamedplus clipboards -noremap y "*y -noremap p "*p -noremap Y "+y -noremap P "+p - -" These are the default mappings Default mappings -let g:multi_cursor_start_word_key = '' -let g:multi_cursor_select_all_word_key = '' -let g:multi_cursor_start_key = 'g' -let g:multi_cursor_select_all_key = 'g' -let g:multi_cursor_next_key = '' -let g:multi_cursor_prev_key = '' -let g:multi_cursor_skip_key = '' -let g:multi_cursor_quit_key = '' diff --git a/vimrc b/vimrc new file mode 100644 index 0000000..1ad35e4 --- /dev/null +++ b/vimrc @@ -0,0 +1,458 @@ +" Sanity +set encoding=utf-8 +scriptencoding utf-8 + +" Install vim-plug if not installed already (requires curl) +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 + autocmd VimEnter * PlugInstall --sync | source ~/.vimrc +endif + +" Plugins +call plug#begin('~/.vim/vim-plug') +" Basic vim config +Plug 'tpope/vim-sensible' +" Colorscheme +Plug 'https://github.com/morhetz/gruvbox' +" Asynchronous Linting Engine +Plug 'https://github.com/dense-analysis/ale' +" Open files/recent files/tags quickly +Plug 'https://github.com/ctrlpvim/ctrlp.vim' +" Git +Plug 'https://github.com/tpope/vim-fugitive' +" Comment shit easily +Plug 'https://github.com/tpope/vim-commentary' +" Browse file system +Plug 'https://github.com/scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } +" Minimal status line +Plug 'https://github.com/itchyny/lightline.vim' +" Lightline status for ALE +Plug 'maximbaz/lightline-ale' +" Insert parentheses in pairs +Plug 'https://github.com/jiangmiao/auto-pairs' +Plug 'https://github.com/amix/open_file_under_cursor.vim' +" Multi cursor +Plug 'https://github.com/mg979/vim-visual-multi' +" Easily explore open buffers +Plug 'https://github.com/vim-scripts/bufexplorer.zip' +" Search +Plug 'https://github.com/mileszs/ack.vim' +" Yank history +Plug 'https://github.com/maxbrunsfeld/vim-yankstack' +" Mark indentation level +Plug 'nathanaelkane/vim-indent-guides' + +" snipmate +Plug 'https://github.com/MarcWeber/vim-addon-mw-utils' +Plug 'https://github.com/tomtom/tlib_vim' +Plug 'https://github.com/garbas/vim-snipmate' + +" Git gutter line +Plug 'https://github.com/airblade/vim-gitgutter' +" Zero distractions +Plug 'https://github.com/junegunn/goyo.vim' + +" Highlight lines not covered by tests +Plug 'https://github.com/mgedmin/coverage-highlight.vim' + +"Languages +Plug 'https://github.com/rust-lang/rust.vim' +Plug 'https://github.com/vim-scripts/nginx.vim' +Plug 'https://github.com/plasticboy/vim-markdown' +Plug 'https://github.com/altercation/vim-colors-solarized' + +Plug 'epheien/termdbg' + +" No RGB, no party +let vim_razer = expand('~/projects_razer/vim-razer') +if isdirectory(vim_razer) + Plug vim_razer +endif +call plug#end() + +" Style +set background=dark +colorscheme gruvbox + +" General stuff +set nowrap +set mouse=a +set relativenumber number +set foldlevelstart=3 foldmethod=syntax nofoldenable "without nofoldenable all folds are closed at startup" +set ttymouse=xterm2 " fix mouse when used in tmux/byobu https://unix.stackexchange.com/q/50733 + +set nobackup nowb noswapfile " no need for backups of every file +set history=10000 + +set list listchars=tab:›\ ,trail:•,extends:#,nbsp:. + +set splitbelow splitright +set autoread +" Don't redraw while executing macros (good performance config) +set lazyredraw + +set ignorecase smartcase " ignore case on search but be smart about it +set hlsearch "highlight search results (using *) + +set shiftwidth=4 tabstop=4 +autocmd FileType yaml,yml setlocal shiftwidth=2 softtabstop=2 expandtab + +" Return to last edit position when opening files (from amix's vimrc) +au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif + +" Remap VIM 0 to first non-blank character +" map 0 ^ + +" Bash like keys for the command line +cnoremap +cnoremap +cnoremap + +cnoremap +cnoremap + +try + set undodir=~/.vim/temp_dirs/undodir + set undofile +catch +endtry + + +"""" PLUGINS CONFIGURATION +let g:ack_default_options = " --cc --cpp --shell --python --html --js --vue" + +" ALE configuration +let g:ale_set_balloons = 1 " enable tooltips +let g:ale_fixers = { + \ '*': ['remove_trailing_lines', 'trim_whitespace'], + \ 'bash': ['shfmt'], + \ 'json': ['prettier'], + \ 'cpp': ['clang-format'], + \ 'css': ['prettier'], + \ 'html': ['prettier'], + \ 'markdown': ['prettier'], + \ 'java': ['eclipselsp'], + \ 'yaml': ['prettier'], + \ 'python': ['black', 'isort'], + \ 'go': ['gofmt', "goimports"], + \ 'rust': ['rustfmt'], + \ "javascript": ["prettier", "eslint"], + \ "vue": ["prettier", "eslint"] +\} +let g:ale_fixers_aliases = {'vue': ['vue', 'javascript']} + +let g:ale_python_bandit_options = "-c banditrc" +" let g:ale_python_pylint_options = "--rcfile pylintrc --disable=W0511" " if the rcfile does not exist, pylint will exit without linting +let g:ale_python_pylint_options = "--disable=W0511" +let g:ale_cpp_clang_options = '-std=c++17 -Wall -Wpedantic' +let g:ale_cpp_gcc_options = '-std=c++17 -Wall -Wpedantic' + +let g:ale_linters = { + \ 'bash': ['bashlint', "shellcheck"], + \ 'zsh': ['bashlint', "shellcheck"], + \ 'python': ['pyls', 'pylint', 'bandit'], + \ 'go': ['gopls', 'gobuild'], + \ 'rust': ['analyzer', 'rustc'], + \ 'yaml': ['yamllint'], + \ 'javascript': ["yarn lint", "eslint", "vls"] +\} +let g:ale_linter_aliases = {'vue': ['vue', 'javascript']} + +let g:ale_set_quickfix=1 +let g:ale_set_loclist=0 +let g:ale_open_list = 0 +let g:ale_keep_list_window_open = 1 + +let g:ale_lint_on_save = 1 +" let g:ale_lint_on_enter = 0 " uncomment if you do not want to lint files on open +let g:ale_lint_on_insert_leave = 1 +" let g:ale_lint_on_text_changed = 1 +let g:ale_lint_delay = 2500 " lint 2.5 seconds after text has changed +let g:ale_fix_on_save = 1 +let g:ale_completion_enabled = 1 +" let g:ale_completion_autoimport = 1 + +let g:ale_sign_priority = 99 +let g:ale_sign_error = "xx" +let g:ale_sign_warning = ">>" +let g:ale_sign_info = "--" +"let g:ale_sign_style_error = +"let g:ale_sign_style_warning = + +packadd termdebug "useless shit + +" Fix some gitgutter stuff +let g:gitgutter_enabled = 1 +let g:gitgutter_sign_allow_clobber = 0 " do not allow gitgutter to overwrite signs +let g:gitgutter_sign_priority = 50 +" let g:gitgutter_set_sign_backgrounds = 1 +" let g:gitgutter_override_sign_column_highlight = 0 + +" highlight clear GitGutterAdd GitGutterChange GitGutterModified GitGutterDelete SignColumn +highlight SignColumn ctermbg=none + +highlight GitGutterAdd ctermbg=none ctermfg=2 +highlight GitGutterChange ctermbg=none ctermfg=3 +highlight GitGutterDelete ctermbg=none ctermfg=1 +highlight GitGutterChangeDelete ctermbg=none ctermfg=1 + +let g:gitgutter_sign_added = '+' +let g:gitgutter_sign_modified = '~' +let g:gitgutter_sign_modified_removed = 'x' + +" Improve vimdiff colors (deprecated, this was useful for the twilight256 colorscheme) +" highlight DiffAdd cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red +" highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red +" highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red +" highlight DiffText cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red + +" Lightline config from amix's vimrc " TODO: this could be improved +let g:lightline = { + \ 'colorscheme': 'wombat', + \ 'active': { + \ 'left': [ ['mode', 'paste'], + \ ['fugitive', 'readonly', 'filename', 'modified'] ], + \ 'right': [ [ 'lineinfo' ], ['percent'] ] + \ }, + \ 'component': { + \ 'readonly': '%{&filetype=="help"?"":&readonly?"¿":""}', + \ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}', + \ 'fugitive': '%{exists("*FugitiveHead")?FugitiveHead():""}' + \ }, + \ 'component_visible_condition': { + \ 'readonly': '(&filetype!="help"&& &readonly)', + \ 'modified': '(&filetype!="help"&&(&modified||!&modifiable))', + \ 'fugitive': '(exists("*FugitiveHead") && ""!=FugitiveHead())' + \ }, + \ 'separator': { 'left': ' ', 'right': ' ' }, + \ 'subseparator': { 'left': ' ', 'right': ' ' } + \ } + +let g:lightline.component_expand = { + \ 'linter_checking': 'lightline#ale#checking', + \ 'linter_infos': 'lightline#ale#infos', + \ 'linter_warnings': 'lightline#ale#warnings', + \ 'linter_errors': 'lightline#ale#errors', + \ 'linter_ok': 'lightline#ale#ok', + \ } + +" These are the default mappings for vim-multi-cursor +let g:multi_cursor_start_word_key = '' +let g:multi_cursor_select_all_word_key = '' +let g:multi_cursor_start_key = 'g' +let g:multi_cursor_select_all_key = 'g' +let g:multi_cursor_next_key = '' +let g:multi_cursor_prev_key = '' +let g:multi_cursor_skip_key = '' +let g:multi_cursor_quit_key = '' + +" indent-guides, toggle with ig +let g:indent_guides_enable_on_vim_startup = 0 +let g:indent_guides_exclude_filetypes = ['help', 'terminal', 'nerdtree'] +let g:indent_guides_start_level = 2 +let g:indent_guides_guide_size = 1 + + +"""" Leader shortcuts +let mapleader = "," +" also use space as leader +nmap + +nmap w :w! +command! W execute 'w !sudo tee % > /dev/null' edit! +" nmap W :w! + +"Reload vimrc on config change +map e :e! ~/.vimrc +map ` :ALELint +" FIXME: This results in some weird conflict with lightline +autocmd! bufwritepost ~/.vimrc source ~/.vimrc + +" Quickly open a markdown buffer for scribble +map x :e ~/buffer.md +" Toggle paste mode on and off +nmap pp :setlocal paste! + +" open quickfix +nmap cc :botright cope +" close quickfix (also see C below) +nmap cx :hide +nmap co ggVGy:tabnew:set syntax=qfpgg +" next cope error +map cn :cn +" previous cope error +map cp :cp + +map :noh "disable highlighting for current word +map ss :setlocal spell! + +nnoremap mk :bel copensilent (cargo run) !redraw! +nnoremap wz :call WinZoomToggle() + +nmap \ :Explore +nnoremap C :close +nnoremap B :Bclose +nnoremap k :Ack + +"" Fugitive +nnoremap / :Git +nnoremap g :Git +nnoremap gd :Git diff +nnoremap gp :Git push +nnoremap M :Git commit +nnoremap gpf :Git push --force-with-lease + +"" Gitutter +nnoremap u :GitGutterBufferToggle +nnoremap L :GitGutterLineHighlightsToggle +nmap hn (GitGutterNextHunk) +nmap hp (GitGutterPrevHunk) + +"" Ale +nmap (ale_previous_wrap) +nmap (ale_next_wrap) +nmap sv :ALEGoToDefinition -vsplit +nmap sh :ALEGoToDefinition -split +nmap st :ALEGoToDefinition -tab +nmap A :ALEGoToDefinition +nmap n :ALEFindReferences +nmap h :ALEHover +nmap r :ALERename + +" call ack when pressing gv in visual +vnoremap gv :call VisualSelection('gv', '') + +map nn :NERDTreeToggle +map o :BufExplorer + +"" CtrlP +" Quickly find and open a recently opened file +" let g:ctrlp_map = '' +map :CtrlPBuffer +map j :CtrlP +map b :CtrlPBuffer +map f :CtrlPMRUFiles +map t :CtrlPTag + + +let s:uname='' +let s:uname = system('uname | tr -d "\n"') " Get platform name (stripping the trailing newline) +if s:uname == "Darwin" + "" Mac specific stuff +elseif s:uname == "linux" + "" Linux specific stuff + " Wayland clipboard fix https://github.com/vim/vim/issues/5157 + xnoremap "+y :call system("wl-copy", @") + nnoremap "+p :let @"=substitute(system("wl-paste --no-newline"), '', '', 'g')p + xnoremap "*y :call system("wl-copy --primary", @") + nnoremap "*p :let @"=substitute(system("wl-paste --no-newline --primary"), '', '', 'g')p +else + "" Unkown platform +endif + +" Add shortcuts to yank/paste to unnamed/unnamedplus clipboards +noremap y "*y +noremap p "*p +noremap Y "+y +noremap P "+p + + +let g:ctrlp_custom_ignore = { + \ 'dir': '\v(target|build|dist|.venv)$', + \ 'file': '\v\.(exe|so|dll)$', + \ 'link': 'some_bad_symbolic_links', + \ } +let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard'] + +" A friggin python breakpoint. Invoke with @b "FIXME: make this decent +let @b = 'A breakpoint()€ýajkj0' + + +""" Helper Functions +function! WinZoomToggle() abort + if ! exists('w:WinZoomIsZoomed') + let w:WinZoomIsZoomed = 0 + endif + if w:WinZoomIsZoomed == 0 + let w:WinZoomOldWidth = winwidth(0) + let w:WinZoomOldHeight = winheight(0) + wincmd _ + wincmd | + let w:WinZoomIsZoomed = 1 + elseif w:WinZoomIsZoomed == 1 + execute "resize " . w:WinZoomOldHeight + execute "vertical resize " . w:WinZoomOldWidth + let w:WinZoomIsZoomed = 0 + endif +endfunction + + +" Highlight all instances of word under cursor, when idle. +" Type z/ to toggle highlighting on/off. +nnoremap z/ :if AutoHighlightToggle()set hlsendif +function! AutoHighlightToggle() + let @/ = '' + if exists('#auto_highlight') + au! auto_highlight + augroup! auto_highlight + setl updatetime=4000 + echo 'Highlight current word: off' + return 0 + else + augroup auto_highlight + au! + au CursorHold * let @/ = '\V\<'.escape(expand(''), '\').'\>' + augroup end + setl updatetime=500 + echo 'Highlight current word: ON' + return 1 + endif +endfunction + +" Don't close window, when deleting a buffer +command! Bclose call BufcloseCloseIt() +function! BufcloseCloseIt() + let l:currentBufNum = bufnr("%") + let l:alternateBufNum = bufnr("#") + + if buflisted(l:alternateBufNum) + buffer # + else + bnext + endif + + if bufnr("%") == l:currentBufNum + new + endif + + if buflisted(l:currentBufNum) + execute("bdelete! ".l:currentBufNum) + endif +endfunction + +function! CmdLine(str) + call feedkeys(":" . a:str) +endfunction + +function! VisualSelection(direction, extra_filter) range + let l:saved_reg = @" + execute "normal! vgvy" + + let l:pattern = escape(@", "\\/.*'$^~[]") + let l:pattern = substitute(l:pattern, "\n$", "", "") + + if a:direction == 'gv' + call CmdLine("Ack '" . l:pattern . "' " ) + elseif a:direction == 'replace' + call CmdLine("%s" . '/'. l:pattern . '/') + endif + + let @/ = l:pattern + let @" = l:saved_reg +endfunction + +function! GitStatus() + let [a,m,r] = GitGutterGetHunkSummary() + return printf('+%d ~%d -%d', a, m, r) +endfunction