Wednesday, July 2, 2014

Re: map a chain of commands

On 2014-07-02 01:56, Tarlika Elisabeth Schmitz wrote:
> I would like to map a chain of commands onto a keystroke for use
> with one specific tab separated file:
>
> On the line where the cursor is positioned, I would like to copy
> field 3, field 18, field 6 to clipboard (separately), but only if
> they are not empty, so I can paste them one by one in an external
> application.

You might have to clarify a few things:

- do you only want to do this if *all* of the fields are non-empty,
or *any* of the fields are empty?

- though you don't clarify, I *presume* that you mean "{system}
clipboard", as Vim offers multiple registers ("clipboard"s) which
you can manipulate

- a clipboard only has one slot for holding things, so pulling in
multiple things becomes a bit of a non-starter. You could combine
them; or you could copy one, flip to your app, paste, flip back to
Vim, signal that you're done with that one (copying another to the
clipboard), flip back to your application, paste, back to vim, etc.

It sounds as if something like

:nnoremap <buffer> <f4> :for idx in [3,18,6]<bar>let val=split(getline('.'), '\t')[idx-1]<bar>if strlen(val)<bar>let @+=val<bar>call input('Press enter #'.idx)<bar>endif<bar>endfor<cr>

would do the trick.

If you want to ensure that *all* of the fields have a value, that's
a little trickier, but the logic would be the same.

-tim


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment