How do I save and restore the cursor position and scroll state in a Vimscript function?
winsaveview() and winrestview()
When writing Vimscript functions or complex mappings that move the cursor, it is essential to restore the original view afterward so the user does not notice an
category:
config
tags:
#ex-commands
#normal-mode
How do I view the git history for the current file as a navigable quickfix list using vim-fugitive?
Running :Gclog in vim-fugitive loads the git log for the current file into the quickfix list.
category:
plugins
tags:
#plugins
#git
#buffers
#quickfix
How do I cycle through the numbered delete registers using the dot command?
When you paste from a numbered register with "1p, Vim's dot command (.
category:
registers
tags:
#registers
#editing
#normal-mode
#undo-redo
How do I open the alternate file in a new split window without typing its name?
Press (Ctrl+W followed by Ctrl+6) to open the alternate file in a horizontal split.
category:
buffers-windows
tags:
#buffers-windows
#navigation
#buffers
How do I insert the entire current line into the command line without typing it?
Pressing on the command line inserts the full text of the current buffer line (the line the cursor is on when you pressed :) directly at the command-line cursor
category:
command-line
tags:
#command-line
#editing
#navigation
How do I navigate Vim's undo tree branches to access states that u and Ctrl-R can't reach?
Vim's undo history is a tree, not a linear stack.
category:
editing
tags:
#undo-redo
#normal-mode
#editing
How do I split a complex Vim macro into reusable subroutines?
Record worker macro in @b, call it from @a with @b
Complex macros are hard to debug and maintain when crammed into a single register.
category:
macros
tags:
#macros
#registers
#editing
How do I delete text from the cursor to the next occurrence of a pattern?
Vim lets you use a / search as a motion for any operator.
category:
editing
tags:
#editing
#search
#motions
#delete
#normal-mode
How do I open a Telescope picker result in a split or new tab instead of the current window?
<C-x> / <C-v> / <C-t> (in Telescope)
When browsing results in a Telescope picker, you are not limited to opening selections in the current window.
category:
plugins
tags:
#navigation
#buffers-windows
#tabs
#plugins
How do I jump back and forth between my two most recent cursor positions?
Vim maintains a jumplist — a history of every "jump" you make (searches, marks, gg, G, %, etc.
category:
navigation
tags:
#navigation
#jumplist
#motions
#workflow
How do I jump to the local or global declaration of the variable under the cursor without ctags?
Vim's gd and gD commands jump to the declaration of the identifier under the cursor by searching upward through the file — no ctags setup required.
category:
navigation
tags:
#navigation
#editing
#normal-mode
How do I jump to a specific character on the current line?
The f{char} command moves the cursor forward to the next occurrence of {char} on the current line.
category:
navigation
tags:
#navigation
#motions
#normal-mode
How do I jump to the Nth line from the top or bottom of the visible screen using a count with H and L?
Most Vim users know H jumps to the first visible line, M to the middle, and L to the last.
category:
navigation
tags:
#navigation
#motions
#normal-mode
How do I write a Vim regex lookahead that doesn't consume a capture group slot?
Vim's lookahead assertion \@= confirms that the current position is followed by a pattern — without including those characters in the match.
category:
search
tags:
#search
#regex
#lookahead
#patterns
#normal-mode
How do I profile Vim startup time to find out which plugins are slowing it down?
vim --startuptime /tmp/vim-startup.log +qall && sort -k2 -rn /tmp/vim-startup.log | head -20
When Vim starts slowly, the --startuptime flag writes a timestamped log of every script and plugin loaded during initialization.
category:
config
tags:
#config
#performance
#startup
#profiling
#plugins
How do I run the same normal mode command on every line in a range?
The :normal (or :norm) command lets you execute normal mode keystrokes from the command line.
category:
command-line
tags:
#editing
#ex-commands
#normal-mode
#productivity
#ranges
How do I record a macro that performs a search and replace on each line?
How it works You can combine Ex commands like :s (substitute) with macro recording to create powerful repeatable find-and-replace operations that go beyond what
category:
macros
tags:
#macros
#ex-commands
#search
#editing
How do I run a macro on every line in a specific line number range?
The :normal command lets you execute Normal mode keystrokes over a range of lines.
category:
macros
tags:
#macros
#normal
#range
#ex-commands
How do I list all lines in the current file matching the word under my cursor?
How it works The [I command searches the current file (and included files) for the word under the cursor and displays a list of all matching lines with their li
category:
search
tags:
#search
#navigation
#normal-mode
How do I view the list of positions I have jumped to in Vim?
How it works Vim keeps a jump list that records your cursor position every time you make a jump.
category:
navigation
tags:
#navigation
#ex-commands
#normal-mode