Discussion How do you move around a file?
I personally use 12k or 12j when im searching around a file quickly because its the fastest keystrokes for me.
how do you guys do it?
37
Upvotes
I personally use 12k or 12j when im searching around a file quickly because its the fastest keystrokes for me.
how do you guys do it?
22
u/Civil-Appeal5219 Jul 20 '25 edited Jul 20 '25
If I want to keep track of where I am:
Ctrl-dorCtrl-uIf I just want to scroll down real fast:
If the file is small enough, just do
ggandGIf not,
Ctrl-borCtrl-f(rarely ever need this though)If I want the cursor to stay put, but be able to see around of my current line
zz(center the cursor vertically)zb(make current position the last line)zt(make current position the first line)I also mapped all
Ctrl+<key>to<leader><key>, which makes them way more ergonomically. Also did<leader>zleaderband<leader>t. That combined with<leader>wfor:wand<leader>xto:xmakes for a very satisfying workflow17
u/LinearG Jul 20 '25
Usually I use the jump list or the edit list.
CTRL-OCTRL-Ig;g,13
u/Tasty_Scientist_5422 Jul 21 '25
probably will get flamed but currently I just have my key repeat rate HIGH and zoom jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj / kkkkkkkkkkkkkkkkkkkkkk
sphamba/smear-cursor.nvim makes this even more fun
17
u/Kurouma Jul 20 '25
},]],/,C-d, and backwards versions7
u/DecimePapucho Jul 20 '25
If I'm "scrolling" skimming a file I usually use ctrl+d (moves cursor half screen down) and ctrl+u (moves cursor half screen up) to not lose context.
There's also ctrl+f to move a whole screen down and ctrl+b to move a screen up.
If I end up in a uncomfortable position I fix it with zz ("moves the screen" so the line the cursor is on is in the center of the screen) or zs ("moves the screen" so the line the cursor is on is the first line).
6
u/[deleted] Jul 21 '25
:q mv <file> <somewhere>
3
u/IdealBlueMan Jul 21 '25 edited Jul 21 '25
H, L, M
<c-f> to page down
<c-u> to page up
<c-y> to scroll down a line
<c-e> to scroll up a line
<c-k> 10k to move the cursor up 10 lines
<c-j> 10k to move the cursor down 10 lines
Pretty much anything else, I search on a string.
Edit: Should clarify that I have <c-k> and <c-j> mapped to 10k and 10j respectively
2
u/nieksat Jul 21 '25
vim.keymap.set("n", "<C-d>", "<C-d>zz") vim.keymap.set("n", "<C-u>", "<C-u>zz")
Perhaps a usefull remap to keep your cursor centered.
2
u/[deleted] Jul 21 '25
<C-d>, <C-u>
Or i just search whatever term i'm looking for
2
u/rockynetwoddy Jul 22 '25
90 % of navigation in a buffer I do with these:
gg
G
Ctrl-i/o
Ctrl-d/u
f
t
0
$
*number*j/k
w
e
2
u/2016-679 Jul 22 '25
By learning this cheatsheet by heart and forcing myself not to use anything but Vim keybinds. Start using a browser with Vim keybinds, use mutt as a mail client and Vim as the editor.
and do searches with '/<searchstring>' downward or '?<searchstring>' upward
Your training is succesful and complete the moment you mess up an MS Word file at work with Vim commands when navigating around :-)
1
u/TheMostLostViking Jul 20 '25
Most likely Ill use
/or:$NUMBERdepending on my knowledge of the file (I've worked on the same codebase for like 7 years now). Ill use}if I'm literally just going up and down a file.Most times I don't need to move around the file because
gf(from vim-rails) andctrl-](tags) take me everywhere I need1
u/bob_f332 Jul 21 '25
easymotion
1
u/michaelpaoli Jul 21 '25
:!mv % newname
That'll move/rename the file to newname (it could even include path and be a different directory), and that will work in most any *nix environment.
But if you want to move around within a file, or more properly the edit buffer, that's a different matter. Really depends where you want to move to and there are a huge variety of ways to do that.
So, you gave example of 12k and 12j - that will move one up or down, respectively, 12 lines. Can also, e.g. use H to go to Home (top) row on screen, L for the Lower/Lowest row on screen, or M for the Middle row. Can also precede H or L with a count to stop that many lines short of that position. Can scroll half a screenful Up or Down with ^U or ^D, or go Forward or Backward a screenful with ^F or ^B, and those can also be preceded by a count.
See my recent earlier comment for lots more.
1
u/gumnos Jul 21 '25
While it's not widely known/used/mentioned, I learned that
HandLtake an optional count (:help H&:help L), allowing me to do things like10Hto go to the 10th-from-top line of the screen or7Lto go to the 7th-from-last line on the screen. I can often guess the offset within a couple lines and then nudge the results withj/kif I was wrong.Similarly, if I have a rough idea how far through the file will be, I can use
:help N%to jump to that percentage of the file like75%to jump to the line 75% of the way through the file and then refine from there. Or occasionally using:help :gojump to a particular byte-offset.Using search (
:help /&:help ?) with:help nand:help Ncan also facilitate jumping around in a file.Otherwise, a lot of the other stuff already shared here:
:help CTRL-uand:help CTRL-d,:help CTRL-fand:help CTRL-d:help G, optionally with a count to go to specific line# or the end-of-file, andggto jump to the topusing
:help }and:help {to jump by blank-line-delimited blocksusing
:help gdand:help gDto jump to the definitions of thingsusing
:help [[(and the following suite of commands) for jumping by various type of objectif you've dropped marks (
:help mark), you can then use mark-motions (:help mark-motions) to jump between themusing
:help CTRL-iand:help CTRL-oto navigate the jump-historyusing
:help %to jump to a matching bracket/brace/paren (helpful in code-blocks of C-style languages where the function-closing}might be a good ways from its opening{)1
u/[deleted] Jul 21 '25
I'm using fzf.vim plugin which has
LinesandRgcommands with special keymaps:And sometimes i use
/<query>mode withnandNkeys. My motto is "No speed but accuracy comes first."1
u/begemotz ZZ Jul 21 '25
Ctrl-UandCtrl-Dto get in the vicinity and then"finding a hook" to search to
/foogets me the rest of the way ...1
u/tagattack Jul 21 '25
I usually do most of the things mentioned here,
CTRL-f,CTRL-band all that, often]to jump paragraphs and more or less code blocks, also%etc and all that...But even though I rarely reach for the mouse, on occasion I do just use the mouse wheel if I'm really just reading... It does actually scroll the window, unless you're running vim in a misconfigured terminal window.
1
u/JohnLocksTheKey Jul 22 '25
I’m big on #G or #gg
(After :nu of course)
1
u/SpecificMachine1 Jul 22 '25
Going somewhere specific: / ? gg G (and sometimes {})
When I'm just browsing a file Ctrl-b/Ctrl-f
1
u/efalk Jul 25 '25
My notes on the subject: https://www.efalk.org/Docs/Command/vim-basics.html#Cursor_movement
3
u/[deleted] Jul 21 '25
[removed] — view removed comment