5 ms·
If you learn bash, and you learn vi, then the next most glorious addition is: set -o vi Then you have vi keys in your shell. And it is marvelous.
by bdamm 11y ago
If you learn bash, and you learn vi, then the next most glorious addition is:
set -o vi
Then you have vi keys in your shell. And it is marvelous.
- jonahx 11y agoLearning about this was a revelation for me. I can't live without it now.
- javajosh 11y agoCan you share a little more info about this? I tried it but found it rather confusing. Also, for more readline maneuvers: http://unix.stackexchange.com/questions/21788/how-to-delete-part-of-a-path-in-an-interactive-shell/ http://unix.stackexchange.com/questions/21788/how-to-delete-...
- brown-dragon 11y ago`set -o vi` allows us to use `vi` bindings instead of the default `emacs` bindings. The way to think about it is that the prompt starts out in `vi insert mode` so whatever we type in will just be inserted at the prompt. However, we can hit the`Escape` key and move into `vi normal mode` where the keys are interpreted as normal `vi` commands. So, for example, once we hit `esc` we can navigate around the line using `h` and `l` and navigate history (previous lines) using `k` and `j`. Commands I find very useful are: `jk` : for history navigation `bw`: for moving in the current line. These are word movement commands that are faster to navigate with. `cw` : similarly, changing a particular word in the current line is also great. This works particularly well with history - retrieve a previous command and change a word or option `dw` : for deleting the current word `/` : is a fantastic command for searching history. `/cd` will bring up our last change directory command and just hitting `n` will cycle through all our change directory commands that are in history. `AI` : to insert at the beginning/end of line ...and so on. If you have `vi` muscle memory it's a fantastic option for working on the shell. (edit: Formatting)
- barbs 11y agoAgreed. I made a pull-request for this. https://github.com/jlevy/the-art-of-command-line/pull/9 https://github.com/jlevy/the-art-of-command-line/pull/9
- a3n 11y agoThat's nice, but it only affects the command line. Instead of that, create the following file: ~/.inputrc (tilde slash dot-inputrc) And in that file put at least this: set editing-mode vi Now every program that you run that a) has its own command line, and b) uses the readline library (there are a lot) has vi commandline editing. psql, mysql, telnet, lftp, and many more. man bash has a section on READLINE. For example, in man bash search for editing-mode
- baby 11y agoor if you learn emacs you have emacs shortcuts by default in shells. which goes against his childish comment on emacs: > Learn Vim (vi). There's really no competition for random Linux editing (even if you use Emacs, a big IDE, or a modern hipster editor most of the time).
- carlisle_ 11y agoI would argue it's not childish and is a strong point considering emacs is not typically installed by default. Vim isn't usually installed by default either, gotta go with good ol' vi, unless your distro maintainers are nice and symlink vim to vi for you until you install vim.
- erikb 11y agoAt first I thought the same as you, but then I realised that he's not talking about your average editor, but about which editor to use if you SSH into a random web server etc. The thing you use in a foreign environment. That's what "random Linux editing" probably means.
- omegaham 11y agoThis. On your home computer, use whatever you want. If you're using all sorts of foreign environments, you're going to want to use whatever is common to all of them so that you don't fumble around badly trying to do basic tasks. Learn vi. You don't have to like it, you don't have to use it on your home system, and you don't have to learn the eleventy-billion vim-efficiency-hacks floating around the Internet. But learn it well enough that if you have to ssh into some server that only has vi installed on it, you aren't rendered completely helpless. Even "Notepad Capability" is fine.