Personal Notes on 'Practical Vim' (2nd Edition)
I recently went through “Practical Vim - Second Edition” by Drew Neil to improve my Vim skills. Put together some notes that might be useful as a reference for anyone working with Vim.
These are highlights from various chapters that helped me work more efficiently.
Navigating with Ease
Unlock Vim’s potential for seamless movement:
H,M,L: Jump to the top, middle, and bottom of the screen, streamlining navigation.
Advanced File Management
Grasp Vim’s buffer-based file management for superior control:
:ls: Reveals the buffer landscape, highlighting the active buffer with%.- Navigate buffers effortlessly with
:bnext,:bprevious,:bfirst, and:blast.
Incorporate these mappings for fluid buffer navigation, borrowing from Tim Pope’s unimpaired.vim:
nnoremap <silent> [b :bprevious<CR>
nnoremap <silent> ]b :bnext<CR>
nnoremap <silent> [B :bfirst<CR>
nnoremap <silent> ]B :blast<CR>
Windows and Tabs: Enhancing Your Workspace
Exploring windows and tabs revolutionized my workflow:
:sp[lit]and:vsp[lit]: Splitting the screen is now second nature, allowing for multitasking efficiency.- Open files in splits with
:split {file}and:vsplit {file}, akin to finding direct paths to needed code. - Switching windows with
Ctrl-w w/h/j/k/lfeels like instant navigation, focusing precisely where needed. - Window management commands like
:clo[se],:on[ly], and resizing withCtrl-w =/_/|help tailor the workspace.
Organizing Work with Tabs:
:tabe {file}: Opening files in tabs organizes work into distinct contexts.- Tab navigation (
:tabn,:tabp,gt,gT) is like flipping through a book, each tab a new chapter of work. - Rearrange tabs to match workflow with
:tabmove n, organizing work logically.
Insight: Mastering window and tab management has transformed Vim from a text editor to a comprehensive coding environment.
Advanced Navigation and Marks:
Exploring advanced navigation and marks for pinpoint movement:
:jumpsandControl-o/iact as a navigational history, retracing steps efficiently.- Setting marks (
m, backtick commands) pinpoints important code sections for quick returns.
Tip: Use marks to easily navigate to frequently visited or important code sections.
Macro Magic:
Macros (q) automate repetitive tasks, becoming a vital tool:
- Recording macros captures sequences for reuse with
@a. - Applying macros across lines or files simplifies complex tasks.
- Macros with variables (
:let i += 1) unlock dynamic automation possibilities.
Note: Macros are indispensable in Vim, turning tedious edits into simple commands.
Pattern Matching and Search Literacy:
Pattern matching enhances search capabilities, turning complex searches into simple tasks:
- Case-insensitive searches (
/\c) and “very magic” mode (\v) refine search capabilities. - Literal searches (
\V) pinpoint exact matches, simplifying regex searches. - Reusing the last search pattern in substitutions streamlines text replacements.
Pro Tip: Becoming proficient in Vim’s search and replace commands is like mastering a secret language, enabling precise text manipulations.
Customizing .vimrc:
Personalizing .vimrc unlocks Vim’s full potential:
- Setting a “leader key” (
let mapleader = ",") customizes shortcuts. - Implementing autosave (
autocmd InsertLeave,TextChanged * silent write) safeguards work. - Auto-formatting (
autocmd BufWritePre * :normal gg=G) ensures consistent code style.
Insight: Personalizing .vimrc enhances Vim, making everyday tasks more intuitive and efficient.
TLDR
“Practical Vim” covers a lot of useful functionality that’s easy to miss otherwise. These notes capture what I found most practical. Hope they’re useful for your own Vim setup.