aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2012-02-19 02:23:35 +1300
committerTom Ryder <tom@sanctum.geek.nz>2012-02-19 02:23:35 +1300
commitc0c74d76db7f4999f1c62978ece0f87eafd47dd8 (patch)
tree73522951d1798fc8b8aae578058fb49070c2fc0f
downloadvim-vawk-c0c74d76db7f4999f1c62978ece0f87eafd47dd8.tar.gz
vim-vawk-c0c74d76db7f4999f1c62978ece0f87eafd47dd8.zip
First commit.
-rw-r--r--README21
-rw-r--r--doc/kimble.txt50
-rw-r--r--doc/tags18
-rw-r--r--doc/vawk.txt32
-rw-r--r--plugin/vawk.vim85
5 files changed, 206 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..7f337f1
--- /dev/null
+++ b/README
@@ -0,0 +1,21 @@
+vawk - Awk wrapper and shorthand functions
+
+Author: Tom Ryder <tom@sanctum.geek.nz>
+License: Same terms as Vim itself
+
+Work with Awk-friendly columnar data. Provides a simple wrapper to Awk as well
+as a few useful functions for chopping and changing columnar data. Requires
+Awk to be installed, of course.
+
+All commands accept a range which defaults to the entire file. For commands
+which accept columns, these should be comma-separated; you can also use ranges
+as a shorthand, e.g. 1,3-6,10,11.
+
+:[range]Vawk <script> Run an arbitrary Awk script.
+
+:[range]Vcut <columns> Delete the columns specified.
+
+:[range]Vonly <columns> Delete all columns except for the specified.
+
+g:vawksep The record separator to use for the data.
+ Defaults to Awk's usual whitespace delimiting.
diff --git a/doc/kimble.txt b/doc/kimble.txt
new file mode 100644
index 0000000..65d6d72
--- /dev/null
+++ b/doc/kimble.txt
@@ -0,0 +1,50 @@
+*kimble.txt* Simple Subversion wrappers
+
+Author: Tom Ryder <tom@sanctum.geek.nz>
+License: Same terms as Vim itself (see |license|)
+
+DESCRIPTION *kimble*
+
+Some simple Subversion command wrappers to ease the pain of developing with
+Subversion as a VCS. This is very experimental and will be developed more as I
+have time and/or inclination.
+
+COMMANDS *kimble-commands*
+
+:Sstatus *kimble-:Sstatus*
+ Runs 'svn status' and prints its output in a scratch
+ buffer at the bottom of the screen.
+
+:Scommit *kimble-:Scommit*
+ Runs 'svn commit' and prints its output in a scratch
+ buffer at the bottom of the screen.
+
+:Sinfo *kimble-:Sinfo*
+ Runs 'svn info' and prints its output in a scratch
+ buffer at the bottom of the screen.
+
+:Supdate *kimble-:Supdate*
+ Runs 'svn update' and prints its output in a scratch
+ buffer at the bottom of the screen.
+
+:Sadd *kimble-:Sadd*
+ Runs 'svn add' and prints its output in a scratch
+ buffer at the bottom of the screen. Accepts an optional
+ argument, otherwise assumes you mean the current file.
+
+:Sblame *kimble-:Sblame*
+ Runs 'svn blame' and prints its output in a scratch
+ buffer at the left of the screen. Accepts an optional
+ argument, otherwise assumes you mean the current file.
+
+:Sdiff *kimble-:Sdiff*
+ Runs 'svn diff' and prints its output in a scratch
+ buffer at the bottom of the screen. Accepts an optional
+ argument, otherwise assumes you mean the current file.
+
+:Slog *kimble-:Slog*
+ Runs 'svn log' and prints its output in a scratch
+ buffer at the bottom of the screen. Accepts an optional
+ argument, otherwise assumes you mean the current file.
+
+ vim:tw=78:et:ft=help:norl:
diff --git a/doc/tags b/doc/tags
new file mode 100644
index 0000000..82046ea
--- /dev/null
+++ b/doc/tags
@@ -0,0 +1,18 @@
+:Vawk vawk.txt /*:Vawk*
+:Vcut vawk.txt /*:Vcut*
+:Vonly vawk.txt /*:Vonly*
+kimble kimble.txt /*kimble*
+kimble-:Sadd kimble.txt /*kimble-:Sadd*
+kimble-:Sblame kimble.txt /*kimble-:Sblame*
+kimble-:Scommit kimble.txt /*kimble-:Scommit*
+kimble-:Sdiff kimble.txt /*kimble-:Sdiff*
+kimble-:Sinfo kimble.txt /*kimble-:Sinfo*
+kimble-:Slog kimble.txt /*kimble-:Slog*
+kimble-:Sstatus kimble.txt /*kimble-:Sstatus*
+kimble-:Supdate kimble.txt /*kimble-:Supdate*
+kimble-commands kimble.txt /*kimble-commands*
+kimble.txt kimble.txt /*kimble.txt*
+vawk vawk.txt /*vawk*
+vawk-commands vawk.txt /*vawk-commands*
+vawk-variables vawk.txt /*vawk-variables*
+vawk.txt vawk.txt /*vawk.txt*
diff --git a/doc/vawk.txt b/doc/vawk.txt
new file mode 100644
index 0000000..ec34be3
--- /dev/null
+++ b/doc/vawk.txt
@@ -0,0 +1,32 @@
+*vawk.txt* Awk wrapper and shorthand functions
+
+Author: Tom Ryder <tom@sanctum.geek.nz>
+License: Same terms as Vim itself (see |license|)
+
+DESCRIPTION *vawk*
+
+Work with Awk-friendly columnar data. Provides a simple wrapper to Awk as well
+as a few useful functions for chopping and changing columnar data. Requires
+Awk to be installed, of course.
+
+COMMANDS *vawk-commands*
+
+All commands accept a range which defaults to the entire file. For commands
+which accept columns, these should be comma-separated; you can also use ranges
+as a shorthand, e.g. 1,3-6,10,11.
+
+ *:Vawk*
+:[range]Vawk <script> Run an arbitrary Awk script.
+
+ *:Vcut*
+:[range]Vcut <columns> Delete the columns specified.
+
+ *:Vonly*
+:[range]Vonly <columns> Delete all columns except for the specified.
+
+VARIABLES *vawk-variables*
+
+g:vawksep The record separator to use for the data.
+ Defaults to Awk's usual whitespace delimiting.
+
+ vim:tw=78:et:ft=help:norl:
diff --git a/plugin/vawk.vim b/plugin/vawk.vim
new file mode 100644
index 0000000..49b1107
--- /dev/null
+++ b/plugin/vawk.vim
@@ -0,0 +1,85 @@
+"
+" vawk.vim - Awk wrapper and shorthand functions
+"
+" Maintainer: Tom Ryder <http://www.sanctum.geek.nz/>
+"
+
+"
+" Wrapper to prevent overloading and signal our presence, and check we're not
+" in compatible mode or running a version of Vim that's too old.
+"
+if exists('g:loaded_vawk') || &compatible || v:version < 700
+ finish
+endif
+let g:loaded_vawk = 1
+
+"
+" Default separator is blank, which will inspire Awk to just use whitespace,
+" which will be what people want most of the time.
+"
+let g:vawksep = ''
+
+"
+" Run an arbitrary Awk command on the selected text.
+"
+function! s:Vawk(start, end, cmdline)
+ let l:runline = a:cmdline
+ let l:runopts = []
+ if g:vawksep != ''
+ let l:sep = g:vawksep == '!' ? '\!' : g:vawksep
+ let l:runopts += ['-F ' . shellescape(l:sep)]
+ endif
+ execute a:start . ',' . a:end . '!awk ' . join(l:runopts, ' ') . ' ' shellescape(l:runline)
+endfunction
+
+"
+" Abstracted function for Vonly and Vcut.
+"
+function! s:Vparse(cols)
+ let l:collist = []
+ for l:col in split(a:cols, ',')
+ if l:col =~ '\m^[0-9]\+$'
+ let l:collist += [l:col]
+ elseif l:col =~ '\m^[0-9]\+-[0-9]\+$'
+ let l:lower = matchstr(l:col, '\m[0-9]\+', 0, 1)
+ let l:upper = matchstr(l:col, '\m[0-9]\+', 0, 2)
+ if l:lower < l:upper
+ let l:collist += range(l:lower, l:upper)
+ endif
+ endif
+ endfor
+ return l:collist
+endfunction
+
+"
+" Abstract filter for Vonly and Vcut.
+"
+function! s:Vfilter(start, end, cols, equiv, logic)
+ let l:collist = s:Vparse(a:cols)
+ let l:cmdline = '{for (i = 1; i <= NF; i++) {'
+ let l:cmdline .= 'if (i ' . a:equiv . ' ' . join(l:collist, ' ' . a:logic . ' i ' . a:equiv . ' ') . ') '
+ let l:cmdline .= 'printf("\%s\%s", $i, (i \!= NF) ? FS : "")};print ""}'
+ call s:Vawk(a:start, a:end, l:cmdline)
+endfunction
+
+"
+" Print only the specified columns.
+"
+function! s:Vonly(start, end, cols)
+ call s:Vfilter(a:start, a:end, a:cols, '==', '||')
+endfunction
+
+"
+" Print everything but the specified columns.
+"
+function! s:Vcut(start, end, cols)
+ call s:Vfilter(a:start, a:end, a:cols, '\!=', '&&')
+endfunction
+
+"
+" Define commands.
+"
+command! -range=% -nargs=* Vawk call <SID>Vawk(<line1>, <line2>, <q-args>)
+command! -range=% -nargs=* Vcut call <SID>Vcut(<line1>, <line2>, <f-args>)
+command! -range=% -nargs=* Vonly call <SID>Vonly(<line1>, <line2>, <f-args>)
+