Thread: 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-06 13:16:13
|
From: "Dave (My-IOP)", Tue, February 05, 2008 11:26 pm > > I am hoping for a solution more like the text encyrption plugin for > gedit. With that plugin, I can create a text file like what is shown > below by highlighting the lines I want to encrypt and selecting a > menu command. I can decrypt just by selecting the text and picking > decrypt from the edit menu. This is what I would like to do in Cream > (but binding the command to a key combination would be ideal). Any > suggestions for me? Thanks. The Encrypt add-ons were a beginning on this. Unfortunately, Vim does not have the horsepower to do real encryption so you'd need to pass the values through a command line app. Look at the algorithmic one for an idea. (Although I notice that on Windows it isn't properly "encrypting", probably due to a minor selection alignment error.) -- Steve Hall [ digitect dancingpaper com ] :: Cream... usability for Vim :: http://cream.sourceforge.net |
From: Steve H. <dig...@da...> - 2008-02-06 18:53:10
|
From: "Dave (My-IOP)", Tue, February 05, 2008 11:41 pm > > I just found this info that might address my last question: > http://www.savvyadmin.com/2007/10/08/perform-gnupg-functions-within-vim/#comments > > ---- Simply add the following to your "~/.vimrc" file: > > :cmap cs %!gpg --clearsign > :cmap es %!gpg -seat > :cmap ee %!gpg -eat > :cmap de %!gpg -d > > Is ':set textwidth=70' required for gpg in this situation? I wouldn't think so, at least I wouldn't design it that way myself. > 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? I would recommend not using typical characters though, by doing this Vim will hesitate &timeoutlen (Cream default is 300ms) every time a "c" is typed. Just to clarify about mappings, the idea is that for insert mode, "<C-b>:" drops to command line for one call. For visual mappings ":<C-u>" drops to the command line, with the range being removed by the <C-u>. > Maybe I could use this together with the 'set noswapfile' command > for a fairly complete solution. Would it be as simple as the code > shown below? > > augroup encrypted > au! > " First make sure nothing is written to ~/.viminfo while editing an > encrypted file. > autocmd BufReadPre,FileReadPre,BufNewFile *.gpg,*.asc set > viminfo= > " We don't want a swap file, as it writes unencrypted data to disk. > autocmd BufReadPre,FileReadPre,BufNewFile *.gpg,*.asc set > noswapfile > augroup END I think that's about it. Cream has to manage mappings and modes with a bit of discipline since some Vim keys act differently in normal mode than insert mode (like <Esc>). But everything else is straight Vim. > I realize I'm asking a lot of newbie questions. Hope it isn't > irritating. I appreciate the help! No problem at all, I'm always happy to help anyone interested in understanding the project, getting it to work for them, and being able to implement features that others may be interested in. -- Steve Hall [ digitect dancingpaper com ] :: Cream... usability for Vim :: http://cream.sourceforge.net |
From: Dave (My-IOP) <da...@my...> - 2008-02-06 21:19:51
|
On Feb 6, 2008 1:53 PM, Steve Hall <dig...@da...> 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> 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? For <silent> I see that it does execute {command} silently - makes sense. For <c><s> This is confusing even after reading what you wrote below and searching on Google. <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... I'm lost on most of this. I would recommend not using typical characters though, by > doing this Vim will hesitate &timeoutlen (Cream default is 300ms) > every time a "c" is typed. > > Just to clarify about mappings, the idea is that for insert mode, > "<C-b>:" drops to command line for one call. For visual mappings > ":<C-u>" drops to the command line, with the range being removed by > the <C-u>. > > Hmmm, I can't say I understand that. 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. I'm trying to do it now so I can switch from QuickBooks before getting too far into a new year. (And now I'm realizing that I should have used Ubuntu x86 rather than x64 because I don't see an x64 version of TrueCrypt... so probably need to reinstall the OS now.) 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). 2. open URLs in default browser (which was working until I started messing with the encryption) 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. 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? 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. |
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 |