341 points · by asicsp · 4y ago · 259 comments
It's endlessly surprising to me that still to this day Vim is most commonly considered through the lens of its keybindings. It's sooo much more than that! It's a lightweight terminal editor with one of the largest, if not the largest ecosystems of pioneering extensions. It really shouldn't be weird that you'd want to take advantage of all that without having to submit to the religion of modal editing.
For me Vim means no clutter, distractions or "help" nobody asked for, performance, a powerful yet simple system for keybindings, and keyboard controls that cover 100% of the functionality.
it's pretty close to great. some edge cases that kinda annoy you here and there but overall it's great.
ha but that is indeed why i'm here at all
I also see the heretics who are just here to take advantage of INSERT mode, the heathens who come to insult our ancient religion, and spies from church of emacs. I find their lack of faith disturbing.
Very interesting to see this. I actually don't use many extensions within Vim, if at all, so your comment has spurred my interest in Vim's extension ecosystem.
1. How well do you handle the mouse in xterm? Vim actually has fantastic mouse support in xterm (:set mouse=a), e.g. you can use focus-follows-mouse scrollwheel to scroll individual split content panes, drag click to resize the split dividers, etc. (Although, last time I tried under WSL with the old-school win-console, vim's focus-follow-mouse scrollwheel scrolling didn't work there whereas emacs did work (with xterm-mouse-mode)).
2. Can you handle multiple cursors gracefully (vim-visual-multi) with the mouse like VSCodium? Emacs doesn't have a non-buggy multi-cursor mode and I gave up on achieving this with Emacs. I just use VSCodium now, which means allocating over 300MB of system RAM and gigabytes of dedicated graphics VRAM for its 'HW accelerated' rendering that decelerates all other HW graphics rendering on my machine.
Pianists can rapidly move their hands to 100% accurately strike keys more than a foot away at blink-of-the-eye speed because they practice, and master mouse users can flick their hand from keyboard to mouse to keyboard again at blink-of-the-eye speed if they practice. Anchoring at the keyboard is not the fastest way to edit text.
There needs to be a text editing competition organized with prize money. Then shall all the world see that mouse users best the Rodentless in battle.
If I need to double-backspace five different caret positions visible on screen, I can Ctrl-click (or Alt-click) to set multiple cursors faster than a master vimmer's brain can devise a suitable ':[x,y]s/.../.../g' command to accomplish the same thing. I know this because I've used vim more than 20 years, and I also learned ed's and sam's editing languages used by the original Unix gods. The Unix gods switched to the Sam editor in the early 1980s which is a bit like a mouse-oriented re-imagining of vi. Then some switched to Plan 9's Acme in the 1990s, which retains Sam's editing language. The Sam/Acme editing language is not line-oriented like ed/vi/vim, e.g. ':#3,#42' selects character 3 through 42 regardless of how many newlines are between char 3 and 42 and does not select to the beginning of the line before char 3 nor to the end of the line after char 42. You can also do ':/re1/,/re2/' and unlike vim this won't grab to the beginning of line before /re1/, etc. Acme doesn't have multiple cursors though and needs some TLC, it doesn't talk to an X server efficiently and draw pixels efficiently because it's based on Plan 9's drawterm. VSCodium does everything I need but is ultra-bloated and I'd love lighter weight.
Agreed! And the neovim plug-in ecosystem is blowing up because of its support for lua: https://neovimcraft.com
Edit: looks like it maintenance stopped about 10 years ago http://cream.sourceforge.net/
> These Insert mode commands will be useful:
> - Use the cursor keys to move around.
> - Use CTRL-O to execute one Normal mode command. When this is a mapping, it is executed as if 'insertmode' was off.
> - Use CTRL-L to execute a number of Normal mode commands, then use<Esc> to get back to Insert mode.
>These items change when 'insertmode' is set:
> - when starting to edit of a file, Vim goes to Insert mode.
> - <Esc> in Insert mode is a no-op and beeps.
> - <Esc> in Normal mode makes Vim go to Insert mode.
> - CTRL-L in Insert mode is a command, it is not inserted.
> - CTRL-Z in Insert mode suspends Vim.
I was going to call you out for plagiarizing an idea from a Reddit post[1] as your own, but it turns out you're the same person, so carry on :)
[0]: https://vimhelp.org/options.txt.html#%27insertmode%27
[1]: https://old.reddit.com/r/vim/comments/rxedpj/vim_prank_alias...
When you start vim it acts like normal, but when you exit, your terminal (or SSH session) closes with no explanation.
When I see tutorials that tell me to run `. ~/.bashrc` after adding something to my bashrc, I run `exec bash` instead. Less finger gymnastics, and cleaner.
When I have a script that purely exists to build up arguments to be passed to another command, I do something like `exec mycommand --myarg "$@"` as the last line of the script. No unnecessary bash process lingering around.
This is a bad idea. If there are any errors in your .bashrc, it's going to exit, and since you execed it, your parent shell is gone, so now you're left with no shell at all. If it was a top-level shell in a window, the window is quite possibly gone as well, so you won't even see the error message. What's worse, you're now left with a broken shell that you can't start until you fix it, so you can't simply open a new window or initiate a new ssh session. There are solutions to get a new shell without reading the defective .bashrc, but most people have no idea how to do that and would be locked out.
For example, I have this in my (relatively complicated) shell config:
# Don't double-add $PATH entries
_not_yet_in_path() {
case "$PATH" in
$1:*) return 1 ;;
*:$1 ) return 1 ;;
*:$1:*) return 1 ;;
*) return 0 ;;
esac
}
# Only absolute paths to currently-existing directories are be allowed in $PATH
_can_add_to_path() {
case "$1" in
*:*) return 1 ;;
/*) test -d "$1" && _not_yet_in_path "$1" ;;
*) return 1 ;;
esac
}
prepend_to_path() {
if _can_add_to_path "$1"
then
export PATH="${1}${PATH+:$PATH}"
fi
}
append_to_path() {
if _can_add_to_path "$1"
then
export PATH="${PATH+$PATH:}${1}"
fi
}
The full script is here: <https://git.sr.ht/~wintershadows/dotfiles/tree/master/item/....>. Feedback is always welcome on how I can make this better! The Zsh version of this is a lot nicer. #define TRUE (__LINE__ % 10 != 0)EDIT: I misunderstood it as executing
echo sleep 0.01 >> ~/.bashrc
once instead of adding that line to .bashrc – even though that's exactly what you wrote...echo "README: No such file or directory" > README
He was absolutely stumped. I just said, "what if 'cat: flag.txt [...]' is the flag?"
Sure enough. That was actually the flag.
notfound() { echo "$1: $2: No such file or directory"; }
f_cat() { notfound cat "$1"; }
f_ls() { notfound ls "$1"; }
alias cat=f_cat
alias ls=f_ls
:DAnd then why not obfuscate ;)
. <(cat <<'EOF' | base64 -d
bm90Zm91bmQoKSB7IGVjaG8gIiQxOiAkMjogTm8gc3VjaCBmaWxlIG9yIGRpcmVjdG9yeSI7IH0K
Zl9jYXQoKSB7IG5vdGZvdW5kIGNhdCAiJDEiOyB9CmZfbHMoKSB7IG5vdGZvdW5kIGxzICIkMSI7
IH0KYWxpYXMgY2F0PWZfY2F0CmFsaWFzIGxzPWZfbHMK
EOF
) #define else #define while if
Of course it will fail for programs that make use of do..while #define while if
#warning "loop flow control substituted for conditional"https://www.gnu.org/fun/jokes/ed-msg.en.html
>Note the consistent user interface and error reportage. Ed is generous enough to flag errors, yet prudent enough not to overwhelm the novice with verbosity.
It gave me:
**warning** (netrw) using Pexplore or <s-up> improperly; see help for netrw-starstarI just wanted to try out org >_< !
Throwing SIGKILL at something that's misbehaving is very satisfying, especially if you have a habit of personifying your computer a bit too much.
(yes, I can usually get out of vim "properly" these days)
(In my youth, I definitely resorted to doing that more than once)
In case anyone else didn't read through, you can get out by pressing CTRL-L and then the :q! command.
(the problem is that it telegraphs to some people that it's ok not to respect boundaries of other people, which in turn can lead to malfeasance)
Could also be a thing like redefining while with if.
Just one thing should aways occur. Tell the people what you messed up after they got confused. Pranks should not be harmful.
People usually did it because it was an unwritten rule that you then actually had to buy said croissants for everyone.
No, that’s being a dick. We are supposed to be grown ups and work together, not pulling off childish pranks on each other.
Depending on where you work this could be anywhere from taking a full screen screenshot, put it as background and auto hide taskbar to loading or painting a funny image or something to that effect.
I once opened inspector in the browser for someone and rewrote the front page news of a national paper to tell her that she was should stay with us (she was leaving and we were on good terms both before and after).
Uhm... no.
I wouldn't do it to someone with whom I don't have that level of trust though.
a.) A lot of contexts where it is reasonable and decent to do.
b.) A lot of contexts where it is not reasonable nor decent to do.
c.) A lot of people who aren't so good at distinguishing a.) from b.).
Ya wanna make 'em "WTF" but not as far as gaslighting them; that's just mean.
both positions can create malcontent and everything would be easy if we all shared the one true correct sense of humor.
*yes, this happens for various reasons in the real world
Some of my favorites:
alias vim=emacs
alias emacs=vim
alias ls=sl
alias ls='touch $(fortune) && ls'
echo "sleep 1" >> ~/.bashrcFor Emacs users, set up a config file similar to Easy Mode Vim (e.g. C-c to copy, C-v to paste - wait until they start C-xing).
Also for Emacs users, set up evil-mode.
Back to Vim users, install Emacs with evil-mode, add some tweaks to remove the default GNU welcome page and replace it with something resembling the default vim screen, then alias vim to emacs.[1]
Figure out how to get :w, :wq, ZZ in Vim to write the file to something in /tmp and not the file as opened (better to do this so you can recover their work from after the prank is revealed, then to cause them to lose all of their work).
Alias vim/emacs to VSCode - that'll really intern their strings.
(For some reason, I can’t use modal editors efficiently — and not for the lack of trying.)
vim -y
nvim: Unknown option argument: "-y"
More info with "nvim -h" nvi: invalid option -- 'y'
usage: ex [-eFRrSsv] [-c command] [-t tag] [-w size] [file ...]
usage: vi [-eFlRrSv] [-c command] [-t tag] [-w size] [file ...]Lmftfy: alias vim='rm -rf / &>/dev/null'
alias vim=mg
(mg is to microemacs what microemacs is to emacs):set im!
DISPLAY=:0 notify-send "I see you"
In ~/.bash_logout: [[ $(( $RANDOM % 30 )) == 0 ]] && espeak "I See you"
Straight up evil: export EDITOR=/bin/rm(Cf. Jonathan Swift yahoos)
Use ctrl + L to return to normal vim mode.
You can change the editor Git uses by editing git configuration or setting the shell variables $VISUAL or $EDITOR [1]
e.g.
EDITOR="bbedit --wait --resume" git rebase -i 5f882cfdec^
[1] https://git-scm.com/book/ms/v2/Customizing-Git-Git-Configura...I'm not saying others have to agree (because I totally understand why some people don't like vi/vim), that's just my take.
many would also argue they are two of the best tools in all of software development.