2

When in copy mode I would like keyboard navigational keys to auto select whole current line. Ideally, the selected line would be trimmed upon selection/copy/paste.

Example

I often want to select whole, trimmed lines to select output from git <anything> or ls -1 etc:

# git status

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        robots.txt
        index.php
        [...]

I want to commit robots.txt, so I enter into copy mode, and start to move the cursor towards robots.txt line. Upon moving it up, it selects first index.php:

# git status

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        robots.txt
        **index.php** (<-- text between ** is auto selected)
        [...]

# git status

Then upon moving cursor up (with keyboard) it selects the line with robots.txt (trimmed):

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        **robots.txt** (<-- text between ** is auto selected)
        index.php
        [...]

Is it something that can be done in the current version of tmux?

1 Answer 1

1

Solution

Here's a macro that does "go up/down and select trimmed line" on C-Up / C-Down (usually Control + Up / Control + Down ):

In tmux enter command mode by C-b :, then use the following code:

bind -T copy-mode C-Up send-keys Up \; send -X back-to-indentation \; send -X begin-selection \;  send -X end-of-line 
bind -T copy-mode C-Down send-keys Down \; send -X back-to-indentation \; send -X begin-selection \;  send -X end-of-line

To copy the text & paste it you press C-w and C-b ]

Gist

Bug fixes, enhancements etc.: https://gist.github.com/mklepaczewski/ee9c4cd85f678859c90844ef18ac8ceb

Demo

After git status:

enter image description here

After C-b [ and 3x C-Up:

enter image description here

Now it's just a matter of C-w (to copy) followed by C-b ] (to paste)

1
  • As much as I don't like accepting my own answer, there are no other submissions.
    – matt
    May 22, 2019 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.