kakoune: % should not move cursor

It’s really inconvenient to press % and get taken to the last line.

And if I do <c-s>% and then hit <c-o>, my selection clears…

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 1
  • Comments: 28 (22 by maintainers)

Most upvoted comments

Then the question might be, “should the main cursor always be visible”? Or perhaps, “are there other ways to keep the main cursor visible (e.g. some kind of folding) without losing the user’s place?” There are some ideas in #2727 that might be relevant here.

No wonder I left discuss.kakoune.org for good

You’re getting insulting here. If you can’t restrain from this kind of remark in the future, I don’t think you’re a welcome addition in the community.

The issue can be solved if we change the title little bit:

The view should not move when selecting contents with %

Kakoune has the <kbd>v</kbd> feature that goes into this View Mode, and I find it practically useless because it can’t move anywhere beyond the cursor. Sure it is good for re-centering cursor, but that’s not view mode. View mode should allow to view the file without moving the cursor, like in any modern GUI editor. It would be even better if we could evaluate commands while staying in view mode, like % or s. It will not move our viewpoint anywhere.

If View mode would allow this, we will be able to map % to v% or V% and simply select whole file after entering view mode.

I am always sorry to see users go away from Kakoune, especially at this time where I cannot dedicate as much time to it as I used to (young kid in the house, second one on the way…)

There are two issues conflated into one here:

  • The representation of selections as an inclusive (cursor, anchor) pair: this is a relatively early decision which most of the editing code assumes, there are definitely trade-offs there, such as the long discussion we had about the impossibility of empty selections in Kakoune. It is not perfect, but it is very unlikely to change at this time, and I think it did prove quite practical.

  • The fact that the cursor must always be visible. This is not as strongly embedded into Kakoune but is still not that easy to change (we place the hardware terminal cursor at this position to allow for “over-the-spot” style IM methods). This is much more up for debate, the current logic is simple (always keep it visible), we could have some commands that do force visibliity (mutation to the buffer for example, rotating the main selection…) and some that do not (select the whole buffer). But I am afraid it would be hard agree on which should and which should not.

@nonumeros sad to see you go!

From what I can tell, you and @andreyorst had different, conflicting ideas for solving this problem, and that got fairly heated?

You believe that the way forward is to separate “what’s selected” and “where is the cursor”. This would allow having <c-s>%<c-o> have the whole screen selected, but the cursor(s) in the same place as before the key combo. The screen would be looking at a similar part of the file, as the cursors would be in the same place.

@andreyorst wants to keep “what’s selected” and “where is the cursor and anchor” intimately connected. They believe the way forward is to separate “what part of the screen is showing” and “where the cursor is”. This would allow <some unknown key combo>%<some unknown key combo> to select the whole buffer (and clear selections) but keep looking at the code that was being looked at before.

@nonumeros, If you don’t mind commenting one more time, would you mind confirming if I have your idea written down correctly?

I want to understand both sides of this, since they both look like valid (but very different) solutions to the problem at the top of this thread. Looking at the merits of both seems like a good idea. But if the ideas are misunderstood, then that isn’t possible.

If I’m butting in on this issue (and argument?), my apologies for that.

@andreyorst I’m slightly more confident I understand your proposal. But if I’ve written it down incorrectly, could you correct it?

(edit: @Delapouite, apologies for incorrectly pinging you on this! I somehow got you and @andreyorst confused for a second when writing this post and trying to understand the different solutions to this.)

@losnappas Perhaps you already implemented your idea, but I could not resist giving it a try myself. The following selects everything until the cursor and everything after it.

execute-keys -save-regs a '<space><a-:>Zgg<a-z>uZl"aZge"a<a-z>u<a-z>a)'

EDIT: Originally this post contained the following code, but I found that it is buggy. It worked only when the anchor preceded the cursor and the cursor was not on a newline.

select "1.1,%val(cursor_line).%val(cursor_column)" "%val(cursor_line).%sh(expr $kak_cursor_column + 1),%val(buf_line_count).2147483648"