Thursday, July 3, 2014

Re: map a chain of commands

Hi Tarlika!

On Do, 03 Jul 2014, Tarlika Elisabeth Schmitz wrote:

> On Wed, 2 Jul 2014 16:35:46 -0500
> Tim Chase <vim@tim.thechases.com> wrote:
>
> >On 2014-07-02 22:07, Tarlika Elisabeth Schmitz wrote:
> >> >> > :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>
> >> >
> >> >The mapping takes the current line, splits it on <tab>s, iterates
> >> >over the desired positions (3,18,6), pulling out that value and, if
> >> >it has a non-zero length, stuffs it in the system clipboard [then
> >> >currently waiting for you to hit <enter>, but as mentioned, you
> >> >might be able to take that bit out].
> >>
> >> Is there maybe a typo in the command above?
> >
> >You're typing it all as one line? I tested it with a tab-separated
> >file I've got here and it (at least with the "call input(...)"
> >fragment) worked exactly as expected.
>
> Once I removed <buffer>, it worked.
>
> However, it does not cope with empty fields. The CSV file has 19
> columns but it would appear that split() does not generate 19 items. I
> get "list index out of range" and incorrect fields are placed in the
> clipboard.

Try the additional parameter 1 for split (see :h split())

Best,
Christian
--
Gegner glauben uns zu widerlegen, wenn sie ihre Meinung
wiederholen und auf die unsrige nicht achten.
-- Goethe, Maximen und Reflektionen, Nr. 588

--
--
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: