Binding to copy selections vertically to equal substrings #1115

Open
rouanth opened this Issue Jan 9, 2017 · 2 comments

Projects

None yet

2 participants

@rouanth
rouanth commented Jan 9, 2017

For example, regarding this snippet:

/// Brief description
///
/// Long
/// really long
/// ...
/// description
struct MyStruct {
    field: i8
}

I wish to select the whole documentation comment.
a-ai selects the whole text.
a-ap selects the comment along with the struct definition.
I could to to the start of the paragraph, extend to struct and go back a line, but it is quite hacky.

Another example:

\begin{tabular}{|c|c|c|}
\hline
n & Time (s) & k     \\ \hline
1 & 232.4    & 123.3 \\ \hline
2 & 344.8    & 552.9 \\ \hline
3 & 45       & 45    \\ \hline
4 & 44       & 44    \\ \hline
\end{tabular}

Some long, really long line.

The cursor is at the beginning. I need to delete the column Time (s):

\begin{tabular}{|c|c|c|}
\hline
n & k     \\ \hline
1 & 123.3 \\ \hline
2 & 552.9 \\ \hline
3 & 45    \\ \hline
4 & 44    \\ \hline
\end{tabular}

Some long, really long line.

The following does the trick: /T<ret>b;4Ct&d. But I have multiple tables that are alike to this one, and they have a differing number of rows. So 4C isn't really a solution. There is a workaround, however: indent a table multiple times, run C many times, then deindent after I'm done: /T<ret>?end<ret>K>>><a-;>b;CCCCCCCCCCCt&d<<<. I can't run 10C because then it would affect the lines below. I hope we all agree that while this solution allows me to patch my tables it isn't the best one.

There are probably better ways to do this, but I think that the most lucid one would be possible if there was a way to select all & in the current continuous column if the cursor is on one of them. The same goes for selection of comments, selection of brackets in the example "Easily swap parameters with the 'rotate selection contents' command" on http://kakoune.org and in many other places.

@danr
Contributor
danr commented Jan 9, 2017

Here are some ideas that do not use C:

For the comment+struct, you can select the paragraph, split it at lines <A-s>, keep the ones that contain a comment <A-k>//<ret>. If you want, you can now merge consecutive selections with <A-m>.

For the latex tables, select the paragraph with the tables, split it at lines, <A-s>, keep the ones that contain for instance & or \\. Now you have a selection at each line, and you can navigate around so you only select the second column and remove it.

@rouanth
rouanth commented Jan 9, 2017

Thank you, these are correct solutions. However, my intent was to show the class of problems the introduction of a new binding would greatly simplify.

Your solution for the table problem is better than the one I've presented but I believe isn't applicable if the column in question is the second in one table and the third in another. I'm sorry I didn't specify that the requirement is to remove the column Time (s) regardless of table structure which was the actual problem I've encountered. My bad.

As a side note, thank you for reminding me about <a-m>, I've managed to completely forget about it. Much appreciated.

@rouanth rouanth closed this Jan 9, 2017
@rouanth rouanth reopened this Jan 9, 2017
@rouanth rouanth added a commit to rouanth/kakoune that referenced this issue Jan 9, 2017
@rouanth rouanth Add keybinding '^' in normal mode
This keybinding allows to copy the current selections vertically to the
preceding and following lines if the selections that would result have
the same contents as the source selection. This fixes #1115
a981433
@rouanth rouanth added a commit to rouanth/kakoune that referenced this issue Jan 9, 2017
@rouanth rouanth Add keybinding '^' in normal mode
This keybinding allows to copy the current selections vertically to the
preceding and following lines if the selections that would result have
the same contents as the source selection. This fixes #1115
08d7761
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment