4 ms·
Given the title of the article, I was really hoping that the author would answer the following question. Suppose I have the following line: >rsync ~/20160604/a
by aabajian 10y ago
Given the title of the article, I was really hoping that the author would answer the following question. Suppose I have the following line:
>rsync ~/20160604/apache-tomcat-7.0.63/webapps/ROOT/contact.html apache-tomcat-1:/svr/apache-tomcat-7.0.63/webapps/ROOT/
I'm rsyncing the contact.html file to my website. Now I want to rsync the index.html page. I do this by:
1. Pressing the up arrow key to get the previous command.
2. Press and hold the back arrow key until it gets to "contact.html"
3. Press and hold backspace to delete "contact.html" and type "index.html"
My question is: How to quickly move the cursor to a location on the line. For example, in Vi I could do "F+c" twice to move to the first "c" if this were a text file. I know I can enabled Vi commands for Bash, but this seems cumbersome. There has to be a way in Bash to jump around the already typed line.
- Gorgor 10y agoIt's not as precise as vi movement, but for most command line activities I find the Emacs-like movements sufficiently practical: M-b: back one word M-f: forward one word C-a: beginning of line C-e: end of line I also don't like to use the arrow keys because they are so far away, so: C-b: back one character C-f: forward one character C-p: previous command C-n: next command And since I'm making a list now anyway: C-k: Kill to end of line. C-u: Kill to beginning of line. C-y: Yank (put/paste) last killed string. You can then cycle further through the kill ring with M-y. But I have a question concerning Emacs movement: M-b and M-f are rather similar to vim's b and e, respectively, meaning they don't jump to the beginning/end of the non-whitespace-string. That's why vim has B and E. Is there anything similar in Emacs?
- mikelward 10y agoThe equivalent in Emacs mode (the bash default) is Ctrl+]. Alt+<number> followed by that goes to that <number> occurrence of the character, so "Alt+4 Ctrl+] c" would go to the 4th c. Ctrl+Alt+] searches backwards in the same way. But I find just about anything better. !!:s/contact/index/ ^contact^index alias r='fc -e - --' # if not already present r contact=index or if you know ahead of time, do them both together rsync ~/20160604/apache-tomcat-7.0.63/webapps/ROOT/{contact,index}.html
- falcolas 10y agoIf you do man-bash, and look for the READLINE header, you can see all of the navigation and history manipulation functions available to you. Of particular interest would be forward-word, backward-word, and edit-and-execute-command.
- lolive 10y agoMy habit is: Ctrl-x Ctrl-e after your step 1. (Note: be sure to have your $EDITOR set) Otherwise, typing ^contact^index after your step 1 should also work.
- dwdz 10y ago^contact^index
- CaptSpify 10y agoMaybe you are asking a different question than this, but this should work: > $ mroe file1 ; mroe file2 > $ !!:gs/mroe/more But instead, you would do: >$ rsync ~/20160604/apache-tomcat-7.0.63/webapp /ROOT/contact.html apache-tomcat-1:/svr/apache-tomcat-7.0.63/webapps/ROOT/ > $ !!:gs/contact/index
- lolive 10y agoYet another option: Typing "Ctrl-r aString" will recall the previous command and position the cursor where the string "aString" occurs. You can then Alt-d, Ctrl-w, whatever. cf http://stackoverflow.com/a/2215511 http://stackoverflow.com/a/2215511
- niedzielski 10y agoI've added word hopping ctrl-left / right keybindings to my ~/.inputrc (you can also put it in your .bashrc but .inputrc works for all readline programs including bash): "\e[1;5C":forward-word "\e[1;5D":backward-word The readline manual shows more sophisticated argument operations. Zsh, IIRC, has more features for command processing.
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]
- devnonymous 10y agoSince you know how to do this in vi, do a Ctrl+x Ctrl+e to open the command in $EDITOR. Closing the editor will execute whatever was edited in it.
- philsnow 10y agoThere's also a shell builtin `fc` (mnemonic: fix command) that does this.
- hxegon 10y agoHe talks about using ^ substitution in the article. You could do: ^contact^index