m' " Set previous context markm` " Same as m'm[ " Set start of last change/yankm] " Set end of last change/yankm< " Set start of last visual selectionm> " Set end of last visual selection
Vim maintains several special marks automatically:
Change Marks
Visual Marks
Position Marks
'[ " Start of last change/yank'] " End of last change/yank`[ " Exact start position`] " Exact end position'. " Position of last change`^ " Position of last insert
Example:
yap " Yank a paragraph`] " Jump to end of what was yanked
'< " Start of last visual selection'> " End of last visual selectiongv " Reselect last visual selection
Example:
viw " Select word<Esc> " Exit visual modegv " Reselect the word
'' " Position before last jump`` " Exact position before last jump'" " Position when last exiting buffer`" " Exact position when last exiting
" Mark important locationsmf " Mark function definitionmc " Mark callermt " Mark test" Jump between them'f " Go to function'c " Go to caller't " Go to test
File Bookmarks
" In main.luamM " Mark Main file" In config.luamC " Mark Config file" In utils.luamU " Mark Utils file" Jump between files'M " Go to main.lua'C " Go to config.lua'U " Go to utils.lua
Quick Return
" Before exploringmm " Mark current position" Explore code.../some_function<CR>gd " Go to definitionCTRL-O " Go back" Return to mark'm " Jump back to mark m
" Mark sectionsgg " Top of filemt " Mark top50% " Middlemm " Mark middleG " Bottommb " Mark bottom" Quick navigation't " Go to top'm " Go to middle'b " Go to bottom
" Jump optionsset jumpoptions=stack " Use stack-based jumplist" ShaDa settings (save marks)set shada='100,<50,s10,h" | | | |" | | | +-- no hlsearch on startup" | | +------ max 10KB per register" | +---------- max 50 lines per register " +--------------- remember marks for 100 files" Show marks in sign column (with plugin)" Plugin: vim-signature or similar" Convenient mark mappingsnnoremap <Leader>m :marks<CR>nnoremap <Leader>j :jumps<CR>nnoremap <Leader>c :changes<CR>
-- Jump optionsvim.opt.jumpoptions = 'stack'-- ShaDa settingsvim.opt.shada = "'100,<50,s10,h"-- Convenient mark mappingsvim.keymap.set('n', '<Leader>m', ':marks<CR>')vim.keymap.set('n', '<Leader>j', ':jumps<CR>')vim.keymap.set('n', '<Leader>c', ':changes<CR>')-- Auto-restore cursor positionvim.api.nvim_create_autocmd('BufReadPost', { pattern = '*', callback = function() local mark = vim.api.nvim_buf_get_mark(0, '"') local lcount = vim.api.nvim_buf_line_count(0) if mark[1] > 0 and mark[1] <= lcount then vim.api.nvim_win_set_cursor(0, mark) end end,})
Remember last position: Add to your config to restore cursor position:
vim.api.nvim_create_autocmd('BufReadPost', { callback = function() local mark = vim.api.nvim_buf_get_mark(0, '"') if mark[1] > 0 and mark[1] <= vim.api.nvim_buf_line_count(0) then vim.api.nvim_win_set_cursor(0, mark) end end,})
Mark Best Practices
Use lowercase for local navigation (within file)
Use uppercase for file bookmarks (between files)
Use mnemonic letters:
mt = top, mb = bottom
mf = function, mc = class
md = definition, mr = reference
Don’t overuse marks — jump list and change list often suffice
Clear old marks with :delmarks periodically
Jump List Workflow
Use search (/) to explore code
Jump to definitions with gd or CTRL-]
Return with CTRL-O (not '' unless you want to add to jumplist)
Use :jumps when lost in navigation
Clear jumplist with :clearjumps when starting new task