Skip to content

Instantly share code, notes, and snippets.

@eellpp
Created August 8, 2016 00:19
Show Gist options
  • Select an option

  • Save eellpp/43f109260ea203b59bb6acaae738b99c to your computer and use it in GitHub Desktop.

Select an option

Save eellpp/43f109260ea203b59bb6acaae738b99c to your computer and use it in GitHub Desktop.

Revisions

  1. eellpp created this gist Aug 8, 2016.
    78 changes: 78 additions & 0 deletions vim Scratchpad
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,78 @@
    vim Help
    - help
    - help <String>Tab
    - help grep
    cnext, cprev, cfile

    vimgrep pattern files

    Repeat a character n times without typing
    <C-o>80i-<Esc>

    Custom maps
    Buffer
    nmap H :bn<CR>
    nmap L :ls<CR>
    nmap HB :bn
    nmap HD :bdel

    w: moves across word seperator; b will move backwards
    W: will move to the next empty space

    :h normal-index # all the commands in the normal mode
    # check out the watchdog plugin that adds useful information the command line below

    0: move to the start of the line
    ^: move the start of the first word in the line
    $: move to the end of current line
    -: move to the beginning of the last line
    <CR>: move to the start of the next line
    <Number>% : move to n% of the file
    # do calculations with bc. Replace the current line
    !!bc
    # with 2 decimal places 41.57
    # pretty json
    !python -m json.tool

    #Find the various mappings of the command
    : help index
    |CTRL-B| CTRL-B 1 scroll N screens Backwards
    |CTRL-F| CTRL-F 1 scroll N screens Forward
    |CTRL-E| CTRL-E scroll N lines upwards (N lines Extra)
    |CTRL-U| CTRL-U scroll N lines Upwards (default: half a
    |CTRL-Y| CTRL-Y scroll N lines downwards

    Regex
    Except . and * almost all metcharacters require an escape
    prefix the regex with \v and all the metachars are magic chars with special meaning and need not be escaped.
    nnoremap / /\v

    vim regex word boundary are \< and \>
    * and # : next and previous match of the current char

    yankmatches.vim

    Search Replace
    # relative and absolute range selection
    .,+33s/dfg/df
    # pattern based range selection
    \<TAG\>,\<\/TAG\>s/sdf/dff

    Global Command : apply the command on a pattern
    :g /PATTERN/ <Any Colon command>
    :g /PATTERN/ :normal <Any Normal command>

    copy
    y/<>

    Copy text objects
    yaw (when in middle of a word, copy the full word)
    yaW
    yas (sentence)
    yap (paragrap)
    Yank between delimiters (delimited objects)
    ya{
    ya[
    ya'

    sort and join