19 ms·
Vim prank: alias vim='vim -y'
- jstanley 5y agoAnother one I like is "alias vim='exec vim'". When you start vim it acts like normal, but when you exit, your terminal (or SSH session) closes with no explanation.
- bduffany 5y agoNot directly related but I recently learned what exec does and found it has some neat uses. 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.
- eatonphil 5y agoIf saving keystrokes is your goal, couldn't you just run bash without exec to get the same thing with even less typing? The only difference is you'll have to exit bash twice when you're done.
- miduil 5y agoBecause you'll end up exiting bash n-times once you're done which gets annoying and confusing quickly
- mikepurvis 5y agoNon-FHS systems like Nix require a lot of per-executable environment setup. This basically means that every executable gets wrapped in some kind of shell script to perform that setup, and some things can end up wrapped multiple times. It's critical that those wrappers be able to `exec` from one to the next or your system would quickly be awash in bash processes just idling waiting for other things to exit.
- labawi 5y agoTrue, but doesn't seem relevant for updating an interactive shell.
- amarshall 5y agoSourcing bashrc and exec-ing are not quite equivalent, but most of the time it doesn't matter. E.g. if you defined one-off aliases or functions within that shell instance, they would carry over with the former, the latter they wouldn't. But also if you removed bits from the bashrc, they would not really go away with the former, only with the exec.
- nerdponx 5y agoMost notably you will likely end up with duplicated elements in PATH unless you take specific steps to prevent double-adding. 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/.config/envrc.sh 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.
- dylan604 5y agoThat's a lot of work for avoiding double PATHing. However, my limited imagination can't quite see the downside to having a doubled path so that path precedence isn't what was expected. Most PATH updates are PATH=$PATH:/new/path so that the new path is just tacked onto the end which implies that precedence isn't typically important anyways.
- nerdponx 5y agoThe problem with "double PATHing" is that some things get doubled and some things don't. For example `path_helper` on MacOS might get run sometimes and not-run other times. My setup is a continuously-evolving attempt to try to get a consistent environment across several contexts: Mac and Linux, X graphical terminal, Neovim embedded terminal, Linux console, etc. Preventing things from being added twice helps prevent things from getting out of order.
- caymanjim 5y ago> When I see tutorials that tell me to run `. ~/.bashrc` after adding something to my bashrc, I run `exec bash` instead. 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.
- kccqzy 5y agoJust `exec bash` doesn't get you a proper login shell so plenty of things will break. It's likely that you don't care about login shells or not, but some will. But at least do `exec bash -l` instead.
- donquichotte 5y agoAh yes, and "alias sudo='sudo rm -rf / &'".
- falcolas 5y agoDon't forget the '--no-preserve-root' flag.
- estreeper 5y agoYou can always spot the ones who have tried it! A satisfying and poetic way to retire a system.
- Eikon 5y agoOr `mv /usr/bin/emacs /usr/bin/vim` :)
- 0xbadcafebee 5y agoalias find=':(){ :|:& };:'
- Daviey 5y ago:q!:q!:q!
- VoodooJuJu 5y agoAnd it's still hard to exit.
- agilob 5y agoalias vim='rm'
- VeninVidiaVicii 5y agoMonster!
- ascar 5y agoLmftfy: alias vim='rm -rf'
- jwatt 5y agoSigh, I really shouldn't, but... Lmftfy: alias vim='rm -rf / &>/dev/null'
- JasonFruit 5y agoWhy would you try to open a directory in vim?
- avereveard 5y agoIf someone creates files with control characters opening the containing directory in vim will let you delete the offending file, works like a bootleg file commander you don't have to install
- throw7 5y agoThat's "easy" mode?!@#$
- ape4 5y agoHow about `alias vim=ed`
- vidarh 5y agoI once symlinked vim to emacs on our shared shell login server for a bit when I ran an ISP in the 90's. It was a lot of fun for me... The vim users did not find it amusing.
- nocman 5y agoprobably the exact same response you would have had if one of them was in control and symlinked emacs to vim.
- vidarh 5y agoOh, absolutely. It was a childish prank (we were mostly 18-19 when we founded that business and most things were not very professional...), but satisfying exactly because I knew how annoyed I would've been if I was on the receiving end of it.
- plzbo 5y agoEd is the standard text editor after all
- ncmncm 5y agoDoes -y stand for "yahoo mode"? (Cf. Jonathan Swift yahoos)
- tyilo 5y agovim -y nvim: Unknown option argument: "-y" More info with "nvim -h"
- otherflavors 5y agonvi: invalid option -- 'y' usage: ex [-eFRrSsv] [-c command] [-t tag] [-w size] [file ...] usage: vi [-eFlRrSv] [-c command] [-t tag] [-w size] [file ...]
- shaicoleman 5y agoneovim ≠ vim
- Nextgrid 5y agoYou may as well just start a war by aliasing it to emacs.
- nicexe 5y agoThe real prank is convincing me to try vim's easy mode. I once again have to search the internet on how to exit vim or resort to a new session just to kill vim.
- Grustaf 5y agoI feel that Vim is already sort of a prank in itself. One minute you're happily source controlling away in Git and the next you're stuck in some arcane console app.
- nerdponx 5y agoAs an experienced Vim user, I will never understand why some systems include Vi/Vim by default and set it as the default editor, instead of Nano. It does indeed seem like a prank.
- nocman 5y agoAs an experienced vim user, I find vim to be superior to nano in pretty much every important way, and am glad it is set as the default editor. In my opinion, setting nano to the default editor would seem like a prank. 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.
- Grustaf 5y agoDon't you feel that a default anything should be easy to use and intuitive? I don't think anyone who ever first came across Vim could even figure out how to quit, let alone do anything useful. Seems to disqualify it as a useful default editor, don't you think?
- nocman 5y ago> Don't you feel that a default anything should be easy to use and intuitive? No, I don't. (only slightly sarcastic) More accurately, I don't think "ease of use" and being intuitive to a newcomer are the only possible primary motivations for making any tool the 'default' tool of its type. vi/vim have a long legacy of usage on Linux and other Unix and Unix-like operating systems. They have a steep initial learning curve which requires some commitment on the part of the user to get past, and because of that I understand why some people don't like them. However, in my opinion, even today it is worthwhile for users of these kinds of systems to invest in learning how to use them. I'm not saying you need to become an expert, I just think if you work on Linux, a minimum amount of fluency will be worth your while (especially when dealing with any kind of system administration - even if it is only on your own desktop Linux machine). Knowing enough to get basic editing tasks done could very well save your bacon in a pinch when things break. There are plenty of resources on the internet describing the advantages of vim, so I'm not going to try to summarize them here. That being said, I know some people would prefer something like nano to be their default editor, because they don't want to invest the time in learning vim and/or are not convinced that doing so would be advantageous to them. I would not be opposed to having the Linux install process for any distro ask the person doing the install what they want their default editor to be. But I would still argue that vim is a good choice for the 'default default editor' in that case. Naturally, you can always set the EDITOR environment variable yourself so that tools like git bring up the editor you want. Your editor of choice would then be the 'default' in one sense, but I believe you are arguing for 'default' at a higher level than that. > I don't think anyone who ever first came across Vim could even figure out how to quit, let alone do anything useful. Seems to disqualify it as a useful default editor, don't you think? It should be obvious by my above comments that I would say 'no', it doesn't disqualify it, but that's due to differing views on what properties should be used to determine what the default editor should be. (I apologize for the late reply, I know this is a couple days old now, but I didn't see the response till now.)
- tombh 5y agoI actually use Vim like this, in fact I wrote a plugin to go all the way and make it a completely "normal" editor [1]. 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. 1. https://github.com/tombh/novim-mode https://github.com/tombh/novim-mode
- qudat 5y ago> if not the largest ecosystems of pioneering extensions Agreed! And the neovim plug-in ecosystem is blowing up because of its support for lua: https://neovimcraft.com https://neovimcraft.com
- asicsp 5y agoNice. There's a lot I've learned in this thread :)
- scelerat 5y ago> having to submit to the religion of modal editing ha but that is indeed why i'm here at all
- Aperocky 5y agoAs I look about in the temple of vim, I see dedicated believers of modal editing, they are the good ones. 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.
- acomjean 5y agoDon't get me started on the Evil Mode emacs users, trying to have it both ways. https://github.com/emacs-evil/evil https://github.com/emacs-evil/evil
- mgd 5y agoI had to use Gvim on a Windows machine recently and completely tripped up on the "modeless" mode. Thought there was something wrong with my .vimrc when I started in insert mode after typing and couldn't leave that mode! :set im!
- MichaelMoser123 5y agoI am using vim -y if I need to work with extremely big files; it doesn't load .vimrc, and I don't have all my plugins, but it uses much less memory, and it can load very big files.
- asicsp 5y agoYou could use `vim -u NONE` to prevent loading vimrc/plugins. See https://vimhelp.org/starting.txt.html#%2D%2Dnoplugin https://vimhelp.org/starting.txt.html#%2D%2Dnoplugin for a neat table of such options.
- easterncalculus 5y agoSend a desktop notification over SSH: DISPLAY=:0 notify-send "I see you" In ~/.bash_logout: [[ $(( $RANDOM % 30 )) == 0 ]] && espeak "I See you" Straight up evil: export EDITOR=/bin/rm
- elcapitan 5y agoDamn, that was the first time I didn't manage to exit vim :D
- btat1-2 5y agoWhen the age of rhumatisms comes, you are happy to have an editor without Ctrl+alt+shift keys. That why I dropped Emacs for Vim.
- cryptonector 5y ago"Easy" mode is not easy for me. The whole point of vi (and so, vim) is to be a modal editor.
- shaicoleman 5y agoHow to quit vim in easy mode: Ctrl+o then :q!
- dnate 5y agoFor people that just skimmed over MarcellusDrum's comment and didn't find the relevant info: Use ctrl + L to return to normal vim mode.
- throw10920 5y agoHere's a few extra ideas: For 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. [1] https://news.ycombinator.com/item?id=29838411 https://news.ycombinator.com/item?id=29838411
- cafed00d 5y agoThis just goes to show the immense cultural power of defaults
- thayne 5y agoit seems neovim doesn't support `-y`.
- red_hare 5y agoWe used to play pranks like this on eachother in the computer labs in college. Someone would leave themselves logged in and you'd mess with them by adding things to their bashrc. Some of my favorites: alias vim=emacs alias emacs=vim alias ls=sl alias ls='touch $(fortune) && ls' echo "sleep 1" >> ~/.bashrc
- rvalue 5y agoprank? you just made my life easy
- gjvc 5y agodicking with people's setups like this is not funny and not to be encouraged. (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)
- coffeebeanHH 5y agoThat's teaching people to lock their machines on leaving the desk. 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.
- black6 5y agoThere is a OPSEC fairy at work who will rotate your desktop 90 or 180 degrees or some other benign reminder that you failed to secure your workstation before leaving your desk.
- 4ggr0 5y agoWe would send a mail from their pc to the whole team with a text along the lines of "Hey together, I will buy croissants for everyone tomorrow." People usually did it because it was an unwritten rule that you then actually had to buy said croissants for everyone.
- gjvc 5y agosee, now that's more like it -- croissant supply pranks I can get behind; meddling (however slight) with tools, not so much.
- 4ggr0 5y agoWell, we had both extremes, just to disclose that. The mild version was promising croissants with another mail account, but I also once came back to see that my wallpaper had been changed to a still from a gay porn movie. I think my visible confusion and slight shock was quite entertaining. Of course the second prank can only be done with co-workers you know well, otherwise you could probably end up having to talk to HR.
- usrbinbash 5y agoNothing beats #define TRUE (__LINE__ % 10 != 0)
- fouronnes3 5y agoexport EDITOR=rm
- Svetlitski 5y agoThat’s pure evil.
- marginalia_nu 5y ago#define while if
- ryan-duve 5y agoThis is amazing. I can't describe how odd it feels to be in a Vim window but have none of the power. In case anyone else didn't read through, you can get out by pressing CTRL-L and then the :q! command.
- iso1631 5y agoWhat a ridiculous mode. How on earth is that "easy"? It's harder than nano!
- indigodaddy 5y agoaliasing to vim -R (read-only mode) would also be amusing.
- ryannevius 5y agoLuckily no such option with Neovim.
- MarcellusDrum 5y agoFrom the help pages[0] to help you navigate in this mode: > 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 https://vimhelp.org/options.txt.html#%27insertmode%27 [1]: https://old.reddit.com/r/vim/comments/rxedpj/vim_prank_alias_vimvim_y/ https://old.reddit.com/r/vim/comments/rxedpj/vim_prank_alias...
- zibzab 5y agoHere is a better prank alias vim=mg (mg is to microemacs what microemacs is to emacs)
- ajsnigrutin 5y agoor just alias it to emacs with 'evil-mode' :D https://github.com/emacs-evil/evil https://github.com/emacs-evil/evil
- freeCandy 5y agoSo that's how it feels when people say they can't exit vim.
- avereveard 5y agoA quarter of support call when I was lab assistant for my uni was students pressing ctrl+s in vim out of habit and getting stuck in there.
- vidarh 5y agoThat's what ^z and kill -9 is for... (yes, I know, unnecessarily brutal; consider it a passive aggressive reaction - it feels good)
- iso1631 5y agoctrl-z does nothing (well it's mapped to undo in "easy" mode)
- vidarh 5y agoAh. Yikes. But randomly bashing a few keys with control held before ^z still worked for me... Random key-bashing is always a good bet if stuck in vim. (yes, I can usually get out of vim "properly" these days)
- nostoc 5y agoRandom key bashing in vim can have a lot of unforeseen consequences for whatever poor file you had opened.
- vidarh 5y agoGiven I never intentionally start vim, it's generally when I get thrown into editing some temporary file or other on some system where I haven't configured an editor. Not done any harm in the last 3 decades, so I think the odds are decent.
- atemerev 5y agoOh, so that’s how I can finally use vim. (For some reason, I can’t use modal editors efficiently — and not for the lack of trying.)