Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Is there a way to get the current line number?

34 views
Skip to first unread message

Trevor Avant

unread,
Dec 15, 2024, 1:43:13 AM12/15/24
to tmux-users
I would like to get the line number the cursor is on. I believe that tmux keeps track of this information as it has the goto-line function. Ultimately I would like to use this information to get the line number after a search-backward command, or get the line number after double-clicking the line.

Nicholas Marriott

unread,
Dec 15, 2024, 1:48:51 AM12/15/24
to Trevor Avant, tmux-users

How about copy_cursor_y?


On Sun, 15 Dec 2024, 06:43 Trevor Avant, <trevo...@gmail.com> wrote:
I would like to get the line number the cursor is on. I believe that tmux keeps track of this information as it has the goto-line function. Ultimately I would like to use this information to get the line number after a search-backward command, or get the line number after double-clicking the line.

--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/tmux-users/10adf3fd-8323-41ab-bd72-8e4274c46b10n%40googlegroups.com.

Trevor Avant

unread,
Dec 15, 2024, 4:35:08 AM12/15/24
to tmux-users
That would work if there is a way to return to that line number later (something like "goto-cursor-y"). The only thing I know about is goto-line, which seems to reference a line numbering system different than copy_cursor_y (on my computer, it seems to reference the hidden lines that do not appear on the screen).

Nicholas Marriott

unread,
Dec 15, 2024, 4:37:33 AM12/15/24
to Trevor Avant, tmux-users
goto-line will be from the start of the history, you can probably work if out with scroll_position and/or history_lines as well.

Trevor Avant

unread,
Dec 15, 2024, 5:27:50 PM12/15/24
to tmux-users
Ok, is there anyway to make tmux go to a line number that is shown on the screen? It seems that goto-line only works for lines that are not visible. For example, in Vim you can enter the command ":7" which will move the cursor to line 7. Based on the tmux manual, that's what I thought the goto-line function did.

Nicholas Marriott

unread,
Dec 15, 2024, 5:30:29 PM12/15/24
to Trevor Avant, tmux-users
the visible screen is at the bottom of the history so goto-line should do it too, or use top-line and cursor-down with send-keys -N

Trevor Avant

unread,
Dec 15, 2024, 11:08:43 PM12/15/24
to tmux-users
Ok thanks, yeah it seems to work now, not sure what my problem was. I can convert between the copy_cursor_y line number system to the goto-line line numbering system by subtracting copy_cursor_y from pane_height-1. It would be great if in the future tmux supported a way to get the cursor line number in the goto-line numbering system.

Trevor Avant

unread,
Dec 23, 2024, 12:29:34 AM12/23/24
to tmux-users
I'm having the same problem again - goto-line does not work unless there are more lines in the history than in the terminal. Here's a minimal example:

- open a terminal (I tried gnome-terminal, kgx, and konsole)
- run tmux
- run the command "echo hi" in the terminal
- press Ctrl+B then [ to go to copy mode
- press : to enter the goto-line prompt
- press 1 (or any number larger than 1) and Enter
- I remain on the lowest line

I'm running tmux 3.5a, Arch Linux, and an empty ~.tmux.conf.

Nicholas Marriott

unread,
Dec 23, 2024, 1:46:21 AM12/23/24
to Trevor Avant, tmux-users
Sorry I thought goto-line did the visible screen but actually it doesn't. I don't have time to change it so you will need to do something like "send -X top-line; send -N 5 -X cursor-down" instead.

Reply all
Reply to author
Forward
0 new messages