Almost all are not able to remember all the shortcuts that are available for the vi or vim editor. I will call it vim throughout this article. There are several cheatsheets out there, but the one that works for me is the one provided by rtorr in Github. I use the cheatsheet often. I suggest that you start small. At the very least learn how to navigate in vim. Once you feel comfortable doing that, you can learn other advanced shortcuts such as editing, search and replace, working with multiple files and many much more. I hope you’ll find the cheatsheet as helpful as it has done for me. Again if you missed the link above, I posted it below.
vim
Vim Colors
I had trouble getting my vi editor to display all black background color. This includes the background color after the end of the file. I just wanted an all black background for better visibility. I did a little bit of googling and found this nice little gem. I happen to like the dessert theme and went with that instead of the recommended mustang theme which I don’t have installed. Hope you’ll find this helpful.
set t_Co=256 set background=dark colorscheme dessert highlight Normal ctermbg=NONE highlight nonText ctermbg=NONE |
Set Vim Colors Permanently
Here’s how to set Vim colors permanently.
vi ~/.vimrc |
Add the following.
highlight Normal ctermfg=white ctermbg=black |
Vi Search and Replace
How to do search and replace in Vim.
Search for “foo” and replace it with “bar” in the current line. Use :s
:s/foo/bar/g |
Search for “foo” and replace it with “bar” in the entire document. Use :%s
:%s/foo/bar/g |
You can also pipe instead of forward slash. Useful if your search contains a /.
:%s|foo/|bar|g |
GCP Cloud Shell Vim Settings
I had an issue with using the backspace in Vim in GCP’s Cloud Shell. Every time I’m in the insert mode and I want to edit using backspace, it doesn’t delete the characters. It shows these characters “^?” instead. Well, it turned out to be a backspace setting that you can set within .vimrc. So, here’s my working setup.
colo desert syntax on set backspace=indent,eol,start set nocompatible |
- The first line uses the desert theme.
- The second line turns on syntax highlighting. It’s on by default.
- The third line fixes the backspace issue I mentioned above.