惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
D
Docker
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
美团技术团队
V
V2EX
Last Week in AI
Last Week in AI
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Microsoft Security Blog
Microsoft Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
B
Blog RSS Feed
博客园_首页
B
Blog
博客园 - 叶小钗
I
InfoQ
WordPress大学
WordPress大学
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
The Register - Security
The Register - Security
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Latest news
Latest news
W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
News and Events Feed by Topic
S
Secure Thoughts
The Hacker News
The Hacker News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News

Yuexun J

Native macOS Updates in Tauri Why MCP Matters How to Make Your Tauri Dev Faster Developing an App with My AI Intern My Journey with Vim How the Notion Editor Works
The Vim Guide for VS Code Users
Yuexun Jiang · 2020-09-29 · via Yuexun J

Arrow keys are slow. You just don’t know it yet.

Most frontend developers use VS Code. Almost none use Vim. But Vim’s editing model is worth learning regardless of your editor. Once you internalize it, reaching for arrow keys feels like walking through mud.

You don’t have to switch editors. VS Code has excellent Vim support. What matters is the model — the way Vim thinks about text.

This guide starts from zero. By the end, you’ll have everything you need to start.

The Basics

Modes

Vim has four modes: Normal, Insert, Visual, and Command-line.

Other editors have one mode. You type, it appears. Simple.

Vim separates navigating from editing. You move in Normal mode. You type in Insert mode. You select in Visual mode. You run commands in Command-line mode.

This sounds complicated. It isn’t. You’ll switch between modes constantly, and it’ll become muscle memory.

The four modes

Normal Mode

When you open Vim, you’re in Normal mode. Your keyboard doesn’t type — it commands.

h/j/k/l move the cursor. Left, down, up, right.

Why not arrow keys? Because your fingers never leave the home row.

Commands take counts. Want to move down 10 lines? 10j. Delete 5 lines? 5dd. This is faster than holding down a key.

Moving Around

Here’s what you need:

  • h/j/k/l — left, down, up, right
  • ^ / $ — start / end of line
  • w / b — next word / previous word
  • f{char} / F{char} — jump to next/previous occurrence of a character

h and l are left and right. j goes down (your index finger’s home position). k goes up.

^ and $ work like regex anchors. Start of line, end of line.

w and b hop between words. 2w moves two words forward.

f{char} is powerful. Want to jump to the next =? Press f=. Done.

Moving with ^ $ w b

Moving with f{char}

Master these, and you’ll never reach for your mouse again.

Insert Mode

Insert mode is what other editors call “normal.” You type, characters appear.

To enter Insert mode from Normal mode:

  • i — insert before cursor
  • a — insert after cursor
  • o — insert new line below

Entering Insert mode

Variations

Uppercase versions do more:

  • I — insert at start of line (like ^i)
  • A — insert at end of line (like $a)
  • O — insert new line above (like ko)

To exit Insert mode: Esc or Ctrl+[.

The workflow: Normal mode to navigate, Insert mode to type, back to Normal mode. Like a painter picking up the brush, painting, putting it down to think.

This feels awkward at first. Then it becomes automatic. Then regular editors feel broken.

Visual Mode

How do you delete text in Vim?

You could enter Insert mode and use backspace. But that’s slow.

In Normal mode, x deletes a character. d deletes a range.

Common d commands:

  • dd — delete entire line
  • diw — delete current word
  • dt{char} — delete until character

But what if you want to select exactly what to delete?

Press v to enter Visual mode. Move with h/j/k/l/w/b/f. The selection follows. Press d to delete.

Selecting in Visual mode

V selects entire lines. Ctrl+v selects columns.

Cut, Copy, Paste

d is cut, not delete. The text goes to a register.

y is copy (yank). yy copies a line.

p is paste.

Select with v, copy with y, move somewhere, paste with p. Simple.

Text Objects

This is where Vim gets interesting.

diw means “delete inside word.” d is the command. iw is a text object.

Text objects let you operate on logical chunks without moving the cursor first:

  • iw — inside word
  • aw — around word (includes trailing space)
  • i( — inside parentheses
  • a( — around parentheses (includes the parens)

Replace ( with any paired character: i[, i{, i", i'.

yiw copies the word under your cursor. ci" changes everything inside quotes. da( deletes a function call’s arguments, parentheses included.

Copying a text object

This is Vim’s superpower. Learn text objects.

Command Mode

Press : in Normal mode to enter Command mode.

Essential commands:

  • :q! — quit without saving
  • :w — save
  • :wa — save all
  • :s/old/new/g — replace text

There are hundreds of commands. You’ll use maybe ten.

Key Mappings

Vim lets you remap anything.

In ~/.vimrc:

nnoremap <C-f> :s/

Now Ctrl+f starts a find-and-replace.

nnoremap means “normal mode, non-recursive mapping.” Use inoremap for Insert mode, vnoremap for Visual mode.

Non-recursive means the mapping won’t chain. If you map a to b and c to a, pressing c gives you a, not b. This prevents infinite loops.

The Leader key is Vim’s modifier. Default is ,. I use Space:

let g:mapleader = "\<Space>"

Then:

nnoremap <Leader>j 2j

Press Space, then j, to move down two lines.

This is why I love Vim. Total control over keybindings. No conflicts. No restrictions.

Macros

Macros record and replay actions.

Press qq to start recording into register q. Do something. Press q to stop.

Press @q to replay. 10@q replays ten times.

Example: add prefix and suffix to 10 lines.

Record once: I, type prefix, Esc, A, type suffix, Esc, j. Stop recording.

Then 9@q for the remaining lines.

Recording a macro

Replaying a macro

I use macros constantly for transforming JSON, converting enums, reformatting data.

Basic Configuration

Vanilla Vim is spartan. Add this to ~/.vimrc:

Line Numbers

set number
set relativenumber

number shows the current line. relativenumber shows relative distances — essential for commands like 10j.

Relative line numbers

Better Indentation

nnoremap < <<
nnoremap > >>

Now > and < indent without pressing twice.

set shiftwidth=2
set tabstop=2
set autoindent
set smarttab
set expandtab

Two-space indentation with spaces, not tabs.

Better Movement

noremap H ^
noremap L $
noremap J G
noremap K gg

Now H/L go to line start/end. J/K go to file start/end. Logical extensions of h/j/k/l.

Vim in VS Code

You don’t need to switch editors. VS Code has excellent Vim support.

Two options:

VSCodeVim

VSCodeVim emulates Vim in VS Code.

Configuration lives in settings.json:

{
  "vim.insertModeKeyBindings": [
    { "before": ["j", "j"], "after": ["<Esc>"] }
  ],
  "vim.normalModeKeyBindingsNonRecursive": [
    { "before": ["H"], "after": ["^"] },
    { "before": ["L"], "after": ["$"] }
  ]
}

It works. But you can’t reuse your .vimrc, and configuration is verbose.

Good for beginners who want to stay in VS Code.

vscode-neovim

vscode-neovim embeds actual Neovim into VS Code.

This is what I use. It reads your existing Vim config. It’s fast. You get real Vim, plus VS Code’s extensions.

The catch: you need Neovim 0.5+ installed. More setup, but worth it.

Wrap VS Code-incompatible plugins in your config:

if !exists('g:vscode')
  " Vim-only plugins here
endif

Keep Going

This guide covers the fundamentals. There’s much more: splits, buffers, registers, advanced motions.

Read Learn Vim the Smart Way or Practical Vim.

The learning curve is real. But once Vim clicks, you’ll wonder how you ever edited text any other way.

Start small. Use Vim mode in VS Code. Let muscle memory build. One day you’ll realize the arrow keys feel wrong.

That’s when you know it worked.

References