vimtricks.wiki Concise Vim tricks, one at a time.

How do I view all symbols in the current file using Neovim's built-in LSP?

Answer

gO

Explanation

Since Neovim 0.10, gO is a default LSP keymap that calls vim.lsp.buf.document_symbol(). It opens a floating list of all symbols (functions, classes, variables, methods) defined in the current file as reported by the attached language server, letting you quickly jump to any symbol.

How it works

  • Press gO in normal mode when an LSP client is attached
  • Neovim opens a quickfix-style list (or the built-in symbol picker depending on your setup) showing all document symbols
  • Navigate to the desired symbol and press <CR> to jump to it
  • The keymap is only active in buffers with an attached LSP client

Example

In a Python file with pyright attached:

gO opens a list:
  Class MyApp (line 5)
    Method __init__ (line 6)
    Method run (line 12)
  Function helper (line 25)
  Function main (line 40)

Select Method run and press <CR> to jump to line 12.

Tips

  • gO complements the other 0.10+ defaults: grr (rename), gra (code action), gri (go to implementation)
  • If you use telescope.nvim or fzf-lua, set vim.lsp.handlers['textDocument/documentSymbol'] to use their pickers for a richer UI
  • For workspace-level symbols (across files), use :lua vim.lsp.buf.workspace_symbol() — there is no default keymap for this one
  • Combine with :lua vim.lsp.buf.references() to see where each symbol is used

Next

How do I make Neovim restore the scroll position when navigating back through the jump list?