Hi all! I just want to first say that this tool is awesome and I'm super happy to have discovered it!
I have a particular use case that I'm curious if visidata can handle. I have a text file (or output from some command) that looks like this:
line 1
line 2
line 3
line a
line b
line c
line I
line II
line III
What I am trying to do is:
(1) select the first three lines and copy them to the system clipboard
(2) paste them so that they fill the first column of a blank visidata sheet
(3) repeat two more times to get a final visidata sheet like this:
line 1 | line a | line I
line 2 | line b | line II
line 3 | line c | line III
Is there a way to do this easily in visidata without writing code?
Thanks!
Thanks @kovasap! I think you want to use select (or other command) to select the rows; then gzy to yank the selected cells in the current column to the clipboard; then gzp to paste the clipboard cells to the current column. Along the way you'll have to use A to create a new sheet, ga to add blank rows to that sheet, and perhaps gza to add additional blank columns to that sheet.
Let me know if this gets you what you want! There are more clever ways to maybe do it with Pivot, but this seems like the simplest for your use case.
This works! A couple follow up questions I had when doing this:
First, is there a way to select using vim-like motions? e.g. 10s to select the next 10 rows (repeat s 10 times).
Second, I understand now that my workflow works fine if I open my original text file in visidata itself, then do my copy and pasting within visidata, using it's clipboard. This is great! However, my original thought when I started this was instead to select and copy some text with newlines outside of visidata with my mouse, then paste that stuff from the system clipboard directly into a visidata column (with the newlines telling visidata where to start new rows). This is arguably easier/more intuitive. Is this possible/something visidata wants to support?
There is no way to use vim-like motions. The command "language" is deliberately much simpler than vim's, just single command keys with an optional prefix (g z or gz). There are several ways of selecting rows by their contents, and we can talk about specific ways to make it easier for you if you want.
As for pasting from the system clipboard, we don't currently support that. I think it'd be useful, at least as an option for people like yourself. Do you imagine that you'd do something like double-click onto a column and have the values pasted into the next N rows? I think we can probably do something like that. The tricky part is getting the clipboard data into VisiData, since the newlines would interfere with the current input mechanisms. So we'd probably want to make a custom command that used the CLI clipboard manipulation tools (like clipboard.py does currently, but in reverse). Are you interested in trying to implement this yourself? I'd be happy to help and provide guidance if so.
Ok cool, I can read up more on the selection mechanism as I use it more.
Yeah, that's what I'm thinking. I might look into it this weekend actually and see how far I can get. I'll let you know if I have any questions, or if I choose not to pursue it :).
Thank you so much for spearheading this @kovasap :tada: This is lovely and something I wanted for a while.
For posterity, @kovasap's work on this issue was recorded and reviewed within PR https://github.com/saulpw/visidata/pull/258.
After testing the PR, I made some changes in commit https://github.com/saulpw/visidata/commit/abf990d8b593f13aee8abfbdea31ade2c0425882 .
I expanded @kovasap's existing work to:
I think that captures the work on this issue. The feature can be explored on develop and used either with middle mouse clicking, pressing Space and then typing syspaste-cells or by writing bindkey('keystroke', 'syspaste-cells') in a ~/.visidatarc to bind a specific keystroke to the command (http://visidata.org/docs/customize/).
I'm extremely sorry and probably missing something but how do you actually paste from the system clipboard? E.g., I have a column of data in my clipboard and want to insert it as a column into the current sheet in vd?
Thank you :)
I think we settled on middle-click. Try that.
@kovasap , thanks for your reply!
But no keyboard hotkey?
Also, I'm on laptop (MacBook), and Cmd-click results in no command for "ALT-BUTTON1_CLICKED"
EDIT: found an old magic mouse, middle-click results in no command for "BUTTON2_RELEASED"
@for-coursera Try Space syspaste-cells.
Says no binding for syspaste-cell | "syspaste-cell" and nothing happens. Typing sys and pressing <Tab> cycles syscopy* and sysopen commands but shows no syspaste-cells. I'm using visidata 1.5.2 installed with pip3.
This feature is not in 1.5.2. You would have to install from develop or v2.-1.
@for-coursera More information here! http://visidata.org/v2.x/
@saulpw, @anjakefala Thanks, installed 2.-1dev!
However, ga now reports AttributeError: 'Sheet' object has no attribute 'newRow' | "10". gza works just fine, though.
After @anjakefala fixed that bug with ga, I can confirm that syspaste-cell command indeed does work. Thanks to everyone for support :)