OK, it does seem like such a deep product but there always seem like a few new things to learn with vi. Here are some really useful ones. The g and z commands arrived because they were relatively unused. So here’s a quick list of useful ones
- zz. I’ve always know that with H or M or L, you get to the top, middle or bottom of the screen, but how can you redraw so your cursor is in the center of the screen, turns
- zb. Or redraw with the current line at the bottom of the screen
- zt. Redraw with the current line at the top
- z<CR>. This puts the cursor at the top of the windo
- z+
But the big use of z is for folding which kind of makes sense, ‘z’ is kind of a folding character and this only works if you have folds for say a YAML or a program.
- zA. Alternate the fold so, Open a closed fold or vice versa
- zc. close a fold
- zC. Close a fold
- zd. Detete a fold
- zD. Delete all the folds
- zF create a fold for N lines
- zM set folder level to the minimum or zero
- zm subtract one from fold level
- zo open a single fold
- zO open all folds
Finally z is used for spelling in adjunct the ]s and [s which moves to next and previous spelling
- zg – Add the current word to the dictionary
- zG – temporarily mark a word as correct
- zw – Ignore the current word it is wrong but don’t spell check
- zW – temporarily make a wrong word
The g commands are also kind of a hodgepodge of things that are roughly going somewhere and there are lot of good ones that I didn’t know about, but g is mainly for “going somewhere”
- * – the asterisk by itself means search forward for the word under the cursor
- # – the number sign means search backwards fro the word under the cursor
- g* – find matches forward for matches that are not a whole word
- g# – find matches backward for partial matches and not just whole words
- gd – go to the definition of a variable that is under the cursor searching down
- gD – go to definition starting from the the first line of the file
- gf – open the file whose name is under the cursor
- gx – open the url under the cursor
- gm – goto the character in the middle of the screen
- gM – go the middle of the text line
- go – Go the Nth byte in the file so 140go means go to character 140
Then there are commands that print values of characters:
- g8 – print the octal value of the character under the cursor
Then there are command I use a bunch for formatting:
- gq{motion} – this means reformat to that motion where gqq means word wrap that line
- gu{motion} – make under or lowercase along that motion