Created
August 24, 2010 02:54
-
-
Save bootleq/546828 to your computer and use it in GitHub Desktop.
[.vimrc] make bookmarklet @see http://bootleq.blogspot.com/2010/08/vim-function-javascript-bookmarklet.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
command! -nargs=* Bookmarklet call Bookmarklet(<f-args>) | |
fun! Bookmarklet(...) | |
let result = JsCompress(0, 0, '--compilation_level=WHITESPACE_ONLY') | |
if len(getqflist()) == 0 && strlen(result) > 0 | |
let reuse_win = 0 | |
for winnr in tabpagebuflist(tabpagenr()) | |
if bufname(winnr) == '[Bookmarklet]' | |
exec winnr . 'wincmd w' | |
let reuse_win = winnr | |
endif | |
endfor | |
if ! reuse_win | |
exec 'belowright 5new [Bookmarklet]' | |
setlocal noswapfile bufhidden=wipe winfixheight filetype=javascript | |
endif | |
let result = substitute(result, '[\n]', '', '') | |
setlocal buftype= | |
call setline(1, 'javascript:(function(){' . result . '})();') | |
if has('ruby') | |
ruby require("uri"); VIM::Buffer.current.line = URI.escape(VIM::Buffer.current.line); | |
else | |
echohl WarningMsg | echomsg "No ruby support. Can't do URI encoding." | echohl None | |
endif | |
setlocal buftype=nofile | |
endif | |
endf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment