How to insert the output of a command in VI
Friday, February 27th, 2009To insert the output of a command (e.g. ‘ls’) below the cursor, type: :r !ls or :read !ls
To insert the output of a command (e.g. ‘ls’) below the cursor, type: :r !ls or :read !ls
To insert the contents of a file called /tmp/myfile.txt below the cursor, type: :r /tmp/myfile.txt or :read /tmp/myfile.txt
To search and replace in VI, you have to use the “substitute” command, which looks like this: [range]s/[search_string]/[replacement_string]/[options] Examples To search and replace all occurrences of OLD with NEW, type: :%s/OLD/NEW/g To search and replace all occurrences of OLD with NEW and ask for confirmation with each substitution, type: :%s/OLD/NEW/gc To search and replace all [...]
To change VIM’s current working directory, type: :cd NEW_DIRECTORY To display the current working directory, type: :pwd To change the working directory to that of the file that is open at the moment, type: :cd %:h