Delete and insert I often find myself wanting to replace text. With a GUI-based editor, I would highlight the text with my mouse and start typing. Vim has some handy commands for accomplishing the same without having to move your hands from the keyboard:
r - replace the character under the cursor R - like r, but moves the cursor forward so that you can replace several characters in a row I like using "R" when I am replacing text that has a fixed width (like a date) since, unlike other delete and insert commands, it does not move the text to the right of the cursor, which makes it easier to spot input errors, like typing "209" or "20009" when I mean "2009". The "c" command is pretty nifty since it can be combined with motions. I use "cw" to replace words all the time. Sometimes I want to replace a word scattered throughout a document but this string matches things that I don't want to replace, and crafting a regex that would do the right thing would be complicated. I start by searching for the string with "/word" and it moves the cursor to the first character of the first word it finds that matches. If this is a word that I want to replace, I type "cw" and then the new word. Now I can repeat the replace with "." so I continue the search by pressing "n" until I find the next word I want to replace, and then press ".". Repeat until I reach the end of the document. Useful actions: cw - replace a word cE - replace text up to next whitespace C - replace from cursor to end of line cap - replace "A Paragraph" cG - replace all lines from the cursor to the end of the file c1G - replace all lines from the cursor to the beginning of the file Other useful delete and insert (a.k.a. replace) commands: ~ - change the case of letter under the cursor and move the cursor forward CTRL-A - add one to the number under the cursor (of course vim can handle multi-digit numbers!) CTRL-X - subtract one from the number under the cursor Bonus command: When in insert mode, CTRL-Y will copy the character immediately above the cursor. Very handy if you are entering formatted text that has common strings. Chris P.S. I would appreciate some feedback; is anyone reading my tips? Should I continue? I hope so, because I am not sure if I have a week's worth, so this may force me to learn more vim! _______________________________________________ mlug mailing list [email protected] https://listes.koumbit.net/cgi-bin/mailman/listinfo/mlug-listserv.mlug.ca
