Monday, October 6, 2014

VI commands

  • vi test.txt     > create the file using the vi command
  • :q!                > quit the VI editor without save
  • :wq!             > save and quit the VI editor
  • shift + g (G) > Move  the cursor to the end of the file
  • g                  > Move cursor to the first line of the file
  • i                   >The characters typed in will be inserted before the current cursor position
  • I                   >The characters typed in will be inserted in first of the current line
  • Shift + A     >The characters typed in will be inserted in end of the current line
  • x                  > Delete the  character under the cursor
  • {number}x  > Delete the character under the cursor and next n number right characters
  • X                 >Delete the  character before the cursor
  • {number}X > Delete the n number characters before the cursor position (Not the cursor)
  • u                  >Undo the last change to the file. Typing u again will re-do the change. 
  • dd                > Delete the current line 
  • {number}dd > Remove the n number of lines down wards include current line
  • d{number}k > Delete the n  number of above lines including current line
  • d{number}j  > Delete the n number of down lines including current line
  • :3,18d        >delete lines 3 through 18
  • :1,$d              > Delete the all lines in file
  • :n  + Enter    > Go to nth line in a file Ex; :10 + ENTER
  • h                    >Move the cursor to the left one character position. 
  • j                     >Move the cursor down one line. 
  • k                    >Move the cursor up one line. 
  • l                     >Move the cursor to the right one character position. 
  • d^                  >Deletes from current cursor position to the beginning of the line. 
  • d$                  >Deletes from current cursor position to the end of the line. 
  • dw                  >Deletes from current cursor position to the end of the word. 
  • db                  > Deletes from current cursor position to the starting of the word
  • :1,$s/up/right/ > To Replace string Ex:1,$s/test1/test2
  • 16,25m30  > Move lines 16 through 25 to after line 30
  • 23,29co62 > Copy specified lines and place after line 62

No comments:

Post a Comment