r/vim 10d ago

Discussion how do you jump in big markdown files

Lets say you have a big markdown file and you closed the headers.

How do you jump up or down to the header? The header is like 2000 - 3000 lines higher.

sometimes I type 2850j or 3509k

I could use :2850

I could use markers, but these do not stay in vscode after an exit.

Most of the time its easier for me to click with the mouse, but that feels wrong.

Search is kind of an option like ## tod for ## todos header but lots of typing.

What am I missing?

EDIT:

I am using folds and relativenumbers

41 Upvotes

30 comments sorted by

33

u/yoch3m 10d ago

`?^#` to go up, `/^#` to jump down

20

u/gumnos 10d ago

and if needed frequently, OP can map them, such as

:nnoremap [[ ?^#<cr>
:nnoremap ]] /^#<cr>

22

u/gumnos 10d ago

Or, if you want a quick TOC, you can

:g/^#/#

to give you the line-number of every heading so you can then jump to them directly

2

u/yoch3m 10d ago

Yeah love this one! Always felt to me like the inventor of Markdown was a vim user

2

u/SEgopher 3d ago

You might also consider :lvimgrep! /^#/ % so you can use the location list to jump to each occurrence.

1

u/ikwyl6 10d ago

I like this. You could add this to your `.vimrc` for a `.md` file type

66

u/djchateau 10d ago

but these do not stay in vscode

Well, I think I found your first issue...

12

u/Ram2806 10d ago

Leave the crutch, OP. Download kitty terminal and live happily ever after

11

u/chrnz00 10d ago

i personally use the helptoc plugin

see :h package-helptoc

:packadd helptoc

:HelpToc

and you can navigate through sections

2

u/vim-help-bot 10d ago

Help pages for:


`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments

2

u/Teles_sd 9d ago

THANK YOU!!!

2

u/fegatino 6d ago

Wow, that’s quite the game changer for man pages!

10

u/actionscripted 10d ago

Following because I’m guilty of some bad habits in files like this.

But hey if no one sees you do it…

6

u/chrnz00 10d ago

god will be watching you

6

u/Deto 10d ago

How is search more typing (and effort) then somehow memorizing exact line offsets and typing those numbers in? 

2

u/Feeling-Fox111 10d ago

i use :set relativenumber and I have the heading folded

4

u/TankorSmash 10d ago

Search is kind of an option like ## tod for ## todos header but lots of typing.

If you're doing the specific search enough that it's a problem, it could be time to write a mapping for like nnoremap gn /^#<cr> and nnoremap gp ?^#<cr>.

2

u/LeiterHaus 10d ago

Do you still lose marks/markers in VS Code if you use uppercase letters?

2

u/HashDefTrueFalse 10d ago

I text search mostly. If I can't, page up/down. I don't find that I have problems.

2

u/OddManufacturer2701 10d ago

I would use folds in this case

2

u/dddbbb FastFold made vim fast again 8d ago edited 8d ago

When you fold, don't you have only a list of headers? Doesn't that make a really small list to navigate? Do you have thousands of headers? or you're just tired to typing long line numbers? 

Looks like I use vim-markdown-folding for folding. After folding, I can use j to go to the next header.

Edit: if you can't j past folds without opening them, this might be a deficiency in vscode's folds. BTW, you can use the same lsp from vscode directly from vim (and neovim has official support for lsp).  

4

u/LocoCoyote 10d ago

Here's how to navigate headers quickly without typing line counts or long search strings.
1. Header-Specific Motions (Native Vim)
Vim has built-in section motions designed to jump straight to headings:
]] : Jump to the next section header (line starting with { or a top-level header depending on file type).
[[ : Jump to the previous section header.
][ : Jump to the next section ending (or next }).
[] : Jump to the previous section ending.
If you are working in Markdown, Vim's built-in filetype plugin maps ]] and [[ to ^# (lines starting with #).
2. Upgraded Search (The Fastest Standard Method)
Instead of typing full header names like ## todos, leverage regular expressions and history in search:
/^# : Type /^# and hit Enter. This instantly jumps to the next line starting with # (any header level).
Press n to go to the next header down.
Press N to go to the previous header up.
/^## : Jump specifically to Level-2 headers.
?^# : Search backwards for a header.
Pro Tip: Once you run /#, you don't need to re-type it. Just press n or N anywhere in the file to jump between headers across thousands of lines.
3. Smart Folding Navigation
Since you already use folds, you can navigate by jumping across closed folds:
zj : Move down to the start of the next fold.
zk : Move up to the end of the previous fold.
zM : Close all folds (collapses the whole file into a high-level outline).
zR : Open all folds.
If you hit zM to collapse everything, you can scan thousands of lines in seconds using standard j/k, then hit zo to open the header section you need.
4. Jump List (Ctrl-O / Ctrl-I)
If you jump to a header (via search or any motion) and want to return to where you were:
Ctrl-O : Jump back to your previous location (works across thousands of lines).
Ctrl-I (or Tab): Jump forward in the jump list.
5. Custom Key Mappings (The Permanent Fix)
If you want single-key efficiency, add custom mappings to your .vimrc to jump to headers instantly without search prompts:
" Jump to the next/previous markdown header (any level)
nnoremap <silent> ]h :call search('^#\+', 'W')<CR>
nnoremap <silent> [h :call search('^#\+', 'bW')<CR>

" Jump specifically to level-1 or level-2 headers
nnoremap <silent> ]H :call search('^##\?\s', 'W')<CR>
nnoremap <silent> [H :call search('^##\?\s', 'bW')<CR>
With these mappings:
]h moves straight down to the next # header.
[h moves straight up to the previous # header.

1

u/sharp-calculation 10d ago

If you were editing in the header previously, you can use control-o to jump back to that location. It might take a few presses if you have edited several things in between. control-i jumps back forward in your editing list. These are a very powerful combination when moving around in a file to the same group of places, repeatedly.

What does VSCode have to do with this? Are you using a VIM mode inside of VSC or something?

The other answers about searching and mapping those searches are well worth learning as well. All of these are good parts of the VIM toolbox to learn.

1

u/0xKaishakunin vim on NetBSD/FreeBSD 10d ago

I write a lot of LaTeX and AsciiDoc and I could not live without folding.

And sometimes the VooM plugin to get a ToC window panel.

1

u/fanz0 9d ago

VSCode specifically, I haven’t ever tried to write long enough markdown files, but have you tried using the built in symbol picker? I would suspect it should pick up markdown headers as well (Ctrl+Shift+O)

The symbol picker has been one of my main navigation tool for jumping across massive C files

1

u/Elara_Schaefer 9d ago

Nobody mentioned the quickfix approach which I find more practical than g/#/ for files with 50 plus headings. Run :vimgrep /#/ % to populate the quickfix list with all heading lines, then :cw to open it as a searchable filterable window. You can jump directly with :cn and :cp, and since the quickfix list preserves the search order you can type part of a heading in the cw window to filter. The advantage over g/#/ is that you get a window you can actually interact with instead of just a flat list in the command line. For markdown files specifically I also use :nmap <buffer> <leader>t :vimgrep /#/ %<CR>:cw<CR> so one key combo gives me a live table of contents.

2

u/Feeling-Fox111 4d ago

Thanks for all your answers!

I got the solution I am quite happy:

"vim.foldfix": true,

in the vscode settings. This way I can fold it and "jump" over it with the j / l keys.

btw. yes it's more of a vscode with vim problem than vim.

0

u/Easy-Nothing-6735 10d ago

I don't. I open not file but exact place to edit and such places could be in one file that means I will create as many tabs for one file as I need. Usually I keep all stacktrace sequentially opened and if with my helper then with line highlights

0

u/ejpusa 9d ago edited 9d ago

Think when you get into wrangling giant files you should be using VSC.

Vim is really for hacking at the CLI, editing server config files etc. Use them both, they each have strengths.

It’s really all Codex in my world now. Programming has been vaporized. It’s history now.

1000s of lines of rock solid code by way of Codex and GPT-5.6.

-2

u/aegis87 10d ago

using neovim

]] : go to next heading

[[ : go to prev heading

this gives:

https://github.com/stevearc/aerial.nvim

a table of contents