Re: [cream] integrating and using WoC
Cream is a free, easy-to-use configuration of the Vim text editor
Brought to you by:
digitect
From: Steve H. <dig...@da...> - 2008-02-07 05:07:07
|
On Wed, 2008-02-06 at 16:19 -0500, Dave (My-IOP) wrote: > On Feb 6, 2008 1:53 PM, Steve Hall <digitect dancingpaper com> wrote: > > From: "Dave (My-IOP)", Tue, February 05, 2008 11:41 pm > > > > > > How would I bind these commands to shortcut keys in Cream? > > > > Cream relies on a slightly more complex method of mapping to keep > > everything portable. Essentially EVERYTHING is in a function, and > > all keys map to a function call. Using your statements above: > > > > function! GPG_clearsign() > > %!gpg --clearsign > > endfunction > > imap <silent> <c><s> <C-b>:call MyFunction()<CR> > > vmap <silent> <c><s> :<C-u>call MyFunction()<CR> > > > > Make sense? > > The use of a function call makes perfect sense. (The details of the > mappings don't.) Here's what I get out of the above: > some_stuff_I_dont_understand:call GPG_clearsign()<CR> Sorry, totally wrong mappings above, they should be: imap <silent> cs <C-b>:call GPG_clearsign()<CR> vmap <silent> cs :<C-u>call GPG_clearsign()<CR> > I looked up imap and vmap. I think imap maps a key combination in > insert mode, and vmap does the same in visual mode, right? Correct. > <C-b> -- I see you said, For insert mode, "<C-b>:" drops to command > line for one call. That leaves me wondering how the selected text is > passed to gpg and back... <C-b> (Ctrl+B) is a remap of Vim's Ctrl+O. We want to use that for File > Open, since it is a very standard GUI convention. In the mapping above, the keys "cs" are mapped to a single command line entry: :call MyFunction() The keys to get to the command line (Ctrl+B) and the key to enter this (<CR>) are included in the mapping. The command we enter is a call to a function, one that we defined as function! GPG_clearsign() %!gpg --clearsign endfunction There is really only one logic line here, the middle one. It is based on the "!" command, which essentially calls any system command available to the OS. Thus at the command line you can do :!dir and Vim will echo the return of that system command result. In your case, you are trying to call a command "gpg" with an argument "--clearsign". The last little bit is the "%". In the context of a command, this is the range, the area in the file that should be passed to the call. You can use 3,5 to pass those three lines, or a symbol like "%" which means the entire file (:help :%). > At this early stage of learning Vim/Cream I think I'm getting in too > deep. I'm trying to learn Linux, Vim, gpg and a bunch of other > productivity apps all at the same time so I can switch from Windows > immediately. It's hard to learn everything at once, and I think its safe to say that implementing gpg in Cream might not be the easiest thing to do. :) > It would help a lot if I could just start using Cream and learn more > about the underlying power of Vim over time. To get started, I just > need two customizations: > 1. decrypt/encrypt selected text via mapped shortcut keys using gpg > and my default gpg key (or a gpg key specified in the script). More about this follows... > 2. open URLs in default browser (which was working until I started > messing with the encryption) Hopefully that works now, I did some more tweaking with it today on Windows. > The encryption stuff is important because I'm maintaining financial > info for relatives. I couldn't find Linux apps to replace several of > my Windows apps, but then it occurred to me that the above two > customizations I can do it all in Cream and I'll be set to ditch > Windows. Do you really need gpg, or would a simpler form of obfuscation suffice? Vim has the :X option, which works for me. You just need to remember to :set key= when you're done, or everything will have it. Cream also has the Encrypt add-ons which can obfuscate a bit, too. > As far as the key bindings, are Ctrl-E (encrypt selected text) and > Ctrl-D (decrypt selected text) good choices? How would the code look > if I were using those key bindings? That's the easy part, a little menuing sub-routine can even present all the options from one key. (See the Email Prettifier add-on as an example.) > I would be very appreciative if someone could offer a complete > script to implement these two customizations! I realize that's > asking a lot. What can I do in return? Thanks. Well, I hacked away on this for a couple of hours with no luck. I'm getting closer, but gpg doesn't appear able to read streams/redirection. So I tried a whole system of saving the selection to a tempfile, encrypt that, and read it back in to paste it over the original selection area. Not elegant, but it should work in theory. For now, check out :help encryption and see if there's anything useful there. -- Steve Hall [ digitect dancingpaper com ] :: Cream... usability for Vim :: http://cream.sourceforge.net |