Home / Notes / vi & vim Notes
========================

 1. CVS commit the current file:

    :!cvs commit -m '[commit message]' %

 2. Execute a command and read its input into the current
    buffer:

    :r![command]

 3. Hard wrap text to 80 columns:

    a. Set the text width to 80 columns:

       :set textwidth=80

       or

       :set tw=80

    b. To format the entire file, go to the start of the file (:gg),
       and then:

       :gqG

       To format the current line only:

       :gq$

       To format the current paragraph only:

       :gq}

    c. Alternatively, use :%!fold -w [col]

    Sources: http://mark.stosberg.com/Tech/text_editor_review.html#vim
             https://stackoverflow.com/questions/3033423/
             https://vim.works/2019/03/16/wrapping-text-in-vim/

 4. Split a window and edit two files

    a. :sp or <CTRL>ws (horizontal split, new window on the top
       :vs or <CTRL>vw (vertical split, new window is on the left)

    b. <CTRL>ww (move to new window)

    c. :edit [file]

    To resize a split: <CTRL>w+ (increase size)
                       <CTRL>w- (decrease size)

    To close a split: :only or :q or <CTRL>wo

    Sources: https://vim.works/2019/03/03/split-windows-in-vim/
             https://vi.stackexchange.com/questions/64/

 5. Spell checking the current file:

    :!aspell -c %

 6. Enable a custom dictionary for additional words for spelling mode:

    $ mkdir -p ~/.vim/spell
    $ touch ~/.vim/spell/en.utf-8.add

    From: https://codeyarns.com/tech/2015-09-30-how-to-make-spellfile-in-vim.html

 7. Spelling mode shortcuts:

    ]s      move to the next misspelled word
    [s      move to the previous misspelled word
    z=      list suggested spellings for a misspelled word
    zw      add selected word to the custom dictionary

    From: https://www.ncartron.org/vim-spellcheck-cheat-sheet.html

 8. Yank multiple lines

    [num lines]Y
    [num lines]yy

    For example, '3yy' would yank the current line and the next two lines.

    From: https://vi.stackexchange.com/questions/27148
          https://superuser.com/questions/234317

 9. Copy or cut the next word:

    yiw     Copy / yank next word
    ciw     Cut

   From:  https://stackoverflow.com/questions/7797068/

10. Delete all text to the end of the file:

    dG                  From current line
    :[line number],$d   From a particular line

11. Replace all occurrences of 'old' with 'new':

    :%s/old/new/g

12. Execute a script being edited without quitting vim:

    :!%

    From: https://www.tumfatig.net/2024/execute-current-edited-script-in-vim/

12. Navigation:

    0            move to the first column of the current line
    ^            move to the first non-space/tab character of the current line
    $            move to the last character of the current line
    w            move to the next word, exclusive of punctuation
    W            move to the next word, inclusive of punctuation
    b            move back one word, exclusive of punctuation
    B            move back one word, inclusive of punctuation
    e            move to the end of the current word, exclusive of punctuation
    E            move to the end of the current word, inclusive of punctuation
    H            move to the top of the current screen
    M            move to the middle of the current screen
    L            move to the bottom of the current screen
    1G (or gg)   move to the first line of the document
    G            move to the last line of the document
    CTRL-F       move forward one screen
    CTRL-B       move back one screen

    From: https://vermaden.wordpress.com/2024/09/23/ghost-in-the-shell-part-8-use-vi-editor/
          https://m4xshen.dev/posts/vim-basic-commands
          https://www.thegeekdiary.com/basic-vi-commands-cheat-sheet/
          https://www.ungerhu.com/jxh/vi.html
          https://wiki.arahant.com/Wiki.jsp?page=Vi
          https://levelup.gitconnected.com/vim-is-not-about-speed-88968ae4283c?gi=2317b00898a3