4 ms·
Nice. But full vi has been available from the cl with readline for a long time. Not quite as nice as athame, but very easy and serviceable. If you are in vi m
by a3n 12y ago
Nice.
But full vi has been available from the cl with readline for a long time. Not quite as nice as athame, but very easy and serviceable.
If you are in vi mode (set -o vi, or your .inputrc is so configured), then on the command line press esc to get out of insert mode and into normal mode, then type v. A full vim editor will open in the terminal, with whatever you've typed so far.
Edit, :wq to execute the command. Delete the whole buffer and :wq if you don't want to execute anything.
This won't work anywhere but the cl I don't think, so the bit about python in athame is nice.
- finnh 12y ago"v" just opens your $EDITOR, btw, not necessarily vim-in-terminal. It's basically the same as the bash built-in "fc" command, but operates on the current line instead of the last one.
- dllthomas 12y agoInterestingly, the readline command "edit-and-execute-command" does what it says on the tin (by recourse to fc) even if you're in a context where the line wouldn't usually be executed. If you try prompting for filenames with the read builtin, and turn on readline (-e) to get completions, and hit v (or, in emacs mode, C-x C-e) to open your editor, when you leave your editor it will execute whatever you typed as a line of bash. Unexpected.
- ZeroGravitas 12y agoOoh, thank you! That's exactly what I've been looking for. Basically the only time I feel the need for vi editing powers in bash is when one (or more) long complicated commands need edited and this fills that gap nicely. One of the Google results that most succinctly summed up what this command can do: http://htks.kylemilnes.com/2012/07/bash-fc-fix-command-cheatsheet.html http://htks.kylemilnes.com/2012/07/bash-fc-fix-command-cheat...
- motoboi 12y agoTo get deadline support on command-line programs that don't, one can use rlwrap. Ex: rlwrap openssl s_client -connect IMAP.google.com:993 rlwrap telnet google.com 443
- voltagex_ 12y agoI guessed that rlwrap used an LD_PRELOAD trick but a cursory glance at the source shows that it's much more complex. Can anyone explain? This might be worthy of its own HN post.
- tlb 12y agorlwrap just pipes terminal I/O through itself. It doesn't change anything about the child process except where stdin comes from.
- 4ydx 12y agoWow this is pure gold. I cannot understand why I have never run across this until now. Thank you for pointing this out!
- a3n 12y agoLike so many things, I found that by accident. I also found editing you command and search history in vim by accident. :q will quit the editor. q: will open a buffer with a history of your vim commands, which are navigable and editable. Edit a command, then enter and it's executed. In command history edit mode, :q to exit that mode. q/ works for searches.
- emidln 12y agoYes and no. readline's vi support is missing a bunch of random stuff. The thing that tends to irk me the most is the lack of the normal mode: ge This goes to the end of the previous word. There are other things, but I use this quite a bit and when it's not there, I become temporarily jarred trying to figure out if I'm mistyping.
- a3n 12y agoYou and I are talking about two different things. You're talking about command line editing, on the command line. And you're right, ge doesn't work there. vi mode at the command line is a small subset of vi. The next time you want to use ge or any other full vim feature, try this instead: - esc, to get into normal mode. - the single character 'v' (no quotes), to open a full vi (or vim, or $EDITOR). - the vim session will have your command line so far. - edit with the full power of vim or whatever opened. - :wq to execute the command. - or empty the buffer and then :wq to not execute anything.