How do I make Vim automatically jump to where I last edited when reopening a file?
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
Vim remembers the last cursor position for every file you edit (stored in the viminfo or shada file), but by default it opens files at line 1.
category:
config
tags:
#config
#autocmd
#navigation
#vimrc
#productivity
How do I encrypt a file directly in Vim?
The :X command sets an encryption key for the current file.
category:
command-line
tags:
#command-line
#security
#file-management
#ex-commands
How do I visually select an entire sentence in Vim?
The vas command visually selects the current sentence, including surrounding whitespace.
category:
visual-mode
tags:
#visual-mode
#text-objects
#motions
How do I convert selected text to uppercase?
In visual mode, pressing U converts all selected text to uppercase.
category:
visual-mode
tags:
#visual-mode
#editing
How do I quickly jump between method or function definitions in code?
The ]m and [m motions let you jump forward and backward between the start of method or function definitions.
category:
navigation
tags:
#navigation
#motions
#normal-mode
#editing
How do I paste from a register while staying in insert mode?
Pressing followed by a register name in insert mode inserts the contents of that register at the cursor position without leaving insert mode.
category:
registers
tags:
#editing
#insert-mode
#registers
#productivity
How do I create a custom operator that works with motions and text objects?
:set operatorfunc=MyFunc<CR>g@
Vim lets you define custom operators that behave like built-in ones (d, c, y) — they wait for a motion or text object, then act on the selected region.
category:
config
tags:
#config
#normal-mode
#motions
#text-objects
#mapping
How do I edit a binary file in hex mode using Vim?
Vim can serve as a hex editor by piping buffer contents through xxd, a hex dump utility that ships with Vim.
category:
editing
tags:
#editing
#binary
#ex-commands
#filters
How do I center the screen on my cursor without leaving insert mode?
When you are typing in insert mode and the cursor drifts near the top or bottom of the screen, you normally have to press , then zz, then i or a to continue edi
category:
navigation
tags:
#navigation
#insert-mode
#scrolling
#normal-mode
How do I display a vertical line at a specific column width?
The :set colorcolumn=80 command displays a vertical highlight at column 80, giving you a visual guide for line length.
category:
config
tags:
#config
#formatting
#ex-commands
How do I scroll up half a page in Vim?
The (Ctrl+u) command scrolls the window up by half a screen, moving the cursor along with it.
category:
navigation
tags:
#navigation
#motions
#normal-mode
How do I set a colorscheme with a fallback in case it is not installed?
try | colorscheme gruvbox | catch | colorscheme default | endtry
How it works When you share your vimrc across multiple machines, a colorscheme you have installed on one system may not exist on another.
category:
config
tags:
#editing
#formatting
How do I combine multiple Ex commands into a single undo step in Vim?
When writing Vim scripts or running multiple Ex commands, each command normally creates a separate undo entry.
category:
command-line
tags:
#undo-redo
#ex-commands
#editing
How do I search for a pattern only within specific columns of a line?
When working with columnar data like CSV files, log files, or fixed-width records, you often need to match a pattern only when it appears in a specific column r
category:
search
tags:
#search
#regex
#navigation
#ex-commands
How do I resize a window horizontally?
The > and > increases width by 1 column > increases width by 10 columns maximizes the window width Example With a vertical split, 20> gives the current window 2
category:
buffers-windows
tags:
#windows
#normal-mode
How do I clear search highlights without disabling hlsearch permanently?
After a search in Vim, matched text is highlighted as long as hlsearch is enabled.
category:
search
tags:
#search
#hlsearch
#highlight
#ex-commands
How do I list all open buffers in Vim?
The :ls command displays a list of all open buffers in Vim, showing their buffer number, status indicators, file name, and the line the cursor was last on.
category:
buffers-windows
tags:
#buffers
#ex-commands
#navigation
How do I define or fix a macro using Vimscript instead of re-recording it?
Macros in Vim are just text stored in named registers.
category:
macros
tags:
#macros
#registers
#ex-commands
How do I edit a recorded macro without re-recording it from scratch?
Macros are stored as plain text in named registers.
category:
macros
tags:
#macros
#registers
#editing
How do I open a file in a new tab or switch to it if it is already open?
When working with many tabs, you often want to open a file — but only if it is not already open somewhere.
category:
buffers-windows
tags:
#buffers
#tabs
#navigation
#windows