# More Vimism with z and g commands

- Link: https://tongfamily.com/2022/01/17/more-vimism-with-z-and-g-commands/
- Published: 2022-01-17T15:36:29-08:00
- Author: rich

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](https://vi.stackexchange.com/questions/6981/what-does-z-stand-for-in-vim)
arrived because they were [relatively](https://vim.fandom.com/wiki/Power_of_g) 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

### Share this:

 * [  Mastodon ](https://tongfamily.com/2022/01/17/more-vimism-with-z-and-g-commands/?share=mastodon)
 * [  LinkedIn ](https://tongfamily.com/2022/01/17/more-vimism-with-z-and-g-commands/?share=linkedin)
 * [  Facebook ](https://tongfamily.com/2022/01/17/more-vimism-with-z-and-g-commands/?share=facebook)
 * [  WhatsApp ](https://tongfamily.com/2022/01/17/more-vimism-with-z-and-g-commands/?share=jetpack-whatsapp)
 * [  Email ](https://tongfamily.com/2022/01/17/more-vimism-with-z-and-g-commands/?subject=%5BShared%20Post%5D%20More%20Vimism%20with%20z%20and%20g%20commands&body=https%3A%2F%2Ftongfamily.com%2F2022%2F01%2F17%2Fmore-vimism-with-z-and-g-commands%2F&share=email)
 * [More](https://tongfamily.com/2022/01/17/more-vimism-with-z-and-g-commands/#)

 * [  Telegram ](https://tongfamily.com/2022/01/17/more-vimism-with-z-and-g-commands/?share=telegram)
 * [  Print ](https://tongfamily.com/2022/01/17/more-vimism-with-z-and-g-commands/#print?share=print)
 * [  Pinterest ](https://tongfamily.com/2022/01/17/more-vimism-with-z-and-g-commands/?share=pinterest)
 * [  Tumblr ](https://tongfamily.com/2022/01/17/more-vimism-with-z-and-g-commands/?share=tumblr)
 * [  X ](https://tongfamily.com/2022/01/17/more-vimism-with-z-and-g-commands/?share=twitter)

### Like this:

Like Loading…
