How do I open the current file in a preview window at a specific pattern?
:pedit +/TODO %
When you need a second read-only view of the same file, opening more normal splits can disrupt your working layout.
:pedit +/TODO %
When you need a second read-only view of the same file, opening more normal splits can disrupt your working layout.
:arglocal
By default, Vim's argument list is global, so changing it in one window can unexpectedly affect another workflow in a different tab or split.
:set sessionoptions+=globals,localoptions
If you rely on sessions for context switching, default :mksession can feel incomplete because some state does not come back.
:execute 'vimgrep /' . @/ . '/gj **/*'
If you already refined a search interactively with / or ?, retyping that pattern for project-wide grep is repetitive and error-prone.
:setlocal errorformat=%f:%l:%c:%m | cexpr system('tool %') | copen
Not every linter or internal script speaks Vim quickfix format out of the box.
command-line #command-line #quickfix #errorformat #linting #workflow
:set viewoptions=folds,cursor,slash,unix
mkview and loadview are great for restoring editing context, but the default viewoptions can bring back more state than you actually want.
:packadd cfilter | Lfilter /pattern/
When you already have a populated location list, rerunning the original search just to focus on a subset is slow and disruptive.
:command! -nargs=* -complete=file W w <args>
When you repeatedly type a long Ex command with filenames, define a user command that keeps the behavior but shortens the keystrokes.
command-line #command-line #ex-commands #completion #workflow
:set jumpoptions+=stack,view
When you jump around large files with and , the default behavior can feel disorienting because your cursor position may return but your viewport context does no
:tab sbuffer
Sometimes you want a second workspace for the same file: one tab for broad navigation, another for focused edits or test-driven jumps.
buffers-windows #buffers-windows #tabs #workflow #navigation
:let @+ = @0
When you yank text in Vim, register 0 always holds the most recent yank, independent of deletes that may have changed the unnamed register.
:Obsession
If you routinely work across many files, tabs, and split layouts, rebuilding your workspace after a restart is costly.
plugins #plugins #sessions #workflow #buffers-windows #productivity
:set jumpoptions+=stack
By default, Vim's jumplist can feel surprising: if you jump backward and then make a new jump, the old forward path is not always discarded like a browser histo
cnoreabbrev w!! w !sudo tee > /dev/null %
When you forget to open a file with elevated privileges, quitting and reopening can break your flow.
command-line #command-line #abbreviations #sudo #write #workflow
:debug normal @q
Recorded macros are powerful, but when one keystroke goes wrong they can fail fast and leave confusing state behind.
:e archive.tar::path/to/file
Vim's built-in tar.
:set noequalalways
When you work with carefully sized splits, Vim's default behavior can feel disruptive: opening or closing a window triggers an automatic rebalance.
:vimgrep /{pattern}/j **/*
For project-wide searches, :vimgrep is powerful but can feel disruptive if it jumps into files while populating quickfix.
:filter /{pattern}/ history cmd
When command history gets crowded, scanning :history cmd manually is slow.
:keepalt edit {file}<CR>
The alternate-file mark (#) powers fast toggles like and commands that depend on the previous file context.
command-line #command-line #buffers #workflow #navigation #advanced