Seth Milliken — Words, Thoughts, Tech

categories:   allgeneralreadtech
tags:   blog code java netsurf personal photos read scrabble server tech vim webobjects writing
Vimperator Form Field Editing [Permalink] Tue Mar 16 20:05:32 PDT 2010 [ tech/ ]

I have been using FireFox as my primary browser for quite a while now. What held me back from switching initially were two things: 1) unacceptably poor non-native widgets, which have since improved dramatically and 2) no support for the Mac OS X Keychain, which is now available via the Keychain Services Integration extension. But eventually my desire for vim keybindings everywhere pushed me to switch despite these shortcomings. The vimperator FireFox extension allows for entirely keyboard-based browsing, using bindings similar to vim. And even better, it facilitates form field editing using vim via external editor support. So when I want to edit a form field, I type either "gi" (to enter the field) or "f#" (where # is the QuickHint mode number associated with the field; useful if there are multiple fields on the page) then hit Control-i. This creates a new tab with a buffer for that field in an existing instance of MacVim which is always running in the same Space as my browser, so it comes up almost instantaneously. I edit the contents of this buffer using all the goodness of native vim and then type ZZ. Thanks to a couple of autocommands in my .vimrc, this saves the buffer, saves a copy of its contents in a timestamped archive file, closes the buffer, and then hides MacVim, leaving FireFox active with the text I just wrote inserted in the form field ready to submit.

Here are the requisite pieces of the puzzle:

.vimperatorcc

This is the vimperator configuration file. You need to add a line to set your external editor to the script that opens MacVim.
set editor="~/bin/vimperator"

shell

Make a symbolic link to your mvim script so that the script can detect the context it's running in.
ln -s ~/bin/mvim ~/bin/vimperator

mvim

This is the mvim script that comes bundled with MacVim, moved to ~/bin and modified. Add this bit to the 'case "$name" in' statement:
	*vimperator)
		opts="$opts --remote-tab-wait-silent"
		gui=true
		;;

.vimrc

Next, a couple of additions to the vim configuration file to make ZZ save the contents to an archive, close the buffer, and return FireFox to the foreground.
augroup Vimperator
	au! BufRead vimperator-* nnoremap <buffer> ZZ :call FormFieldArchive() \| :silent write \| :bd \| :macaction hide:<CR>
	au BufRead vimperator-* imap <buffer> ZZ <Esc>ZZ
augroup END
Finally, here is the function that saves a copy of the form field contents to an archive file, complete with timestamp and url:
function! FormFieldArchive()
	let l:contents = getbufline("%", 1, "$")
	let l:filepath = expand("%")
	let l:filename = expand("%:t:r")
	let l:formfielddir = $HOME . "/webforms/"
	let l:currentdate = TimestampText('date')
	let l:entry = l:formfielddir . l:currentdate . ".txt"
	let l:entryexists = filereadable(l:entry)
	exec "split " . l:entry
	if l:entryexists
		normal Go
		normal o
		exec "call setline(\".\", \"" . TimestampText('time') . "\")" 
	else
		exec "call setline(\".\", \"" . TimestampText('journal') . "\")" 
		exec "silent !svn add " . l:entry
	endif
	normal o
	exec "call setline(\".\", \"" . l:filename . "\")" 
	normal o
	exec "call setline(\".\", " . string(l:contents) . ")" 
	write
	bd
endfunction
This will create a new file with the current date, e.g. "2010-03-15.txt", if it doesn't already exist. If it does exist, it will add the entry to the end of the file separated by a timestamp. TimestampText() is just a convenience function I wrote that returns a timestamp in various strftime() formats.

Posted by: Seth Milliken Tags: tech, vim
0 ]  Comments
snip snip [Permalink] Wed Oct 20 00:38:22 PDT 2004 [ general/ ]

During a dream last night I devised a technique to cut and paste between dreams and reality. I cleverly pasted the description of this technique on the shared dream/reality clipboard. I was thwarted by the fact that alarm clock snooze bars clear the clipboard.

Posted by: Seth Milliken Tags: personal, tech
2 ]  Comments
first post from netnewswire [Permalink] Sun Jun 01 00:03:24 PDT 2003 [ general/ ]

NetNewsWire now supports Moveable Type. This is a test of that functionality. If it works well, maybe I'll post more. On a completely unrelated note, I've been experimenting with leaving Sticky Keys turned on to see if I can improve the state of my wrists which have both taken a turn for the worse due to various combinations of foosball, swing dancing, playing guitar, and typing.

Posted by: Seth Milliken Tags: blog, tech
1 ]  Comment
ssh tunneling rocks [Permalink] Sun Mar 30 00:37:31 PST 2003 [ general/ ]

ssh tunneling is a great lightweight vpn stand-in. You do need three things: an account on a externally accessible machine that is on the same internal network as the machine you're tunneling to, the IP address of the machine you're tunneling, and knowledge of what port(s) you need to forward. The syntax is: ssh <your account>@<externally accessible machine> -L <local port>:<internal target host>:<port to forward>

Posted by: Seth Milliken Tags: tech
0 ]  Comments
 
September 2010
Sun  Mon  Tue  Wed  Thu  Fri  Sat 
   1234
567891011
12131415161718
19202122232425
2627282930  
       
<  Aug   Sep    Oct  >

Links
Contact Information
(415) 710-1357 Cell

5027 NE 19th Ave, Apt B
Portland, OR 97211

<seth@araxia.net> PGP
RSS Feed RSS2 Feed RDF Feed   Powered By blojsom   categories: //general//read//tech//templates/

html hits: 2482