whame / tmux-modal

Execute complex tmux commands in just a few keystrokes with a modal mode that is designed to be efficient, easy to remember and comfortable
MIT License
172 stars 4 forks source link

Question: Why not multiple modes? #8

Closed surrealoatmeal closed 1 year ago

surrealoatmeal commented 2 years ago

I don't know if this is the most appropriate way of doing this, but since the project does not have a discussion page, this is the only way that came to mind.

People have stated that the syntax of w-movement is annoying and that it should be changed, however this has been countered with the Vim philosophy: object then verb.

Although a seemingly valid response, why would we just not drop the idea of stickies and prefixes within the project as a whole, and implement those as modes?

The concept is as follows: The plugin user is dropped into the normal mode, where they can enter input mode to issue commands to their shell, or press one of the keys used for prefixing in the current version. Take w for example, to enter window mode, after which they can use hjkl as usual. Esc to return to normal mode.

Would this not be more alike to Vim and thus more welcoming? Is there a technical (perhaps relating to tmux) or philosophical issue preventing the realization of this idea?

I'm asking since I would be interested in coding this up, although I was leaning towards more of a fork or even a complete rewrite, since this would be a major paradigm shift within the project and I have other things that I want to change about the implementation.

whame commented 2 years ago

On Wed, Aug 10, 2022 at 04:39 surrealoatmeal @.***> wrote:

I don't know if this is the most appropriate way of doing this, but since the project does not have a discussion page, this is the only way that came to mind.

Yeah, I think this is fine!

Although a seemingly valid response, why would we just not drop the idea of stickies and prefixes within the project as a whole, and implement those as modes?

The concept is as follows: The plugin user is dropped into the normal mode, where they can enter input mode to issue commands to their shell, or press one of the keys used for prefixing in the current version. Take w for example, to enter window mode, after which they can use hjkl as usual. Esc to return to normal mode.

Would this not be more alike to Vim and thus more welcoming? Is there a technical (perhaps relating to tmux) or philosophical issue preventing the realization of this idea?

If I understand you correctly, you are saying that you would want something like this (with the current default bindings):

M-m, w, hjkl, q ... etc.

instead of

M-m, w w, hjkl, q ... etc.

And similarly for the session commands with s?

surrealoatmeal commented 2 years ago

Not really, but close. In the concept, tmux would boot into the normal mode by default, so no M-m to begin with, just w to enter window mode. Then hjkl for navigation, end Esc to quit (I do realize q is the current default bind for that, but that is plain confusing for a Vim-like modal scheme, the key to return to normal mode should definitely be Esc.)

Or in a more complicated example, we boot into tmux, press the w key to enter window mode, press the m to initiate the move command, and l to go right. We press Esc to quit to normal mode, press i to enter insert mode, where we type

echo "Hello World!"

We are thus done with tmux for the day, press Esc to again exit to normal mode. Close the window to exit.

Or maybe overwrite the : key to be for the plugin, and reassign the tmux specific commands ; or something, I'm not 100% on this though. If this were to be the case, we would press : and type wq or x to quit and for tmux to remember our session. q! kills the session we just quit.

This could be a bit redundant though, as the idea of writing through w does not really exist within a running tmux instance, and for such an interface to be useful, we'd need to have a plethora of commands like vim to make use of. If we don't, we could just assign those to keys. Like maybe making q in normal mode quit tmux without dealing with a : replacement.

That's the gist of it. Basically think vim, but tmux :) If you have any criticisms of the ideas presented, lmk!

whame commented 2 years ago

Ah ok, now I understand! This is an interesting request. Thank you for submitting this!

I think part of why I didn't immediately get your idea, is that I don't actually use vim, I'm an emacs-guy (although I use modal editing in emacs). This also explains why the default binding might "clash" with the defaults in vim (like q for quit) :)

What you request here, can actually be implemented quite easily with the current design of tmux-modal (off the top of my head). I also believe it fits the overall philosophy of tmux-modal well. I have identified the following "sub-tasks":

  1. Add option to always enter in modal mode (normal mode in your terminology) upon start.
  2. Add option to instead always use the "sticky versions" (e.g. only needing to press w once and then the action command, like m for move).

Fixing these and setting some custom bindings will then be able to achieve this. I will create a new feature branch as soon as I have time (I will soon go on vacation, so it might take a while...).

Regarding the :-command feature, I agree with you that this would probably make more sense if we already had a bunch commands for tmux-modal. This can also be confusing since tmux itself also has the command command-prompt (Prefix + :).

In fact, this made me realize that we don't have a binding for command-prompt (e.g. : is a good candidate). Also, we might want a binding for kill-session as well (even though tmux doesn't by default). I'm thinking of s D as in "session delete" (c.f. current w D binding).

whame commented 1 year ago

Thanks for your suggestion. This has now been implemented on master. Please update and try it out!

More specifically, to get the exact behavior as you want, put this in your .tmux.conf:

set -g @modal-keybindings-conf /path/to/my-tmux-modal-keybindings.conf
set -g @modal-on-start on
set -g @modal-always-sticky on

and change the following in your custom keybindings (https://github.com/whame/tmux-modal#custom-keybindings):

# ... as before ...

# Enter modal command mode.
KBD_CMD=Escape

# Exit modal command mode.
KBD_CMD_EXIT=i

# Quit command. This is used to exit command modes that don't require prefix
# (e.g. "w r" used for resizing panes).
KBD_QUIT=Escape

# ... as before ...