From cefe08df4ba667c36d0de97e33566e725aae200e Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Sat, 30 Dec 2017 23:11:36 -0600 Subject: [PATCH] .vimrc: Add some new commands, misc cleanup --- .vim/bundle/whitespace/plugin/whitespace.vim | 9 -- .vimrc | 88 ++++++++++++++------ 2 files changed, 62 insertions(+), 35 deletions(-) delete mode 100644 .vim/bundle/whitespace/plugin/whitespace.vim diff --git a/.vim/bundle/whitespace/plugin/whitespace.vim b/.vim/bundle/whitespace/plugin/whitespace.vim deleted file mode 100644 index bd0bfe2..0000000 --- a/.vim/bundle/whitespace/plugin/whitespace.vim +++ /dev/null @@ -1,9 +0,0 @@ -" thanks to http://vimcasts.org/e/4 -function! whitespace#strip_trailing() - let previous_search=@/ - let previous_cursor_line=line('.') - let previous_cursor_column=col('.') - %s/\s\+$//e - let @/=previous_search - call cursor(previous_cursor_line, previous_cursor_column) -endfunction diff --git a/.vimrc b/.vimrc index 14a08f5..0269b4f 100644 --- a/.vimrc +++ b/.vimrc @@ -16,6 +16,7 @@ set autoread " reload files (no local changes only) " --------------------------------------------------------------------------- call plug#begin('~/.vim/plugged') + Plug 'altercation/vim-colors-solarized' Plug 'kien/ctrlp.vim' Plug 'kopischke/vim-fetch' @@ -30,9 +31,10 @@ Plug 'tpope/vim-surround' Plug 'tpope/vim-unimpaired' Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' + Plug '~/.vim/bundle/matchit' Plug '~/.vim/bundle/mumps' -Plug '~/.vim/bundle/whitespace' + call plug#end() " Automatic install @@ -288,6 +290,13 @@ nmap gp :Gpush " cd to the directory containing the file in the buffer nmap cd :lcd %:h " toggle diffmode for a buffer +function! DiffToggle() + if &diff + diffoff + else + diffthis + endif +endfunction nmap df :call DiffToggle() " quickly edit/reload vimrc nmap ev :edit $MYVIMRC @@ -295,7 +304,7 @@ nmap sv :source $MYVIMRC " find merge conflict markers nmap fc /\v^[<=>]{7}( .*\|$) " toggle hlsearch -nmap hs :set hlsearch! hlsearch? +nmap hls :set hlsearch! hlsearch? " upper/lower word nmap wu mQviwU`Q nmap wl mQviwu`Q @@ -304,8 +313,6 @@ nmap wU mQgewvU`Q nmap wL mQgewvu`Q " smart paste - enable paste-mode and paste contents of system clipboard map p :set pasteo"*]p:set nopaste -" strip all trailing whitespace in file -nmap sw :call whitespace#strip_trailing() " toggle spell-check nmap sp :setlocal spell! spell? " set text wrapping toggles @@ -319,34 +326,63 @@ nmap tag :split :exec("tag ".expand("")) " Functions " -------------------------------------------------------------------------- -" Toggle diff-mode -function! DiffToggle() - if &diff - diffoff +" :Redir +" Run vim command, redirect output to a scratch buffer +function! s:redir(cmd) + redir => message + silent execute a:cmd + redir END + if empty(message) + echoerr "no output" else - diffthis + new + setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified + silent! put=message + silent! g/^s*$/d endif endfunction +command! -nargs=+ -complete=command Redir call s:redir() +" :ListLeaders " Make a scratch buffer with all of the leader keybindings. -" Adapted from http://ctoomey.com/posts/an-incremental-approach-to-vim/ -function! ListLeaders() - silent! redir @b - silent! nmap - silent! redir END - silent! new - silent! set buftype=nofile - silent! set bufhidden=hide - silent! setlocal noswapfile - silent! put! b - silent! g/^s*$/d - silent! %s/^.*,// - silent! normal ggVg - silent! sort - silent! let lines = getline(1,"$") - silent! normal +command! ListLeaders :call s:redir('nmap ') + +" :Todo +" Use `git grep` to search for to-do comments, add matches to qflist +function! s:todo() abort + let entries = [] + for cmd in ['git grep -nI -e TODO -e FIXME -e XXX 2> /dev/null', + \ 'grep -rnI -e TODO -e FIXME -e XXX * 2> /dev/null'] + let lines = split(system(cmd), '\n') + if v:shell_error != 0 | continue | endif + for line in lines + let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3] + call add(entries, { 'filename': fname, 'lnum': lno, 'text': text }) + endfor + break + endfor + + if !empty(entries) + call setqflist(entries) + copen + endif +endfunction +command! Todo call s:todo() + +" :StripTrailingWhitespace +" Strip trailing whitespace +function! StripTrailingWhitespace() + " preparation: save last search, and cursor position. + let _s=@/ + let l = line(".") + let c = col(".") + " do the business + %s/\s\+$//e + " clean up: restore previous search history, and cursor position + let @/=_s + call cursor(l, c) endfunction -command! ListLeaders :call ListLeaders() +command! StripTrailingWhitespace call StripTrailingWhitespace() " --------------------------------------------------------------------------- " Auto Commands / File Types -- 2.47.1