Thursday, October 14, 2010

My favrite Vim commands

  • search - /
  • ignore case search - /\c
  • search for pattern
 /word1\(.*word2\)\@=
/.*Word1.*word2  
  • replace :   %s/word1/replaceword/gc 
  • to append at end of line  :   %s/$/word/gc
  • to append at begin of line  :  %s/^/word/gc
  • to append newline character at end of line  :  %s/$/\r/gc
  • to remove new line character  :  %s/\r//gc
  • to enable Hex editing :%!xxd
  • to go back in binary mode :%!xxd -r
  • To remove all lines not having getDisplayName

  1. replace othr lines with blank
    :%s#^\(.*getDisplayName.*\)\@!.*$##gc

    2.  remove blank lines 
        :v/\S/d
        3.  to remove all lines having getDisplayName

                  just remove @! FROM SEARCH QUERY

      • :vsp      " Vertically split the window

      • " Changing Case use with
      •  lowercase line guu
      •  uppercase line gUU
      •  lowercase line Vu
      •  uppercase line VU
      •  flip case line g~~
      •  Upper Case Word vEU
      •  Flip Case Word vE~
      •  lowercase entire file ggguG
      • buffer commands
      :bn (next buffer),
      :bp (previous buffer)
      :buffers (list open buffers)
      :b (open buffer n)
      :bd (delete buffer).
      :e will just open into a new buffer
      • Grep Command
        • :vim[grep][!] /{pattern}/[g][j] {file} ... 
        • :lvim /\<\(house\|home\)\>/gj *.txt 
        • :lw list selected buffers in grep

      No comments: