Wednesday, August 1, 2012

Re: What's the best way to move to an arbitrary location on your screen?

On 31/07/12 20:58, Daan wrote:
> I've been learning Vim for a while, and one situation has been coming up a lot for me:
>
> 1) I'm scrolling through a sourcefile, and see an interesting word I'd like to edit or yank.
> 2) I look left at the line number of the word, and type [line number]G
> 3) I keep pressing w/W/b/B until I reach the word, (except if the word happens to be the first or last word of the line, or located near a unique symbol)
>
> However, this feels inefficient (especially step 2), and I'm hoping to find a better solution.
>
> Some things I think might be possible, but have no experience with:
> - Use H/M/L to move roughly to the line, then 0/gm/$ to move roughly to the column, then using small motions to get to the final spot.
> - Learn to guess [number]j/h/k/l way better (perhaps with relative line numbers) to do something like "7j33l".
> - Use / and type characters until it matches, then press enter.
> - Use the easy motion plugin.
>
> Please comment on the above or share your method. :)
>

IMHO there isn't just one best way to go to an arbitrary location; there
are several, for different people and different circumstances.

One possible way is to click where you want to go. This doesn't work if
you're running in Console mode in a terminal which doesn't receive mouse
clicks or if Vim doesn't get this particular terminal's mouse clicks
(for instance, in the Linux text console if gpm isn't installed or if
running a Vim compiled without the +mouse_gpm feature). It also doesn't
work, of course, if the place you want to go isn't already onscreen.

Another possible way is to search, either forward with /, backward with
?, or, on the current line, right with f or t or left with F or T (both
/ and ? will usually wrap around from the end to the beginning of the
file or vice-versa; this depends on the 'wrapscan' option).

If you know on which line number you want to go (either because you have
'number' on, or because you see the same file with line numbers in some
other program such as a browser), there are several ways to go to that
line: for instance, to go to line 1234 you could type either

1234G
or
:1234<Enter>

where <Enter> is one keypress, not seven.

G with no count goes to the end of the file, gg goes to its top.

You can also open a new editfile at a given line number, for instance

:e +456 foobar.c

to edit the file foobar.c, with the cursor at line 456.

Or if you know how many lines to go up or down from where you are now,
you can use a count with j or k (for "file" lines), or gj or gk (for
"screen" lines: if 'wrap' is set you may have one file line wrapped over
several screen lines). Similarly with h or l for columns. And I forgot
to mention the | command: for instance 79| goes to column 79 (if there
are that many on the current line). I also forgot to mention that, for
instance, 75% will put you at that percentage point of the file
(counting by lines).


See:
:help <LeftMouse>
:help /
:help ?
:help f
:help t
:help F
:help T
:help G
:help gg
:help +cmd
:help j
:help k
:help gj
:help gk
:help h
:help l
:help |
:help N%

There is no helptag for :1234 but it is mentioned as :[range] a few
paragraphs after the help for G


Best regards,
Tony.
--
CUSTOMER: You're not fooling anyone y'know. Look, isn't there something
you can do?
DEAD PERSON: I feel happy... I feel happy.
[whop]
CUSTOMER: Ah, thanks very much.
MORTICIAN: Not at all. See you on Thursday.
CUSTOMER: Right.
The Quest for the Holy Grail (Monty
Python)

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: