AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
![]() ![]() What about //? Won't vi get confused since substitution uses / to separate the old value from the new value? This is where we need to use \ (backslash) to escape the double back slashes that represent commenting. So s/^/dog/ would add the word dog to the beginning of each line. ![]() Well "nothing" is really the beginning of each line which is represented with ^ (the caret character). We are trying to substitute nothing with //. Now you may have noticed a little problem. S/cat/dog/ takes the first occurrence of the word cat and replaces it with the word dog. The next two arguments are separated by /, the first being the location or old value and the second being the new value. ![]() Substitution with regular expressions is a powerful tool in vi.ġ1,17 is the range you are interested in. It takes time to even get to this point of sufficiency, but there are better ways. Hit xx to remove the first two characters of the line (in our case the // chars), hit h to navigate up to the next row, and then repeat until all rows are uncommented.īeing able to navigate around and insert and remove characters like this is definitely not something to be scoffed at. Navigate your cursor the beginning of the last row you want to comment. To uncomment the rows, you do almost the same thing. You hit i to go into insert mode, enter // to comment, hit ESC to go back to command mode, hit j to navigate down to the next row, and then repeat until all the rows are commented out. You start your editor, navigate down to the beginning row of the block you want to comment out. It may be a little unfair to call this the "bad" way, but it's certainly the most inefficient. Have you ever found yourself in vi wanting to comment and uncomment blocks of code? Here are 3 ways to accomplish this. This is where things get real fun and adding more commands to your vi toolbox will make you even more productive. There will come a point where you will be comfortable navigating around using the h j k and l keys and going between command mode and insert mode will be second nature. The learning curve is a bit high and there are many ways to do many things in this simple yet powerful editor. Learning vi for the first time can be really intimidating. ![]()
0 Comments
Read More
Leave a Reply. |