Pages

Wednesday 15 May 2013

Vi Tip: Search and Replace

 Search and Replace Text in Specific Range

There are times when you would like to change text within a specific range:
First show the line numbers using;

:set nu

Then do the search and replace task like so:

:start_line,end_lines/text_to_be_searched_for_and_replaced/replacing_text/g

Example:


100 
101     def _set_attr(j_patient):
102         self.id = j_patient.pop("patient.id", None)
103         self.voided = j_patient.pop("patient.voided", False)
104         self.created_by = j_patient.pop("patient.created_by", None)
105         self.created_on = j_patient.pop("patient.created_on", None)
106         self.modified_by = j_patient.pop("patient.modified_by", None)
107         self.modified_on = j_patient.pop("patient.modified_on", None)
108 
109     def _set_patient(self, patient):
110         patient.id = self.id
111         patient.voided = self.voided
112         patient.created_by = self.created_by
113         patient.created_on = self.created_on
114         patient.modified_by = self.modified_by
115         patient.modified_on = self.modified_on
116     


So, to change the word patient to person only under the _set_patient function, do this:

:109,115s/patient/person/g