Can vim create table like this?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Can vim create table like this?

Peng Yu
Hi,

I see that emacs can create table like this. Does vim have a plugin
that offers similar capability?

http://www.youtube.com/watch?v=EQAd41VAXWo&feature=related

--
Regards,
Peng

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Can vim create table like this?

MarcWeber
Excerpts from Peng Yu's message of Mon Jan 09 03:15:13 +0100 2012:
> I see that emacs can create table like this. Does vim have a plugin
> that offers similar capability?

I don't know exactly. I never missed it. Using HTML DSLs like HAML,
slim, JADE tables can be written equally fast:

  - data = [["C programming language", 234], ['other lang', 345]]
  %table
    - for d in data
      %tr
        %td = d[0]
        %td ='$'+d[1]
    %tr
        %td total
        %td = sum( ... )

And if you can't use those for whatever reason you can still use one of
  - zencoding
  - sparkup
plugins
Zen coding such a HTML table is as much work as

table>tr*4>td,td<c-y> (or such)
and filling in the values.

If you really need this feature I'd recommend installing Emacs and get
vi emulation layers such as "evil". Sorry about that. I don't think any
Vim plugin provides that level of abstraction - I may be wrong though.

Marc Weber

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Can vim create table like this?

Karthick Gururaj
In reply to this post by Peng Yu
On Mon, Jan 9, 2012 at 7:45 AM, Peng Yu <[hidden email]> wrote:
> Hi,
>
> I see that emacs can create table like this. Does vim have a plugin
> that offers similar capability?
>
> http://www.youtube.com/watch?v=EQAd41VAXWo&feature=related
>
table.vim script seems to come close? Never used it myself though.
See:
http://vim.wikia.com/wiki/Smarter_Table_Editing_II
http://www.vim.org/scripts/script.php?script_id=769

Fundamentally it should be possible to do all the things in the video.
I learnt most of vim features "fighting" with a friend who was an
emacs user :) Now, spirit is willing but flesh is weak.

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Can vim create table like this?

MarcWeber
Excerpts from Karthick Gururaj's message of Mon Jan 09 12:48:38 +0100 2012:
> table.vim script seems to come close? Never used it myself though.
> See:
> http://vim.wikia.com/wiki/Smarter_Table_Editing_II
> http://www.vim.org/scripts/script.php?script_id=769
I think you've missed the "sum" function being used in Emacs.
You can do calculations. Neither the wiki nor the code of "table.zip"
contained the word "sum". Didn't read the docs though.

Marc Weber

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Can vim create table like this?

Karthick Gururaj
On Mon, Jan 9, 2012 at 10:18 PM, Marc Weber <[hidden email]> wrote:
> Excerpts from Karthick Gururaj's message of Mon Jan 09 12:48:38 +0100 2012:
>> table.vim script seems to come close? Never used it myself though.
>> See:
>> http://vim.wikia.com/wiki/Smarter_Table_Editing_II
>> http://www.vim.org/scripts/script.php?script_id=769
> I think you've missed the "sum" function being used in Emacs.
> You can do calculations. Neither the wiki nor the code of "table.zip"
> contained the word "sum". Didn't read the docs though.
I saw that in the video, and I agree the table script doesn't have any
such features.

But it is possible to script it in vim. I would do it little
differently than what was shown in video... perhaps do a block select
of numbers to be added, place the cursor where the sum needs to be
entered and type a hotkey, say '+'. It is easy enough to yank the
contents of last visual selection, scan for numbers in each line, add
them and insert the sum at cursor position...

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Can vim create table like this?

lith
Am Dienstag, 10. Januar 2012 06:03:02 UTC+1 schrieb Karthick:
> You can do calculations. Neither the wiki nor the code of "table.zip"
> contained the word "sum". Didn't read the docs though.

But it is possible to script it in vim. I would do it little
differently than what was shown in video...

While it's possible in vim to add up visually selected numbers, I think you'd have a hard time implementing field functions as shown in the video. I bet they used overlays (http://www.gnu.org/savannah-checkouts/gnu/emacs/manual/html_node/elisp/Overlays.html) to implement these field functions. Unfortunately, vim doesn't have such a feature (yet?).

Regards,
Tom

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Can vim create table like this?

Karthick Gururaj
On Tue, Jan 10, 2012 at 12:10 PM, lith <[hidden email]> wrote:

> Am Dienstag, 10. Januar 2012 06:03:02 UTC+1 schrieb Karthick:
>>
>> > You can do calculations. Neither the wiki nor the code of "table.zip"
>> > contained the word "sum". Didn't read the docs though.
>>
>> But it is possible to script it in vim. I would do it little
>>
>>
>> differently than what was shown in video...
>
> While it's possible in vim to add up visually selected numbers, I think
> you'd have a hard time implementing field functions as shown in the video. I
> bet they used overlays
> (http://www.gnu.org/savannah-checkouts/gnu/emacs/manual/html_node/elisp/Overlays.html)
> to implement these field functions. Unfortunately, vim doesn't have such a
> feature (yet?).

Thanks for the link, will read up.

FWIW, a crude proto that can add/multiply a selected range:

" Insert the result of the operation 'op' at current cursor position
" The data being operated on is the previous visual select area
function! InsertOpResult(op)
   " Save current cursor position, later operations will move it
   let saved_cursor = getpos(".")
   " Save contents of reg a, later ops will trash it
   let saved_a = @a

   " Yank last visual selection to '@a', split to numbers and add them up
   silent! normal gv"ay
   let nums = split(@a, '\n')
   let result = nums[0]
   for num in nums[1:-1]
      exe "let result = result " . a:op . " num"
   endfor

   " Restore reg a
   let @a = saved_a
   " Restore cursor and insert result
   call setpos('.', saved_cursor)
   exe "normal i" . result
endfunction

nmap <Leader>+ :call InsertOpResult("+")<CR>
nmap <Leader>* :call InsertOpResult("*")<CR>

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Can vim create table like this?

Christian Brabandt
In reply to this post by lith
On Tue, January 10, 2012 7:40 am, lith wrote:

> Am Dienstag, 10. Januar 2012 06:03:02 UTC+1 schrieb Karthick:
>>
>> > You can do calculations. Neither the wiki nor the code of "table.zip"
>> > contained the word "sum". Didn't read the docs though.
>>
>> But it is possible to script it in vim. I would do it little
>> differently than what was shown in video...
>>
> While it's possible in vim to add up visually selected numbers, I think
> you'd have a hard time implementing field functions as shown in the video.
> I bet they used overlays (
> http://www.gnu.org/savannah-checkouts/gnu/emacs/manual/html_node/elisp/Overlays.html)
> to implement these field functions. Unfortunately, vim doesn't have such a
> feature (yet?).

The csv plugin (http://www.vim.org/scripts/script.php?script_id=2830)
implements a Sum Function and allows easy definition of
custom functions.

regards,
Christian

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