MIT-Missing-Semester3: Editors (Vim)

A. Lecture Node: Editors (Vim)

Vim的设计理念

模式化编程:

  • 有5个模式:normal, insert, command, replace, visual
    • Normal: for moving around a file and making edits
    • Insert: for inserting text(用i)
    • Replace: for replacing text(用R)
    • Visual (plain, line, or block): for selecting blocks of text(用v)
    • Command-line: for running a command(用:)
  • 切换模式用

Vim Basics

  • insert

按i进入insert模式,编辑完成后,按ESC退出

  • buffer, tab, window

A Vim session has a number of tabs, each of which has a number of windows.

  • command line

常用命令::q :wq :e :ls

Vim as a Programming Language

  • Movement
    • 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} or {number}G (line {number})
    • Misc: % (corresponding item)
    • Find: f{character}, t{character}, F{character}, T{character}
      • find/to forward/backward {character} on the current line
      • , / ; for navigating matches
    • Search: /{regex}, n / N for navigating matches

(^u,Ctrl+u,代表同一个意思 )

  • Selection

可以用movement keys to make a selection,可以选择line或者block.

  • Edits

    • i enter Insert mode
    • o / O insert line below / above
    • d{motion} delete {motion}
      • e.g. dw is delete word, d$ is delete to end of line, d0 is delete to beginning of line
    • c{motion} change {motion}
      • e.g. cw is change word
    • s substitute character (equal to xi)
    • Visual mode + manipulation
      • select text, d to delete it or c to change it
    • u to undo, to redo
    • y to copy / “yank” (some other commands like d also copy)
    • p to paste
  • Counts

用数字+symbol的方式可以重复操作同一命令多次

3w: move 3 words forward

5j: go 5 lines down

7dw: delete 7 words forward

B. Exercises

1、

猜测是安装vim(树莓派已安装了)。

2、

树莓派的vimrc在:/etc/vim/vimrc。

先备份本地的vimrc:

sudo cp /etc/vim/vimrc /etc/vim/vimrc.backup

下载网页提供的vimrc文件替换/etc/vim/vimrc即可。

sudo vim /etc/vim/vimrc

然后粘贴后保存。

3、

改变CTLRP启动默认映射和默认的命令,在/etc/vim/vimrc最后追加

let g:ctrlp_map = ''
let g:ctrlp_cmd = 'CtrlP'

4、

from __future__ import print_function
import sys

def fizz_buzz(limit):
    for i in range(limit):
        if i % 3 == 0:
            print('fizz', end="")
        if i % 5 == 0:
            print('buzz', end="")
        if  i % 3 and i % 5:
            print(i)

def main():
    fizz_buzz(int(sys.argv[1]))

if __name__ == '__main__':
    main()

补充:分页功能:

法1、tmux分页。

法2、同一个vim会话,执行:sp或者:vsp。

演示的应该是tmux。tmux用于管理多个终端,vim分页用于打开多个文档。
MIT-Missing-Semester3: Editors (Vim)_第1张图片

参考:
1、MIT-Missing-Semester。
2、xiaofanwudi。

你可能感兴趣的:(Linux,vim,编辑器,linux)