Posts Tagged ‘vi’

How to insert the output of a command in VI

Friday, February 27th, 2009

To insert the output of a command (e.g. ‘ls’) below the cursor, type: :r !ls or :read !ls


How to insert the contents of a file in VI

Friday, February 27th, 2009

To insert the contents of a file called /tmp/myfile.txt below the cursor, type: :r /tmp/myfile.txt or :read /tmp/myfile.txt


Search and replace with VI

Wednesday, February 25th, 2009

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 [...]


How to change VIM’s working directory

Wednesday, February 25th, 2009

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