
Vim Editor Tips and Tricks
The best place to find information on VIM is to simple type :help in the editor, which is where I found most of these commands.
VIM Cheatsheet
| Command | Description |
|---|---|
| File Navigation & Information | |
| :%s/word/&/g | Can be used to count occurrences of a word in a file. This works by searching for "word" and replacing it with "&" which is the exact same text that was searched for. |
| g<CTRL+g> | Shows useful information including line, word, and byte position in the file, as well as the total number of lines, words, and bytes in the file. |
| :%!xxd | Shows the hex code for the currently open file. |
| Editing | |
| :%s/\s\+$// | Trims whitespace characters (tabs and spaces) from the end of each line in the file. |
| :%s/^M$//g | Removes all occurrences of ^M from the file. It's important when typing this command in the editor to not simply type ^ and M, but rather type [linux] <CTRL+v><CTRL+m> or [windows] <CTRL+q><CTRL+m>. |
| :%s/,/^M/g | Replaces all occurrences of a string or character with a newline ( a , with a new line in this example). The comma can be any character or string (like tab or space). It's important when typing this command in the editor to not simply type ^ and M, but rather type [linux] <CTRL+v><CTRL+m> or [windows] <CTRL+q><CTRL+m>. |