How do I control how many columns Vim scrolls horizontally at once when the cursor reaches the screen edge?
When wrap is off and the cursor moves past the edge of the screen, Vim jumps the view horizontally by a number of columns determined by sidescroll.
category:
config
tags:
#config
#navigation
#editing
How do I refer to all files in the argument list at once in an Ex command?
The ## special token expands to the names of all files currently in Vim's argument list.
category:
command-line
tags:
#command-line
#buffers
#ex-commands
#search
How do I save just the visually selected lines to a new file?
After making a visual selection, you can write only those lines to a new file using :'w {filename}.
category:
visual-mode
tags:
#visual-mode
#editing
#ex-commands
How do I sort lines in Vim without caring about upper or lower case?
By default, :sort uses byte-value ordering, which places all uppercase letters before lowercase.
category:
command-line
tags:
#editing
#ex-commands
#command-line
How do I sort lines while ignoring a leading prefix like a key or label?
The :sort /{pattern}/ command sorts lines by their content after the first match of the pattern.
category:
command-line
tags:
#editing
#ex-commands
#command-line
How do I define a mapping that only takes effect if the key is not already mapped?
:map <unique> {key} {rhs}
The modifier causes Vim to fail with an error if you try to create a mapping for a key that is already mapped in that mode.
category:
config
tags:
#config
#ex-commands
How do I create abbreviations for the Vim command line to fix typos like W and Q?
:cnoreabbrev defines a non-recursive command-line abbreviation — like noremap but for Ex commands.
category:
command-line
tags:
#command-line
#ex-commands
#config
How do I use lambda functions in Vimscript to filter or transform lists?
Vim 8.
category:
config
tags:
#config
#ex-commands
How do I re-open a file in Vim with a specific encoding without restarting?
When Vim auto-detects the wrong character encoding — mojibake where é shows as é is a classic symptom — you can reload the current buffer with a specifi
category:
command-line
tags:
#command-line
#buffers
#ex-commands
How do I create a dynamic abbreviation that inserts live content like the current date?
:iabbrev <expr> {trigger} {expression}
The flag on :iabbrev turns the right-hand side into a Vimscript expression that is evaluated at expansion time rather than stored as a literal string.
category:
config
tags:
#config
#insert-mode
#abbreviations
#ex-commands
How do I get just the filename without its path or extension to use in a command?
Vim's % special character expands to the current filename and accepts a chain of colon-delimited modifiers.
category:
command-line
tags:
#command-line
#ex-commands
#editing
#navigation
How do I change the cursor shape to a thin bar in insert mode and a block in normal mode in Neovim?
:set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20
Neovim's guicursor option lets you assign a distinct cursor shape and style to each mode, providing immediate visual feedback about which mode you are in.
category:
config
tags:
#config
#normal-mode
#insert-mode
#visual-mode
How do I resize the current window to an exact number of lines from the command line?
The z{height} command simultaneously resizes the current window to exactly {height} lines, scrolls so the current line sits at the top of the window, and moves
category:
buffers-windows
tags:
#buffers-windows
#windows
#resize
#navigation
How do I run an external shell command from Vim without the press-enter prompt afterward?
Running :!cmd in Vim shows the command's output and then pauses with a "Press ENTER or type command to continue" prompt.
category:
command-line
tags:
#command-line
#ex-commands
#shell
#editing
How do I set up a local leader key for file-type-specific mappings that don't conflict with global mappings?
:let maplocalleader = ','
Vim provides two separate leader keys: (global) and (local to the current buffer).
category:
config
tags:
#config
#normal-mode
#ex-commands
How do I save and automatically restore a buffer's fold state and cursor position across Vim sessions?
:mkview saves a snapshot of the current window — its fold states, cursor position, and local option values — to a view file on disk.
category:
buffers-windows
tags:
#folding
#buffers-windows
#config
#ex-commands
How do I force-convert all indentation including tabs in the middle of lines throughout an entire file?
The :retab command converts leading whitespace according to the current tabstop and expandtab settings, but it only touches indentation at the start of lines.
category:
editing
tags:
#editing
#indentation
#formatting
#ex-commands
How do I create a normal mode mapping that correctly captures and passes a count prefix to a function?
nnoremap <key> :<C-u>call MyFunc(v:count)<CR>
When writing custom mappings that call Vimscript functions, a common pitfall is that any count you type before the key (e.
category:
config
tags:
#config
#macros
#ex-commands
#normal-mode
How do I restrict a substitution to the range between two named marks?
Named marks can serve as range endpoints for any Ex command, including :substitute.
category:
search
tags:
#search
#marks
#substitution
#ex-commands
#editing
How do I quickly delete all lines in the current buffer?
The % range address in Ex commands stands for the entire file — it is shorthand for 1,$ (first line to last line).
category:
command-line
tags:
#ex-commands
#editing
#command-line