├── README ├── v └── v.1 /README: -------------------------------------------------------------------------------- 1 | V(1) User Commands V(1) 2 | 3 | 4 | 5 | NAME 6 | v - z for vim 7 | 8 | 9 | SYNOPSIS 10 | v [-a] [-c] [-l] [-[0-9]] [--debug] [--help] [regex1 regex2 ... regexn] 11 | 12 | 13 | AVAILABILITY 14 | bash, vim 15 | 16 | 17 | INSTALLATION 18 | Put v somewhere in $PATH (e.g. /usr/local/bin/). 19 | For the manual page, put v.1 somewhere in $MANPATH (e.g. 20 | /usr/local/man/man1/). 21 | 22 | 23 | DESCRIPTION 24 | v uses viminfo's list of recently edited files to open one quickly no 25 | matter where you are in the filesystem. 26 | 27 | By default, it will open the most recently edited file matching all of 28 | the provided regular expressions. 29 | 30 | 31 | OPTIONS 32 | -a don't skip deleted files 33 | -c restrict matches to subdirectories of the current dir 34 | -l when multiple matches, show a list 35 | -[0-9] edit nth most recent file 36 | --debug dry run 37 | --help show a brief help message 38 | 39 | 40 | EXAMPLES 41 | v list and choose from all files 42 | v -0 reopen most recently edited file 43 | v foo bar edit first file matching foo and bar 44 | v -c foo bar choose files in current dir matching foo and bar 45 | v -l foo bar list and choose files matching foo and bar 46 | 47 | 48 | NOTES 49 | Shell variables, such as $, must be escaped if used in regular expres- 50 | sions. 51 | 52 | Behavior 53 | The default behavior is to open the most recent file that matches the 54 | search terms, even if there are multiple matches. 55 | 56 | You may find it useful to alias vl='v -l'. When there are multiple 57 | matches, this will prompt for a choice, rather than editing the first 58 | match. The author is still not sure which behavior should be the 59 | default, and has chosen one provisionally. 60 | 61 | 62 | SEE ALSO 63 | vim(1), regex(7) 64 | 65 | Please file bugs at https://github.com/rupa/v/ 66 | 67 | 68 | 69 | v February 2011 V(1) 70 | -------------------------------------------------------------------------------- /v: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) 2011 rupa deadwyler. Licensed under the WTFPL license, Version 2 3 | 4 | [ "$vim" ] || vim=vim 5 | [ $viminfo ] || viminfo=~/.viminfo 6 | 7 | usage="$(basename $0) [-a] [-c] [-l] [-[0-9]] [--debug] [--help] [regexes]" 8 | 9 | [ $1 ] || list=1 10 | 11 | _pwd="$(command pwd)" 12 | 13 | fnd=() 14 | for x; do case $x in 15 | -a) deleted=1;; 16 | -c) subdir=1; shift;; 17 | -l) list=1;; 18 | -[0-9]) edit=${x:1}; shift;; 19 | --help) echo $usage; exit;; 20 | --debug) vim=echo;; 21 | --) shift; fnd+=("$@"); break;; 22 | *) fnd+=("$x");; 23 | esac; shift; done 24 | set -- "${fnd[@]}" 25 | 26 | [ -f "$1" ] && { 27 | $vim "$1" 28 | exit 29 | } 30 | 31 | while IFS=" " read line; do 32 | [ "${line:0:1}" = ">" ] || continue 33 | fl=${line:2} 34 | _fl="${fl/~\//$HOME/}" 35 | [ -f "$_fl" -o "$deleted" ] || continue 36 | match=1 37 | for x; do 38 | [[ "$fl" =~ $x ]] || match= 39 | done 40 | [ "$subdir" ] && { 41 | case "$_fl" in 42 | $_pwd*);; 43 | *) match=;; 44 | esac 45 | } 46 | [ "$match" ] || continue 47 | i=$((i+1)) 48 | files[$i]="$fl" 49 | done < "$viminfo" 50 | 51 | if [ "$edit" ]; then 52 | resp=${files[$((edit+1))]} 53 | elif [ "$i" = 1 -o "$list" = "" ]; then 54 | resp=${files[1]} 55 | elif [ "$i" ]; then 56 | while [ $i -gt 0 ]; do 57 | echo -e "$((i-1))\t${files[$i]}" 58 | i=$((i-1)) 59 | done 60 | read -p '> ' CHOICE 61 | [ "$CHOICE" ] && resp=${files[$((CHOICE+1))]} 62 | fi 63 | 64 | [ "$resp" ] || exit 65 | $vim "${resp/\~/$HOME}" 66 | -------------------------------------------------------------------------------- /v.1: -------------------------------------------------------------------------------- 1 | .TH V "1" "February 2011" "v" "User Commands" 2 | 3 | .SH NAME 4 | v \- z for vim 5 | 6 | .SH SYNOPSIS 7 | v [\-a] [\-c] [\-l] [\-[0\-9]] [\-\-debug] [\-\-help] [regex1 regex2 ... regexn] 8 | 9 | .SH AVAILABILITY 10 | bash, vim 11 | 12 | .SH INSTALLATION 13 | Put \fBv\fR somewhere in $PATH (e.g. /usr/local/bin/). 14 | .br 15 | For the manual page, put \fBv.1\fR somewhere in $MANPATH (e.g. 16 | /usr/local/man/man1/). 17 | 18 | .SH DESCRIPTION 19 | \fBv\fR uses viminfo's list of recently edited files to open one quickly no 20 | matter where you are in the filesystem. 21 | .P 22 | By default, it will open the most recently edited file matching all of the 23 | provided regular expressions. 24 | 25 | .SH OPTIONS 26 | \fB\-a\fR don't skip deleted files 27 | .br 28 | \fB\-c\fR restrict matches to subdirectories of the current dir 29 | .br 30 | \fB\-l\fR when multiple matches, show a list 31 | .br 32 | \fB\-[0\-9]\fR edit nth most recent file 33 | .br 34 | \fB\--debug\fR dry run 35 | .br 36 | \fB\--help\fR show a brief help message 37 | 38 | .SH EXAMPLES 39 | \fBv\fR list and choose from all files 40 | .br 41 | \fBv -0\fR reopen most recently edited file 42 | .br 43 | \fBv foo bar\fR edit first file matching foo and bar 44 | .br 45 | \fBv -c foo bar\fR choose files in current dir matching foo and bar 46 | .br 47 | \fBv -l foo bar\fR list and choose files matching foo and bar 48 | 49 | .SH NOTES 50 | Shell variables, such as $, must be escaped if used in regular expressions. 51 | 52 | \fBBehavior\fR 53 | .br 54 | The default behavior is to open the most recent file that matches the search 55 | terms, even if there are multiple matches. 56 | 57 | You may find it useful to alias vl='v -l'. When there are multiple matches, 58 | this will prompt for a choice, rather than editing the first match. The author 59 | is still not sure which behavior should be the default, and has chosen one 60 | provisionally. 61 | 62 | .SH SEE ALSO 63 | vim(1), regex(7) 64 | .P 65 | Please file bugs at https://github.com/rupa/v/ 66 | --------------------------------------------------------------------------------