Vim - MIT Missing Semester

Philosophy of Vim

When programming, you spend most of your time reading/editing, not writing. For this reason, Vim is a modal editor: it has different modes for inserting text vs manipulating test.
Vim avoids the use of the mouse and using the arrow keys. The end result is an editor that can match the speed at which you think.

Modal editing

  • Normal<ESC> : for moving arounding a file and making edits
  • Insert i: for inserting text
  • ReplaceR: for replacing text
  • Visual (plainv, lineV, or block<C-v> ): for selecting blocks of text
  • Command-line:: for running a command

Basics

Inserting text

Buffers, tabs, and windows

[Vedio-Note]

Command-line

  • :q quit (close window)
  • :w save (“write”)
  • :wq save and quite
  • :e {name of file} open file for editing
  • :ls show open buffers
  • :help {topic} open help
    • :help :w opens help for the :w command
    • :help w opens help for the w movement

Vim’s interface is a programming language

Keystrokes (with mnemonic name) are commands, and these commands compose.

Movement

Movements in Vim are also called ‘nouns’, because they refer to chunks of text.
Normal modes:

  • Basic movement: hjkl (left, down, up, right)
  • Words: w (next word), b (beginning of word), e (end of word)
  • Lines: 0 (beginning of line), ^ (first non-blank character), $ (end of line)
  • Screen: H (top of screen), M (middle of screen), L (bottom of screen)
  • Scroll: Ctrl-u (up), Ctrl-d (down)
  • File: gg (beginning of file), G (end of file)
  • Line numbers: :{number}<CR> or {number}G` (line{number})
  • Misc: % (corresponding item)
  • Find: f{character}, t{character}, F{character}, T{character}
    • find/to forward/forward/backward {character} on the current line
    • ,/;for navigating matches
  • Search: /{regex}, n/N for navigating matches

Selection

Visual modes:
Can use movement keys to make selection.

Edits

Vim’s editing commands are also called “verbs”, because verbs act on nouns.
[vedio]

Counts

You can combine nouns and verbs with a count, which will perform a given action a number of times.

  • 3w move 3 words forward
  • 5j move 5 lines down
  • 7dw delete 7 words

Modifiers

You can use modifiers to change the meaning of a noun. Some modifiers are i, which means “inner” or “inside”, and a, which means “around”.

  • ci( change the contents inside the current pair of parentheses
  • da' delete a single-quoted string, including the surrounding single quotes

Demo

[Vedio]

Customizing Vim

Vim is customized through a plain-text configuration file in ~/.vimrc (containing Vimscript commands).
We recommend using a well-documented basic config because it fixes some of Vim’s quirky default behavior. Download our config here and save it to ~/.vimrc.
You can look at people’s dotfiles on GitHub for inspiration, for example, your instructors’ Vim configs (Anish, Jon (uses neovim), Jose). There are lots of good blog posts on this topic too. Try not to copy-and-paste people’s full configuration, but read it, understand it, and take what you need.

Extending Vim

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值