HackMD
  • New!
    New!  Markdown linter lands.
    Write with consistency! Enable markdown linter that hints better markdown styling you can take. Click the lightbulb on the editor status bar 💡
    Got it
      • Create new note
      • Create a note from template
    • New!  Markdown linter lands.
      New!  Markdown linter lands.
      Write with consistency! Enable markdown linter that hints better markdown styling you can take. Click the lightbulb on the editor status bar 💡
      Got it
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Save as template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
      • ODF (Beta)
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • More (Comment, Invitee)
      • Publishing
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
    Menu Sharing Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Gist
    Import
    Dropbox Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML ODF (Beta)
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Note Permission
    Read
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    Write
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    More (Comment, Invitee)
    Publishing
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like BookmarkBookmarked
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Vim 基本操作 在電光石火中我看不清你的身影 ![Vim Logo](https://upload.wikimedia.org/wikipedia/commons/9/9f/Vimlogo.svg =300x) ## Installation Debian: ```shell sudo add-apt-repository ppa:jonathonf/vim sudo apt-get update sudo apt-get install vim tmux zsh ``` Mac: ```shell brew install vim tmux zsh ``` ## 電光石火 [![How哥-紫禁之巔](https://img.youtube.com/vi/kyfoEjAxgEw/0.jpg)](https://www.youtube.com/watch?v=kyfoEjAxgEw) ## Basic - Normal mode `<ESC>` - Insert mode `i` - Visual mode `v` - Command line `:` exit: `:q` ## Workflow `vim hello.sh` ```sh #!/bin/bash echo OwO # ... ``` `:wq` `chmod +x hello.sh && ./hello.sh` or `bash hello.sh` ### Another Example `vim hello.py` ```python #!/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](https://www.theverge.com/2018/10/5/17940902/microsoft-windows-10-october-2018-update-deleting-documents-issues) 複製一些程式碼來練習 ```shell 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](http://vim.wikia.com/wiki/Modeline_magic) [pep8](https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces) ## 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](https://github.com/doraeric/dotfiles) [others](https://github.com/search?q=dotfiles) [Vundle](https://github.com/VundleVim/Vundle.vim) ## Resource [cheat sheet](https://vim.rtorr.com/) [telegram](https://t.me/vim_tw) --- # 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](https://github.com/robbyrussell/oh-my-zsh) [powerline font](https://github.com/powerline/fonts) # Hacktoberfest [github](https://github.com) [hacktoberfest 2018](https://hacktoberfest.digitalocean.com/) ## Git fork first ``` git clone xxx vi xxx git add -A git status git commit -m "xxx" git push ```

    Import from clipboard

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.
    All
    • All
    • Team
    No template found.

    Create a template

    Delete template

    Do you really want to delete this template?

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in via Google

    New to HackMD? Sign up

    Help

    Documents

    Tutorials
    YAML Metadata
    Slide Example
    Book Example

    Contacts

    Talk to us
    Report an issue
    Send us email

    Cheatsheet

    Example Syntax
    Header # Header
    • Unordered List
    - Unordered List
    1. Ordered List
    1. Ordered List
    • Todo List
    - [ ] Todo List
    Blockquote
    > Blockquote
    Bold font **Bold font**
    Italics font *Italics font*
    Strikethrough ~~Strikethrough~~
    19th 19^th^
    H2O H~2~O
    Inserted text ++Inserted text++
    Marked text ==Marked text==
    Link [link text](https:// "title")
    Image ![image alt](https:// "title")
    Code `Code`
    var i = 0;
    ```javascript
    var i = 0;
    ```
    :smile: :smile:
    Externals {%youtube youtube_id %}
    LaTeX $L^aT_eX$

    This is a alert area.

    :::info
    This is a alert area.
    :::

    Versions

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub

        Please sign in to GitHub and install the HackMD app on your GitHub repo. Learn more

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully