Vim cheatsheet - Part I

Posted on Wed 18 May 2016 in vim

  • Read command output to current line

    :read ! command 

  • Open file under cursor

    ESC + gf

  • Create heading 1 in markdown

    :map h1 yypVr=o

  • Create heading 2 in markdown

    :map h2 yypVr-o

  • Replace content from current file to end of file

    :.,$s/pattern1/pattern2/gc

  • Change certain number of lines from current line

    :.,.+s/pattern1/pattern2/gc

    Usage : :.,.+4s/foo/bar/gc # this is will replace foo to bar from current line to next 4 lines.

  • Creating mark

    ESC + m + key_name 

  • Return to mark

    ESC + ' + key_name 

  • Deleting everything from paraenthese or ()

    ESC + di( 

  • Using temporary buffers

    ESC + "a4yy 
    ESC + "ap 

  • Using F5 to automatically remove all trailing spaces in code

    nnoremap <F5> :let _s=@/<Bar>:%s/\s+$//e<Bar>:let @/=_s<Bar><CR>

  • Go to specific character on current line. If you want to go to first occurance of '=' then

    ESCf + = 

  • Delete from current line till specified line number

    ESC:.,d