News for hackers. Stuff that matters.
Re:History and effective use of Vim (2019) by h0l0cube on Friday July 29, 2022 @07:41AM (#32275703)
Unsolicited advice for scrolling without spamming j and k:

- C-u and C-d to jump up/down

- [ and ] to go prev/next empty line (I have a macro to clear empty spaces at the end of lines so this works well for jumping functions in code)

- from the article: 50% to go the halfway point of a document

- 100gg to go to line 100

- 100k to go 100 lines down

Are there any more good ones?

Edit: occurs to me that you might have remapped kkk to escape normal mode. At one time I had done this for jj. Now I just use C-[ as it’s portable to vanilla vim setups and less of a stretch than the escape key.

Re:History and effective use of Vim (2019) by Izkata on Friday July 29, 2022 @08:55AM (#32276243)

  :set relativenumber
The line the cursor is on is now shown in the left sidebar as 0, counting up for each line away from the cursor. So now it tells you what number to use for "10j" and "10k" to move up and down a specific number of lines.

   m[a-z]
   `[a-z]
Mark a point in a file into a register, and jump back to that point. Or even more interesting:

   m[A-Z]
   `[A-Z]
Same as above, except capital marks are global and work across files.

Also,

   ``
Jump back to the last place you jumped from (but only within the same file).
Re:History and effective use of Vim (2019) by scruple on Friday July 29, 2022 @09:32AM (#32276626)
My only problem with relative line numbers (and I use them despite this) is working with ranges of line numbers. For instance, I'll maybe be doing some refactoring and want to see what it looks like to move lines 127,137 to my current cursor (127,137t.). With relative line numbers I have to do some quick arithmetic to sort out the range.
Re:History and effective use of Vim (2019) by yjftsjthsd-h on Friday July 29, 2022 @10:49AM (#32277665)
I believe it's possible to enable relative and absolute numbers at the same time
Re:History and effective use of Vim (2019) by hajile on Friday July 29, 2022 @09:30AM (#32276596)
I also set scrolloff to 10 or so that way I can always see what's above/below what I'm currently editing.
Re:History and effective use of Vim (2019) by pge on Friday July 29, 2022 @09:58AM (#32276956)
H, M, and L will move the cursor to the top, middle and bottom (respectively) of the screen. That is, H moves the cursor to the top visible line on the screen, L to the last line currently visible, and M to the middle. Cursor moves but text does not.

zt, zz, and zb are similar but move the text not the cursor. So, zt will take the current line the cursor is on and make it the first visible line on the screen (and keep the cursor on that line). zz to the middle, zb to the bottom.

Personally, I use [ and ] to jump around most often in code, but the above are handy when you are working with documents.

Re:History and effective use of Vim (2019) by benrow on Friday July 29, 2022 @07:53AM (#32275791)
I like using L and H to go to bottom or top of screen to initiate scrolling with j or k. You can scroll up or down without moving the cursor using Ctrl-Y and Ctrl-E but I find those a bit hard to get used to.
Re:History and effective use of Vim (2019) by AdieuToLogic on Friday July 29, 2022 @08:39AM (#32276123)
> Are there any more good ones?

I find these handy, especially after doing a search (quoted from :h z):

- z. redraw, cursor line to center of window

- z<CR> redraw, cursor line to top of window

- z- redraw, cursor line at bottom of window

Re:History and effective use of Vim (2019) by Macha on Friday July 29, 2022 @01:25PM (#32279642)
{ / } jump to start/end of the block.

Between that and 20j and (blasphemy probably) just using the scroll wheel, that handles most of my scrolling needs.

Re:History and effective use of Vim (2019) by h0l0cube on Friday July 29, 2022 @07:24PM (#32282822)
I think I meant to write { and } (which is previous/next empty line) instead of [ and ] which can be combined like [( ]) or [{ ]} to go to the beginning and end of parentheses and curly brackets respectively. % is good for jumping between matching parenthesis... I wish there was something like this for *ml tags inbuilt (e.g., go to matching <div> <-> </div>)
Re:History and effective use of Vim (2019) by raverbashing on Friday July 29, 2022 @09:44AM (#32276777)
> advice for scrolling without spamming j and k

Or just use the directional keys and PgUp/PgDown like any person in the last 30 yrs

Re:History and effective use of Vim (2019) by h0l0cube on Friday July 29, 2022 @10:13AM (#32277177)
Every time my fingers have to leave the home row I feel pain. Mostly from knowing that I’m likely to typo straight after, or have to remove my gaze from the screen to check my fingers and then find my position on the screen again. It really breaks flow and that flow was a big motivation for me to start using vim
Re:History and effective use of Vim (2019) by chasd00 on Friday July 29, 2022 @10:22AM (#32277296)
:1 to go to the top of the file, G to goto the bottom of the file
Re:History and effective use of Vim (2019) by h0l0cube on Friday July 29, 2022 @04:57PM (#32281688)
gg will take you up to the top as well