• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
jacklee404
Never Stop!
博客园    首页    新随笔    联系   管理    订阅  订阅
Hw03-Vim Editor

Hw03-Vim Editor

1. Complete vimtutor

lee@ubuntu:~/class/Missing-Semester/class-3$ vimtutor

image-20220625173939187

Vimtutor is a simple tutorial for the beginner to learn how to use the editor with the most easy way. After I've been read about it, it pointed that vim need to learn in a long way.

2.Setting the basic vimrc

First download the file to the directory of you user.

lee@ubuntu:~$curl https://missing.csail.mit.edu/2020/files/vimrc > .vimrc

image-20220625175858782

There is something by default as the vim started.

3. Install and configure a plugin ctrlp.vim

Install with the following commands and use it.

lee@ubuntu:~$ mkdir -p ~/.vim/pack/bencor/start
lee@ubuntu:~$ cd ~/.vim/pack/vendor/start
lee@ubuntu:~$ git clone https://github.com/ctrlpvim/ctrlp.vim

image-20220625181327805

Customize the plugin by editing .vimrc file by studying the [document](ctrlp.vim/readme.md at master · ctrlpvim/ctrlp.vim (github.com)).

image-20220625181855898

4. Redo demo in the class

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

def main():
    fizz_buzz(10)

We will fix the following issues:

  • Main is never called
  • Starts at 0 instead of 1
  • Prints “fizz” and “buzz” on separate lines for multiples of 15
  • Prints “fizz” for multiples of 5
  • Uses a hard-coded argument of 10 instead of taking a command-line argument

image-20220625182405158

5. Macro

​ Convert XML to JSON (example file) using Vim macros. Try to do this on your own, but you can look at the macros section above if you get stuck.

  1. GG dd and gg dd the first and the last line

  2. press q and a to start recording macro

  3. V select the line number 1 and r{ to replace to {

  4. Jump to the line and wd<$d<0 press "name" and somthing

  5. Jump to the line do things like 3

  6. do things like 2

  7. jump to the next line

  8. Stop recording to press q

  9. 999@a

posted on 2022-06-25 18:55  Jack404  阅读(18)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3