7 Powerful Vim Tricks to Supercharge Your Coding Efficiency
Discover seven practical Vim techniques—including key remappings, efficient cursor navigation, Git integration, test automation, and powerful substitution commands—that help both beginners and seasoned users boost productivity and streamline their development workflow.
1. Remap the ESC key
Mapping a more convenient key sequence to ESC reduces hand movement; a common shortcut is: inoremap jj <ESC> This lets you exit insert mode by typing jj quickly.
2. Redefine the Leader key
The Leader key acts as a prefix for custom shortcuts. You can set it to a comfortable character, such as a comma, and then bind commands like: nnoremap j VipJ Pressing ,j (comma followed by j) visually selects an entire paragraph and copies it.
let mapleader = ","3. Efficient cursor movement
Vim’s normal‑mode keys h, j, k, l move the cursor left, down, up, and right. Prefixing with a count repeats the motion, e.g., 3j moves three lines down. Additional useful motions include: ^ – jump to the start of the line $ – jump to the end of the line gg – go to the first line of the file G – go to the last line nG or ngg – go to line n (e.g., 10G)
4. Speed up Ctrl‑P in Git projects
Add the following configuration to .vimrc to make Ctrl‑P use ag (if available) or fall back to Git and find for fast file searching:
et g:ctrlp_use_caching = 0
if executable('ag')
set grepprg=ag --nogroup --nocolor
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
else
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
let g:ctrlp_prompt_mappings = {
'AcceptSelection("e")': ['<space>', '<cr>', '<2-LeftMouse>'],
}
endifIt is recommended to install the vim-scripts/gitignore plugin for better ignore‑file handling.
5. Accelerate unit‑test execution
Using the vim‑vroom plugin together with a tmux layout lets you run tests inside a dedicated pane. The default vim‑vroom command is <Leader>r; after remapping Leader to <Space>, you can start tests with <Space>r while watching progress in another pane.
6. Execute normal‑mode commands from the command line
The :normal command runs normal‑mode keystrokes while in command‑line mode. This is handy for batch edits. For example, to prepend a dash to selected lines in a Markdown file, select the lines with V and then execute: :'<,'>normal I- This inserts - at the beginning of each selected line.
7. Powerful substitution with :s
The :substitute (or :s) command replaces text in a given range. To delete trailing spaces on every line in the current buffer, run: :%s= *$== Here % denotes the whole file, and *$ matches any number of spaces at the end of a line.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
