Thursday, July 3, 2014

Re: map a chain of commands

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.


--

Tarlika Elisabeth Schmitz, Scotland
http://my.mutterings.co.uk/

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