$30 off During Our Annual Pro Sale. View Details »

Vim Registers - Simple tutorial

Vim Registers - Simple tutorial

A guide explaining how to use vim editor registers.

More Decks by Weverton do Couto Timoteo

Other Decks in Programming

Transcript

  1. Vim Registers
    How to use vim registers, a :h registers tutorial

    View Slide

  2. List of Registers
    • 1. The unnamed register ""
    • 2. 10 numbered registers "0 to "9
    • 3. The small delete register "-
    • 4. 26 named registers "a to "z or "A to "Z
    • 5. four read-only registers ":, ". and "%
    • 6. the expression register "=
    • 7. The selection and drop registers "*, "+ and "~
    • 8. The black hole register "_
    • 9. Last search pattern register "/

    View Slide

  3. 1. Unnamed register
    Any D, C, S, X and Y:
    Will fill "" register. Except the _ register.
    The "" is used in p, P or :put commands.
    Example:
    Try yank a line, delete with "_dd and paste it.
    The yanked line will be pasted :)

    View Slide

  4. 2. Numbered registers
    Yank register (0) stores your recent yanked line.
    Check your registers:
    :reg "0
    Paste last yanked line:
    "0p
    Paste deleted line:
    p

    View Slide

  5. 3. Small delete register
    Read-only register
    Referenced by "-
    Stores any text that you deleted or changed that
    was less than one line in length
    Example:
    Delete something and check :reg "-

    View Slide

  6. 4. Named registers
    See full list of your registers:
    :reg
    Note a quote (") in start of line
    How to yank to a register?
    and !
    "ayy OR :yank a
    Append to named register:
    "Ayy OR :yank A
    Cleaning a named register:
    qaq
    Copying a pattern to register:
    :global/Lorem/yank A
    See more: :h quote_alpha

    View Slide

  7. 5. Read-only registers
    ":, ". and "%
    ": Contains the most recent executed cmd line
    ". Contains the last inserted text
    "% Contains the name of current file
    !
    "# Contains alternate file (can't reproduce)

    View Slide

  8. 6. Expression register
    In --INSERT-- mode:
    =(your-expression)
    Or in normal mode:
    :put =(your-expression)
    List of functions: :h function-list
    Examples:
    2+2
    4*4
    sqrt(4)

    View Slide

  9. 7. Selection registers
    "*, "+ and "~
    Selects and drops text into the clipboard
    Copy to system clipboard:
    "+y OR "*y
    Paste from system clipboard:
    "+p OR "*p OR :set paste, then p
    "~ Stores the dropped text from last drag'n'drop

    View Slide

  10. 8. Blackhole register
    Check your registers:
    :reg "
    Delete without write in default register:
    "_dd
    Check again:
    :reg "

    View Slide

  11. 9. Last search pattern
    register "/
    Contains the most recent search-pattern
    Used for "n" and 'hlsearch'
    You can't yank or delete into this register
    !

    View Slide

  12. Thank you!
    @wevtimoteo
    !
    References:
    http://vimcasts.org/results/#stq=registers
    http://www.vim.org/docs.php
    http://vim.wikia.com

    View Slide