Thursday 15 August 2013

[VIM] Insert the content of a file into current opened file


read a file and insert it into the position below the cursor of the current file

:read /path/to/file
:re /path/to/file
:r /path/to/file
  • insert into the beginning of the file
:0r /path/to/file
  • insert into the end of the file
:$r /path/to/file

read the output of system command and insert into the position below the cursor of the current file

  • read in the file list by ls command
      :r !ls
    
      :r !ls ~
  • read in the dir tree by tree command
      :r !tree

read a specific lines from a file and insert it into the position below the cursor of the current file

  • read the line no.10 to 20 into current file
:r !sed -n 10,20p /path/to/file

No comments :

Post a Comment