Vim: ZZ and zz: Do you know the difference?
programmerhat.com
programmerhat.com
It works with everything but I use it with vi most of all.
You can even sleep as many processes as you like and choose which one to return to the foreground as needed.
It’s not a trivial thing to support though. ‘jobs’, ‘bg’ and ‘fg’ need to be shell builtins. Other shell builtins might not work if they’re not POSIX fork()s and you need to handle STDIN a little more carefully.
It’s a lot of work for a feature that many alt shell users might not even be aware of.
The real issue is when you do ctrl-z from muscle memory on Windows while running nvim from cmd (through wsl runner but not from an actual shell) and then it just disappears and takes your data with it.
- you get a new shell, so your history is lost
- if you have a "stack" of vim's you have to return to them in stack order
- I develop a habit of typing Ctrl-d when I want to get back to vim, which means I accidentally log out of SSH sessions all the time if I actually haven't still got vim open
I think getting in the habit of using Ctrl-z instead would be a big improvement.
To prevent that from happening you can add this to your .bashrc
#write to history file at each shell prompt
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"So far it's a 6/10 Slightly better then not doing it. =)
I use this plugin: https://github.com/akinsho/toggleterm.nvim
Nvim also has a new --listen flag (if you ever tried nvr this is now built in). So no matter where you are the file will open in your main nvim instance.
No need to exit.
It was adopted by the Korn shell, then codified into the POSIX shell.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/j...
Now that I'm on Win11, I definitely need to revisit that - thanks for the reminder!
The only downside, though, is the clipboard won't be as easily accessible. I'm thinking of things like piping text to clip.
$ ls -al | clip
Command 'clip' not found, but can be installed with:
sudo apt install geomview
"geomview" has something to do with 3D images.I tried this with Ubuntu 18 and 20 ...
1. Installs msys2 (which includes pacman package manager) # can be done separately from your git installation
2. pacman -S tmux # install tmux to msys2 within msys2
3. Copy tmux.exe and msys-event-2-1-7*.dll from msys2 to C:\Program Files\Git\usr\bin # may be a different version msys-event
4. Uninstall msys2! This was important to me because I found edge cases where msys2 did not honor directory links as "not msys files" and it borked things. YMMV
#!/bin/sh
# turn off stupid flow control and shut up.
stty -ixon -ixoff 2>/dev/null
# Allow Ctrl-z to toggle between suspend and resume
function Resume {
fg
zle push-input
BUFFER=""
zle accept-line
}
zle -N Resume
bindkey "^Z" ResumeThrew it in my .zshrc right away. Thank you sir.
That said, if you wanted to continue running in the background with `bg`, you could make that substitution to allow you to double tap Ctrl-z to do so.
Saw this in the internets
if [[ $- == i ]]; then
stty susp undef
bind '"\C-z":" fg\015"'
fi bind \cz 'fg 2>/dev/null; commandline -f repaint'
from: https://github.com/fish-shell/fish-shell/issues/7152#issueco...However shelling out was intrinsic to my workflow. We didn’t have screen or any of the other common multi session terminal programs at the time.
One day I decided to log out. I rarely logged out. If anything I was kicked off by a system restart.
So to log out I started closing sessions. Turns out I was at least 30 deep. Some files were being edited more than once, I even had shells within shells (which typically did to play ENV shenanigans).
:!ack "stupid_structure->who_wrote_this_crap.oooohhhhh\s+="
(and if you wonder what "ack" means: https://beyondgrep.com/)
1. If you want to learn a non-QWERTY layout (e.g. Dvorak or Colemak), you're going to have trouble. (Although some users to try and go to the effort of remapping to suit the layout).
2. Similarly, you might also have trouble if you get a fancy keyboard that doesn't use a row-stagger, like a kinesis, moonlander, crkbd etc.
It reminds me of some bilingual kids I know that can understand their dad's language perfectly, but they have a really hard time speaking it (since they always reply in their mom's language). You only learn what you practice.
Well played. This is a nice way to check whether you read the article first or last.
What's up with thirty different ways to exit vim? ZZ, :q, :wq, :x, good lord! Vim must be the most effective editor as long as you want to not use it. :)
Shift-zz is great as it uses only one hand and can be done in a rolling sort of movement.
Makes me wonder what'll happen if I type QQ, WW, EE, until getting through the whole keyboard. It'll probably summon Moloch.
This is not unique to vim, other editors handle it with prompts and buttons.
https://web.archive.org/web/20230109091524/https://www.progr...
nnoremap <C-j> 4<C-d>
nnoremap <C-k> 4<C-u>
vnoremap <C-j> 4<C-d>
vnoremap <C-k> 4<C-u>
I set it to scroll 4 lines at a time but you can tweak the number to make it scroll faster or slower.Unrelated but I also have a command to remove highlighting from search results:
nnoremap <silent> <C-l> :nohl<CR><C-l>I prefer to use the scroll offset[0] to keep the cursor line always at the center of the screen.
I've been using 'so=20' for a long time now and it feels great.
[0] - https://vim.fandom.com/wiki/Keep_your_cursor_centered_vertic...
Then I realized that I use some alternative setting that makes zz kinda redundant. I use `set scrolloff=3`.
Edit: more elegant solution https://news.ycombinator.com/item?id=34308688
" Center screen on next/previous selection.
nmap n /<CR>zz
nmap N ?<CR>zz
" Last and next jump should center too.
nnoremap <C-o> <C-o>zz
nnoremap <C-i> <C-i>zz " Center screen on next/previous selection.
nnoremap n nzz
nnoremap N Nzz
" Last and next jump should center too.
nnoremap <C-o> <C-o>zz
nnoremap <C-i> <C-i>zznnoremap <C-d> <C-d>zz
nnoremap <C-u> <C-u>zz
BTW I did not upvote this story.
Scrolloff short for scroll offset is the number of lines vim ensures between the cursor and the modeline, as well as between the cursor and the top of the screen.
Super useful for always keeping a good amount of context visible. You can even set it so high the cursor is always centered.
zz: Center view vertically on the cursor line. ZZ: save and close.
Yet, as a long time user, I regret that beginners are often presented with a list of commandes to memorize and are never introduced to what makes vim actually nice: composing scopes and actions.
I have the same issue with the s command. Most people treat the parameters as something slightly magical to be googled when needed. Meanwhile, reading the ed manual was eyes-opening for me. It really helped me understand both where vim comes from and what sed does.
These movement keys are at least 40% the reason I love and use vim or vim plugins. Not having to move my hand, and being able to “drive” with only one hand are immensely beneficial.
With cursor keys, it feels like half of my editing time is spent finding the arrow keys and then finding the home typing position.
Emacs ctrl n/p/f/b are better than cursor keys often, but they require two hands.
The best part of evil-mode in Emacs is that I get to use Emacs bindings in insert mode, and then vim keys in normal mode. For instance when writing function signatures, I can hit C-f to easily jump over the closing parenthesis, or C-e to easily jump to the end of line, usually also to skip the closing parenthesis. I'm not sure how you would do that in vim without exiting back into normal mode and using for instance S-a to append at the end of the line.
From insert mode, vim lets you run one command without explicitly switching back to normal mode. :he i_ctrl-o for details. It's very handy for positioning the cursor for more input, for example ctrl-o f)
Also works in evil.
Also, zz is _so_ practical, it's probably the shortcut I miss the most when I'm not using a vi-compatible editor...
I use ma, mb, etc and ‘a ‘b and ‘’ to mark and jump around, beyond the other options.
Because it is deeply frustrating when Vim complains about :Wq "not existing" well, duh. A lot of people remap those to lower case so that Wq works (also Q!, etc)
But then I switched to nano.
but it’s not really “zooming” it’s scrolling or panning.
I've only recently started using ctrl+c to move from input mode to normal mode
It so happens that rehashing of Vim's documentation on basic commands does not make it interesting enough. When articles on these basic commands (that are easily and better learnt from Vim :help) come on HN again and again, it can lead to a boring reading experience. It stops being interesting. For some people, this can reduce the real value of HN.
I'll confess that my comment may appear as elitist. But hey, at least I am being honest, from my high-horse, elitism and all. If you can get past the thorny issue of elitism, perhaps you can see my point. My point is that I appreciate why these articles appearing too often can be bothering to some. I hope you can appreciate it too.
That's not to say that there is anything wrong with these posts. If the community likes it and upvotes it enough, so be it. There is a "hide" link to hide the story if it is really bothering someone. A few basic Vim articles every week is not really a big problem even if it ends up bothering some people. I can live with it and I hope the parent commenter can live with it too.
Among others, I personally enjoy the basic commands stories, because, as can be seen in the comments, it is often news even to long term users.