owned this note changed 7 years ago
Linked with GitHub

Vim 基本操作

在電光石火中我看不清你的身影

Vim Logo

Installation

Debian:

sudo add-apt-repository ppa:jonathonf/vim
sudo apt-get update
sudo apt-get install vim tmux zsh

Mac:

brew install vim tmux zsh

電光石火

How哥-紫禁之巔

Basic

  • Normal mode <ESC>
  • Insert mode i
  • Visual mode v
  • Command line :

exit: :q

Workflow

vim hello.sh

#!/bin/bash
echo OwO
# ...

:wq

chmod +x hello.sh && ./hello.sh or
bash hello.sh

Another Example

vim hello.py

#!/usr/bin/env python3
print('Hello from the other side')
# ...

:wq

chmod +x hello.py && ./hello.py or
python3 hello.py

Practice

複製一些文字來練習操作 vim

cat << EOF > article.txt
Microsoft released its latest Windows 10 October
2018 Update earlier this week, but some users are
reporting serious issues. Threads on Reddit,
Microsoft’s own support site, and other forums show
that some Windows 10 users are upgrading to the
October 2018 Update and having their documents,
photos, or even entire user profiles wiped out.
While some have discovered a temporary fix for the
issue, it’s not clear why exactly this is
happening.
EOF

reference

複製一些程式碼來練習

cat << MEOW > demo.py
#!/usr/bin/env python3
# vim: ts=4:sts=4:sw=4:expandtab
import calendar, argparse
from argparse import ArgumentParser

def main(year=2018, month=10):
    # display the calendar
    print(calendar.month(year, month))

if __name__ == '__main__':
    parser = ArgumentParser(description='display month',
            argument_default=argparse.SUPPRESS)
    parser.add_argument('--month',type=int,choices=list(range(1,13)))
    parser.add_argument('--year', type=int)
    args = parser.parse_args()
    main(**vars(args))
MEOW

modeline magic
pep8

Normal Mode

  • movement: h :arrow_left: , j :arrow_down: , k :arrow_up: , l :arrow_right:
  • move by word: w word, e end, b back
  • number: 3w, 4j
  • top: gg
  • bottom: G
  • back to last postion: ``
  • line begin: 0, ^
  • line end: $
  • copy (combined with others): y, y3w, yy
  • delete: x, d, dw, paste: p
  • undo: u, Crtl + r
  • substitute: s, change: c, cw
  • newline: o, O
  • insert: i, I, append: a, A

Advanced

  • 縮排: =
  • replace: r, R
  • gg=G, ggyG, ci', da"

Visual Mode

  • select: v, V, Ctrl + v
  • upper case: U, u
  • exit: <ESC>

Command

  • quit vim: :q
  • write: :w
  • split window: :sp, :vsp
  • substitute: :s/pattern/new_string/g
  • search: /pattern, :noh
  • paste: :pu, :pu!
  • select range: :2,3
  • select whole: :% = :1,$
  • external command: :!ls
  • help: :help help

Advanced

:wqa, :qa! (do sth. to all windows)
:version
:reg
:%s/old/new/g, :%!xxd, :%!xxd -r, :%s/\s*$//g | w | noh
prefix: Ctrl + w

.vimrc

config path: ~/.vimrc, ~/.vim/vimrc
my dotfiles
others
Vundle

Resource

cheat sheet
telegram


Tmux

config path: ~/.tmux.conf
tmux, tmux a
prefix: Ctrl + b
detach: <prefix> + d
<prefix> + c/x/%/"
command: <prefix> + :

zsh, oh-my-zsh

config path: ~/.zshrc
oh-my-zsh
powerline font

Hacktoberfest

github
hacktoberfest 2018

Git

fork first

git clone xxx
vi xxx
git add -A
git status
git commit -m "xxx"
git push
Select a repo