LSP-powered navigation including go-to-definition, find references, type definitions, and implementations. Provides semantic code understanding for efficient codebase exploration with language server integration and intelligent symbol resolution.
Navigate to symbol definitions and declarations with LSP-powered semantic understanding across files and projects.
<Plug>(coc-definition)
" Jump to definition of symbol under cursor
" Uses LSP textDocument/definition request
" Mode: Normal
<Plug>(coc-declaration)
" Jump to declaration of symbol under cursor
" Uses LSP textDocument/declaration request
" Mode: Normal
<Plug>(coc-type-definition)
" Jump to type definition of symbol under cursor
" Uses LSP textDocument/typeDefinition request
" Mode: Normal
<Plug>(coc-implementation)
" Jump to implementation of symbol under cursor
" Uses LSP textDocument/implementation request
" Mode: NormalUsage Examples:
" Standard navigation mappings
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gD <Plug>(coc-declaration)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
" Alternative mappings
nmap <silent> <C-]> <Plug>(coc-definition)
nmap <silent> <C-w>] :call CocAction('jumpDefinition', 'split')<CR>
nmap <silent> <C-w><C-]> :call CocAction('jumpDefinition', 'vsplit')<CR>Find all references and usages of symbols with comprehensive search across workspace and dependencies.
<Plug>(coc-references)
" Find all references to symbol under cursor
" Uses LSP textDocument/references request
" Opens results in location list
" Mode: Normal
<Plug>(coc-references-used)
" Find references excluding definition
" Shows only usage locations
" Mode: Normal
CocAction('jumpReferences')
" Jump to references programmatically
" Returns: void
CocLocations({id}, 'textDocument/references', {params})
" Get reference locations from specific language server
" Parameters:
" {id} - string: language server id
" {params} - dict: LSP reference parameters
" Returns: array of location objectsUsage Examples:
" Find references mapping
nmap <silent> gr <Plug>(coc-references)
" Find usages only (exclude definition)
nmap <silent> gu <Plug>(coc-references-used)
" Custom reference handling
function! ShowReferences()
let references = CocAction('getReferences')
if len(references) == 0
echo "No references found"
else
echo "Found " . len(references) . " references"
CocList references
endif
endfunction
nmap <silent> <space>r :call ShowReferences()<CR>Navigate symbols within files and across the entire workspace with fuzzy finding and hierarchical display.
:CocList symbols
" List document symbols with fuzzy finder
" Shows functions, classes, variables, etc.
:CocList -I symbols
" Interactive symbol search across workspace
" Searches all workspace files
:CocCommand document.showOutline
" Show document outline in sidebar
" Hierarchical symbol tree view
CocAction('documentSymbols')
" Get document symbols programmatically
" Returns: array of symbol objects
CocAction('workspaceSymbols', {query})
" Search workspace symbols
" Parameters:
" {query} - string: search query
" Returns: array of symbol objectsUsage Examples:
" Symbol navigation mappings
nnoremap <silent> <space>o :CocList outline<CR>
nnoremap <silent> <space>s :CocList -I symbols<CR>
" Show document outline
nnoremap <silent> <space>O :CocCommand document.showOutline<CR>
" Search for specific symbol
function! SearchSymbol(query)
let symbols = CocAction('workspaceSymbols', a:query)
if len(symbols) > 0
call setloclist(0, [], 'r', {'title': 'Symbols', 'items': symbols})
lopen
else
echo "No symbols found for: " . a:query
endif
endfunction
command! -nargs=1 SearchSymbol call SearchSymbol(<q-args>)Manage navigation history with jump lists and location stacks for efficient code exploration.
CocAction('jumpDefinition' [, {command}])
" Jump to definition with custom command
" Parameters:
" {command} - string: 'edit'|'split'|'vsplit'|'tabe' (optional)
" Returns: boolean - success status
CocAction('jumpDeclaration' [, {command}])
" Jump to declaration with opening command
CocAction('jumpImplementation' [, {command}])
" Jump to implementation with opening command
CocAction('jumpTypeDefinition' [, {command}])
" Jump to type definition with opening command
CocAction('jumpReferences' [, {command}])
" Jump to references with opening commandUsage Examples:
" Jump with split windows
nnoremap <silent> <C-w>gd :call CocAction('jumpDefinition', 'split')<CR>
nnoremap <silent> <C-w>gD :call CocAction('jumpDefinition', 'vsplit')<CR>
nnoremap <silent> <C-w>gt :call CocAction('jumpDefinition', 'tabe')<CR>
" Navigation history management
nnoremap <silent> <C-o> <C-o> " Built-in jump back
nnoremap <silent> <C-i> <C-i> " Built-in jump forward
" Custom jump with history preservation
function! JumpWithHistory(action)
" Add current position to jump list
normal! m'
call CocAction(a:action)
endfunction
nnoremap <silent> gD :call JumpWithHistory('jumpDefinition')<CR>Navigate to external links and URLs in code comments and documentation.
<Plug>(coc-openlink)
" Open link under cursor in browser
" Detects URLs in comments and strings
" Mode: Normal
CocAction('openLink')
" Open link programmatically
" Returns: boolean - success statusUsage Examples:
" Open link mapping
nmap <silent> gx <Plug>(coc-openlink)
" Custom link handler
function! OpenLinkOrFallback()
if CocAction('openLink')
echo "Link opened"
else
" Fallback to Vim's built-in gx behavior
normal! gx
endif
endfunction
nmap <silent> gX :call OpenLinkOrFallback()<CR>Navigate across different languages and external dependencies with language server coordination.
CocLocations({id}, {method} [, {params}] [, {openCommand}])
" Get locations from specific language server
" Parameters:
" {id} - string: language server id
" {method} - string: LSP method name
" {params} - dict: method parameters
" {openCommand} - string: how to open results
" Returns: void (opens results directly)
CocLocationsAsync({id}, {method} [, {params}] [, {openCommand}])
" Async version of CocLocations
" Callback-based for non-blocking operationUsage Examples:
" Cross-language navigation for polyglot projects
function! CrossLanguageDefinition()
let filetype = &filetype
if filetype == 'typescript'
call CocLocations('typescript', 'textDocument/definition')
elseif filetype == 'python'
call CocLocations('python', 'textDocument/definition')
else
" Fallback to generic definition
normal! gd
endif
endfunction
" Navigate to external dependencies
function! GoToExternalDefinition()
let word = expand('<cword>')
let results = CocAction('jumpDefinition')
" Check if we jumped to an external file
let current_file = expand('%:p')
if stridx(current_file, 'node_modules') != -1
echo "Navigated to external dependency: " . fnamemodify(current_file, ':t')
endif
endfunctionNavigate to links, URLs, and external resources referenced in code and documentation.
<Plug>(coc-openlink)
" Open link under cursor
" Handles URLs, file paths, and custom link formats
" Mode: Normal
CocAction('openLink')
" Open link programmatically
" Returns: boolean - success status
CocAction('links')
" Get all links in current document
" Returns: array of link objectsUsage Examples:
" Open link mapping
nmap <silent> <space>l <Plug>(coc-openlink)
" Custom link handling
function! SmartOpenLink()
let links = CocAction('links')
let line = line('.')
let col = col('.')
for link in links
if link.range.start.line + 1 == line &&
\ link.range.start.character <= col &&
\ link.range.end.character >= col
call CocAction('openLink')
return
endif
endfor
" Fallback to built-in gx
normal! gx
endfunction
nmap <silent> gx :call SmartOpenLink()<CR>