← Back to references

NVIM.md

Download Raw

NVIM

Essential NVIM (Vim) Tips and Tricks

This guide covers all main tips from the referenced video and expands on them with additional useful NVIM commands, especially for movement, editing, and productivity.

Core Commands from the Video

1. Start, Exit, and File Management

  • Open file in NVIM: nvim filename
  • Quit: :q
  • Save: :w
  • Save and Quit: :wq
  • Quit without saving: :q!

2. Basic Navigation

  • Move left/right/up/down: h j k l
  • Word movement: w (next word), b (previous word)
  • Line start/end: 0 moves to beginning, ^ to first non-whitespace, $ to end of line.
  • First/Last Line: gg (first), G (last)

3. Search and Replace

  • Find word under cursor: * (searches current word)
  • Navigate matches: n (next), N (previous)
  • Replace word under cursor: ciw (change inner word)
  • Repeat last change: . (dot)
  • Global Replace:
  • :%s/old/new/g (all occurrences)
  • :%s/old/new/gc (with confirmation)

4. Visual Mode and Editing

  • Select: v (character), V (line), Ctrl-v (block/column)
  • Yank (copy): y (or yy for line), or after selecting, press y
  • Paste: p (after cursor), P (before cursor)
  • Delete: d (or dd for line)

5. Registers and Clipboard

  • Show registers: :registers or :reg
  • Paste from specific register: "2p (pastes content of register 2)
  • Yank to a register: "ayy (yank line to register a)
  • System clipboard:
  • Linux: "+y (copy), "+p (paste)
  • Mac: "*y, "*p
  • Show file name: "%p (paste current filename)

6. Macros (Automate Tasks)

  • Record macro: q[a-z] (e.g., qh)
  • Stop recording: q
  • Run macro: @h
  • Run N times: 5@h

Expanded: Additional Useful NVIM/Vim Tips

Moving Around

Command What it Does
0 Start of current line
^ First non-blank character of line
$ End of line
g_ Last non-blank character of line
gg Top of file
G Bottom of file
{ / } Previous/next paragraph or code block
w / b Next/previous word
e / ge End of word/previous end of word
% Go to matching brace/parenthesis ((), {}, [])
f Jump to character (forward in current line)
F Jump to character (backward in current line)
; / , Repeat last f, t, F, or T (forward/backward)
zz Center cursor in window

Editing Tricks

  • Join lines: J
  • Undo: u
  • Redo: Ctrl + r
  • Cut (delete): d (or dd for line)
  • Change motion: c (e.g., cw to change word)
  • Replace single character: r
  • Visual block insert: Ctrl-v, select block, then I (type, then ESC)

Inserting Lines

  • Insert below: o (insert mode, new line below)
  • Insert above: O (insert mode, new line above)
  • Append at end: A
  • Insert at beginning: I

Window Management (Splits)

  • Horizontal split: :sp filename
  • Vertical split: :vsp filename
  • Move between splits: Ctrl-w h/j/k/l
  • Resize split: Ctrl-w + (increase), Ctrl-w - (decrease)
  • Equalize splits: Ctrl-w =

Buffers

  • Next/previous buffer: :bn / :bp
  • List buffers: :ls or :buffers
  • Switch buffer: :b
  • Search for pattern: /pattern
  • Previous match: ?pattern
  • Repeat search: n/N
  • Replace in selection: :'s/old/new/g

Miscellaneous

  • Repeat last command: .
  • Indent line(s): >> (right), << (left)
  • Commenting (with plugin): Use gcc/gc with Commentary/NERDCommenter plugins.
  • Move by screen lines: gj (down), gk (up)
  • Open help: :h command
  • Recording last edit position: '
  • Working with tabs: :tabnew, gt (next), gT (previous)
  • Open files with XXD: Open file with -b for binary then run :%!xxd to switch to hex view. Undo with :%!xxd -r.

Quick Reference Table: Movement and Editing

Task Command
Start of line 0 or ^
End of line $ or g_
First/last line gg / G
Next/prev word w / b
Move between windows Ctrl-w h/j/k/l
Insert line below/above o / O
Undo / redo u / Ctrl-r
Visual mode v (char), V (line), Ctrl-v (block)
Find/replace :%s/foo/bar/g
Open in XXD :%!xxd and undo :%!xxd -r

Tips for Efficient Editing

  • Prefix commands with numbers: 5j (move down 5 lines), 3dd (delete 3 lines).
  • Combine motions: d$ (delete to end of line), y0 (yank to start).
  • Persistent yanks: Use registers to avoid overwriting clipboard.
  • Macros for repetition: Automate changes across many lines quickly.
  • System clipboard: Use "+y and "+p to access global clipboard (for interchange with other programs).

Explore the Neovim/Vim documentation (:h subject) for even more functions and to customize your workflow further. This combination of tips will dramatically boost your movement, editing, and overall efficiency in NVIM.

10 Quirky, Mind-Blowing Vim Tricks (Expanded)

Here are the ten quirky Vim tricks highlighted in the video, with expanded explanations and practical usage details for each[1].

1. ROT13 Encryption with g?

What it is:
ROT13 is a simple letter substitution cipher replacing each letter with the letter 13 positions later in the alphabet.

How to use:

  • In visual mode, select the text you want to ROT13.
  • Type g? (g + question mark).

Examples and expansion:
Useful for hiding spoilers, harmless pranks, or puzzles in plaintext files. ROT13 is not secure, but it’s built-in, quick, and reversible—apply it again to decrypt.

2. Insert Random Data from /dev/urandom

What it is:
Inserts random bytes (often non-printable) into your buffer directly from the system’s random data generator.

How to use:

  • In command mode, type:
    :read !head -c 100 /dev/urandom

Use cases and tips:
While mostly a novelty, this is handy for testing how scripts, applications, or editors handle binary or random input. Change the number after -c for a different byte length.

3. Browse the Web (Sort Of) with Netrw

What it is:
Vim’s netrw plugin can open local files, and with proper compilation (with libcurl), even fetch remote files (FTP, SCP, sometimes HTTP).

How to use:

  • In command mode, type:
    :e http://example.com

Expansion:
This loads the HTML source of the page into your buffer. Excellent for viewing source code, raw HTML, or grabbing data from a site directly for offline review.

4. Export Buffer with Syntax Highlighting to HTML

What it is:
The :TOhtml command produces a colorized HTML version of your current buffer—preserving syntax highlighting.

How to use:

  • In command mode, type:
    :TOhtml

Expansion:
Great for sharing code snippets with syntax colors, publishing example files, or archiving source with formatting for documentation. The created HTML file contains all visible formatting for accurate sharing.

5. Hex Edit with Native Commands

What it is:
Vim can work as a hex editor, letting you inspect and alter files byte by byte.

How to use:

  1. Open file in binary mode:
    vim -b filename
  2. Convert to hex for editing:
    :%!xxd
  3. Edit as needed.
  4. Revert back to binary:
    :%!xxd -r

Expansion:
Essential for programmers dealing with binary files, firmware, or debugging. Allows exact byte-level tweaks, troubleshooting, or corruption investigation—all in Vim.

6. Old EX Mode (Q)

What it is:
Capital Q enters Vim’s old EX mode—a line-based command interface predating modern visual modes.

How to use:

  • In normal mode, press Shift+Q.

Expansion:
While mostly obsolete, EX mode can batch-edit, delete lines, print ranges, and more. Exit EX mode by typing visual. Useful for Vim/VI historians or retro-computing, but rarely needed for daily editing.

7. Pipe Text Through Shell Commands (!)

What it is:
Send lines or selections to a shell command, and have the transformed output replace the original text.

How to use:

  • In visual mode, select lines.
  • Press :! (e.g., :!rev to reverse text).

Expansion:
Endlessly flexible—sort lines, filter, capitalize, run scripts—directly in your buffer. Workflows like pretty-printing JSON, spellchecking, or applying custom scripts become seamless.

8. Do Math Directly in Insert Mode (Ctrl-R =)

What it is:
Evaluate math expressions and insert the result while editing.

How to use:

  • Enter insert mode.
  • Press Ctrl-R =
  • Type an expression (e.g., 2+2).
  • Press Enter.

Expansion:
A time-saver for calculations mid-coding or note-taking. Handles arithmetic and basic functions—useful for quick totals or updating values in text/code.

9. Insert Output from Shell Commands (:r !)

What it is:
Read (“r”) the output from any shell command into your buffer.

How to use:

  • In normal mode, type e.g.
    :r !whoami
    :r !date

Expansion:
Auto-inserts current time, user, system info, or custom command output—ideal for journaling, logging, or dynamic documentation. Any shell command can be used for automation or record keeping.

10. Hidden Easter Egg: :help 42

What it is:
Typing :help 42 brings up a special help page referencing Douglas Adams’ “Hitchhiker’s Guide to the Galaxy” and the answer (42) to the ultimate question.

How to use:

  • In command mode, enter:
    :help 42

Expansion:
A fun demonstration of Vim developers’ sense of humor. There are more quirky help pages and hidden gems in Vim’s documentation, rewarding curious explorers.

Each of these tricks highlights the deep, versatile, and sometimes playful side of Vim. Try them directly and see which surprise you most—or work best in your own workflow[1].

[1] https://www.youtube.com/watch?v=ePzAP38NZ1I