17

Background.

I am a frequent vim-user, I just love the way you can navigate the buffers without ever having to reach for the mouse. I'm especially fond of the relative line numbers that let's me jump to specific lines with perfect accurecy, it just makes navigating that much faster. I also use tmux quite a bit since I often have a lot of stuff going on in my terminal.

The thing that bugs me the most though is when I use tmux copy-mode, it just takes forever to navigate to the line(s) you want to copy if you are using the arrow-keys, ctrl+p or k.

Searching for a unique keyword in the buffer is also not ideal but it might be faster if you already know what to search for. A lot of the time you make a search only to discover that the keyword you searched wasn't so unique after all and you didn't end up on the line you wished for anyway.

My question is this:

Does tmux support relative line-numbers?

..or line-numbers at all for that matter?

I can't find any information about this on the web. Nobody seems to be mentioning anything about this anywhere. Is there a better way?

Any other tips for ultra-speedy navigation in tmux copy-mode using the keyboard would also be very much appreciated.

Machavity
  • 30,841
  • 27
  • 92
  • 100
Master Wo
  • 215
  • 2
  • 7
  • I agree that tmux-copy mode is sometimes a bit difficult to control to your needs. https://github.com/tmux-plugins/tmux-yank tries to help you but I personnaly don't use it a lot. – edi9999 Sep 25 '15 at 15:51
  • I also created https://github.com/edi9999/path-extractor to find file-names from stdin (to use as a pipe), and [there's an issue](https://github.com/edi9999/path-extractor/issues/2) to tell how to use it with tmux – edi9999 Sep 25 '15 at 15:55

3 Answers3

15

tmux has a linenumber system in copy mode. however the first line is very bottom line.

In copy mode you can press : to go to line but there is no option to show linenumber. You can use some vim motions (key-mode was set as vi) in copy-mode, e.g. j k 20j 20k f F t T gg G 20G H L M ^ $ / ? ctrl-u ctrl-d w b ....

I think for copy a block of text, it is enough.. If you think you still cannot "ultra-speedy navigation", make a scenario, let's see how could we copy faster.

check man-page of tmux for details.

Kent
  • 189,393
  • 32
  • 233
  • 301
2

I found this tip. It will take you to your line with less keystrokes.

# super fast way to reach copy-mode and search upwards
bind-key / copy-mode \; send-key ?
Bjarte Brandt
  • 4,191
  • 2
  • 23
  • 25
2

This is a total hack but it works:

tmux split-window -h -l 3 -b "printf '\e[38;5;0m\e[48;5;226m' \
  && seq 200 1 \
  && echo -n 0 \
  && read" \
&& tmux select-pane -l

(newlines added for readablitiy) To break this down:

  • tmux split-window -h -l 3 "command..." splits the pane -h horizontally (that is places a new pane next to the current one rather than above or below) with a -l width of 3 (you're unlikely to need more than 3 digits of line number... 0-999) to the -b left of the current pane and runs the command in it:
    • printf ... just sets the background colour to yellow and the foreground colour to black... You can omit this bit if you're not feeling fancy :)
    • seq 200 1 prints line numbers from 200 to 1 - extend if you have a tall screen!
    • echo -n 0 prints the 0 on the last line, because seq will print a trailing newline and we don't want that
    • read waits for you to press enter - this is how we block it from closing after the echo has completed
  • tmux select-pane -l jumps you back to focus on the pane you were working on

Select the pane and press enter to close it.

I would imagine that you can do something add a name for the new pane and create a keybinding for both opening and closing it from the pane you're actually trying to count line numbers on, but for now I'm just using the binding:

bind N split-window -h -l 3 -b "printf '\e[38;5;0m\e[48;5;226m' && seq 200 1 && echo -n 0 && read" \; select-pane -l
Matt C
  • 21
  • 1