Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to replace from current line in Vim

📅 2014-Oct-31 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

The common command to search and replace text with confirmation in Vim is :%s/old/new/c. But, this begins the search and replace operation from the beginning of the file. There might be times when you want to begin search and replace from the current line.

The % in :%s/old/new/c is shortcut for 1,$, which means replace from first line to the last line. So, to search and replace from current line to end of file we can use .,$. This can be shortened to ,$.

So, the command to search and replace from current line is :,$s/old/new/c

Tried with: Vim 7.4 and Ubuntu 14.04