vim useful commands

vim have many commands, here are some useful:

  • change to insert mode
    • before the current cursor position:
      i
    • after the current cursor position:
      a
    • beginning of the current line
      I
      capital I = (shift +i)
  • deleting current line:
    dd
    pressing twice on the letter d
  • go the last line
    G
    capital G = (shift + g)
  • go to the first line
    gg
    pressing twice on the letter g
  • move to matching parentheses
    %
  • saving changes to file without write permission.
    If you have started to edit a file with out write permission in vim, and you want to save your change you can use the following command (this is very useful when you forgot to use sudo):
    :w !sudo tee %
  • restoring the editor content to previous time
    :earlier <numOfMinutes>m
    for example if we want to go back 15 minutes, we will run:

    :earlier 15m
  • change vim to work as hex editor:
    :%!xxd
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s