How do I reverse the order of all lines in a file using Vim?
:g/^/m 0
This clever use of the :global command reverses every line in the current buffer.
command-line #editing #ex-commands #global #text-manipulation
:g/^/m 0
This clever use of the :global command reverses every line in the current buffer.
command-line #editing #ex-commands #global #text-manipulation
:terminal ++curwin
By default, :terminal opens a new split window for the terminal emulator.
buffers-windows #terminal #buffers #windows #shell #ex-commands
autocmd FileType python setlocal ts=4 sw=4 et
Using autocmd FileType, you can configure Vim to automatically apply buffer-local settings whenever a file of a particular type is opened.
:ilist /pattern/
The :ilist command searches for a pattern not only in the current buffer but also in files referenced by #include directives (or whatever 'include' is set to).
:syntax sync fromstart
Vim's syntax highlighting engine does not always parse the entire file from the beginning — it uses sync points to determine where to start parsing for the vi
:keepjumps
When writing scripts or running commands that move the cursor (like :g, :s, or :normal), Vim normally adds each cursor position to the jump list.
:cexpr system('grep -rn pattern .')
While :make and :grep populate the quickfix list, they are limited to their configured programs.
:lockmarks
Many Ex commands silently adjust or delete marks as a side effect of modifying buffer content.
:profile start profile.log | profile func *
When Vim feels sluggish during editing—not just at startup—you need runtime profiling to pinpoint which functions are consuming the most time.
config #profiling #debugging #config #ex-commands #performance
:ls +
The :ls command (or :buffers) supports filter flags that narrow the buffer list to specific states.
:%s/\<\w\+\>/\=toupper(submatch(0))/g
The \= flag in the replacement part of :substitute tells Vim to evaluate what follows as a Vimscript expression instead of treating it as a literal string.
:g/pattern/normal A;
The :global command combined with :normal lets you execute arbitrary normal mode keystrokes on every line that matches a pattern.
command-line #global #normal-mode #editing #ex-commands #batch-editing
:profile start /tmp/profile.log | profile func *
When Vim feels sluggish during editing (not just at startup), the :profile command lets you measure the execution time of every function call.
:&&
After running a :s/pattern/replacement/g command, you often need to repeat it on another line or range.
:cfdo %s/old/new/ge | update
When you grep across your project and want to perform a search-and-replace on every file that matched, :cfdo is the most efficient approach.
command-line #quickfix #substitute #search #ex-commands #editing
:%!xxd
Vim can serve as a hex editor by piping buffer contents through xxd, a hex dump utility that ships with Vim.
:cexpr system('command')
The :cexpr command parses any expression into the quickfix list using the current errorformat.
:/start/,/end/ {command}
Vim's range addressing lets you specify a line range using search patterns instead of explicit line numbers.
vim --startuptime /tmp/vim-startup.log
When Vim takes too long to start, the --startuptime flag writes a detailed timing log showing exactly how long each plugin, script, and initialization step take
:g/pattern/m $
The :g (global) command combined with :m (move) lets you collect all lines matching a pattern and relocate them to a specific position in the file.
command-line #ex-commands #editing #global #search #formatting