MacOS पर बश के साथ टर्मिनल कीबाइंडिंग का उपयोग करना


51

मैं macOS पर शेल के लिए कीबोर्ड शॉर्टकट सीखने की कोशिश कर रहा हूं, लेकिन जब मैंने ALT+ का उपयोग करने की कोशिश की B, तो यह काम नहीं किया।

आप शेल में कीबाइंडिंग को कैसे खोजते हैं, कॉन्फ़िगर करते हैं और उपयोग करते हैं? कोई भी चीटशीट मददगार होगी।


डुप्लिकेट: superuser.com/questions/113103/… ... OSX विशिष्ट नहीं, लेकिन मानक बैश कीबोर्ड मैपिंग, कस्टमाइज़िंग रीडलाइन और अन्य मज़ेदार बैश ट्रिक के बारे में बहुत सारी जानकारी प्रदान करता है ।
क्वैक कोटे

6
यह उपरोक्त प्रश्न का डुप्लिकेट नहीं है। यह कैसे OSX को टर्मिनल के लिए बाध्य होने वाले प्रमुख बाइंडिंग को पकड़ने के लिए नहीं है
आर्थर उल्फेल्ट

3
कृपया इसे डुप्लिकेट के रूप में चिह्नित करें। इसे OSX टर्मिनल के लिए 'मेटा विकल्प के रूप में उपयोग विकल्प' का संकेत देने वाला उत्तर चाहिए।
बेंटफोर्ड

जवाबों:


12

ओएस एक्स टर्मिनल पर काम नहीं करने वाले 'मेटा' कुंजी दृश्यों से निपटने का एक तरीका विशिष्ट चरित्र अनुक्रमों को विशेष कुंजीपटों को सौंपना है। गैर-यूएस कीबोर्ड वाले हम में से उन लोगों के लिए, यह अक्सर अन्य उत्तरों की टिप्पणियों में उल्लिखित "मेटा के रूप में उपयोग करें" सेटिंग की तुलना में बेहतर समाधान है। (विकल्प / अल्ट कुंजी के बिना विकास कार्य के लिए कई अंतर्राष्ट्रीय मैक कीबोर्ड अनिवार्य रूप से अनुपयोगी हैं क्योंकि कुछ महत्वपूर्ण पात्र अन्यथा अनुपलब्ध हैं। #उदाहरण के लिए यूके मैक कीबोर्ड पर कोई भी नहीं है ।)

बैश के लिए शब्द-बाएँ और शब्द-दाएँ काम करने के लिए, मैंने टर्मिनल में सेटिंग्स के "कीबोर्ड" अनुभाग का उपयोग किया है। आप इसे विशेष कोड अनुक्रम उत्पन्न करने के लिए कह सकते हैं जब विशेष कुंजीपट बनाए जाते हैं। मुझे मेरा कॉन्फ़िगर किया गया है ताकि alt+ उत्पन्न हो \033b(कि वास्तव में दो अक्षर हैं: Esc, और फिर एक लोअरकेस b) और alt+ जेनरेट करता है \033f(यानी, Esc f)। यह आपको तीर कुंजी का उपयोग करने के लिए विकल्प कुंजी के साथ आयोजित करता है ताकि शब्द को बाएं और दाएं व्यवहार मिल सके।

मैंने अभी तक काम नहीं किया है कि Escकाम की कुंजी कैसे प्राप्त की जाए - सिद्धांत रूप में आपको 'मेटा' दृश्यों के लिए उपयोग करने में सक्षम होना चाहिए, लेकिन यह काम नहीं करता है। (तो बस टाइपिंग Esc+ bएक शब्द वापस जाना चाहिए।)

यदि आपके पास एक यूएस कीबोर्ड लेआउट है, या कुछ अन्य कीबोर्ड हैं, जिसमें Apple ने उन सभी कुंजियों को प्रदान करने के लिए फिट देखा है जिनकी आपको वास्तव में आवश्यकता है, तो अन्य लोगों ने सुझाव दिया है, "मेटा कुंजी के रूप में विकल्प का उपयोग करें" (टर्मिनल की सेटिंग के कीबोर्ड अनुभाग पर भी) शायद एक बेहतर विकल्प है क्योंकि आप किसी भी मेटा कुंजी संयोजन को प्राप्त करने में सक्षम होंगे। उस पर स्विच करने के साथ, Alt+ bउम्मीद के मुताबिक काम करता है।


80

मैक ओएस एक्स का टर्मिनल BASH है, यहाँ कुछ BASH शॉर्टकट हैं:

Ctrl + A    Go to the beginning of the line you are currently typing on
Ctrl + E    Go to the end of the line you are currently typing on
Ctrl + L    Clears the Screen, similar to the clear command
Ctrl + U    Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H    Same as backspace
Ctrl + R    Lets you search through previously used commands
Ctrl + C    Kill whatever you are running
Ctrl + D    Exit the current shell
Ctrl + Z    Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W    Delete the word before the cursor
Ctrl + K    Clear the line after the cursor
Ctrl + T    Swap the last two characters before the cursor
Esc + T  Swap the last two words before the cursor
Alt + F  Move cursor forward one word on the current line
Alt + B  Move cursor backward one word on the current line
Tab      Auto-complete files and folder names

जिसे आप ढूंढ रहे हैं वह Ctrl+ है H। (यह बैकस्पेस की मार के समान है)

यदि आप एक चरित्र को वापस जाने के लिए एक भागने के चरित्र की तलाश कर रहे हैं, तो आप ढूंढ रहे हैं \b। जैसे की:

$ echo -e "one two\b\b\b\b three" # Will echo "one three"

25
"Alt" बाइंडिंग को काम करने के लिए, उपयोगकर्ता को टर्मिनल में "मेटा के रूप में उपयोग करें" विकल्प को सक्षम करना होगा । यह सामान्य विकल्प-आधारित विस्तारित वर्णों और मृत कुंजियों को प्रतिस्थापित करेगा।
क्रिस जॉन्सन

6
Sidenote: मेटा कुंजी के रूप में alt का उपयोग करना कई आवश्यक पात्रों जैसे @ [] | {} कई अंतरराष्ट्रीय कीबोर्ड लेआउट जैसे कि जर्मन या ऑस्ट्रियन पर अस्वीकार्य बनाता है। आप क्रमशः ESC-f और ESC-b दबाकर एक शब्द आगे या पीछे कूद सकते हैं। एकल वर्णों के लिए आप ज्यादातर मामलों में तीर कुंजियों का उपयोग कर सकते हैं। Terminal.app में: प्राथमिकताएं> सेटिंग्स [उन्नत] आप अपने डिलीट की को विम्स जैसे ऐप में सही ढंग से व्यवहार करने के लिए "डिलीट सेंड्स Ctrl-H" पर टिक लगा सकते हैं।
मैकलमॉन

2
-1 इस सवाल का जवाब नहीं है। क्रिस जॉन्सन ने सही उत्तर दिया, लेकिन एक टिप्पणी में।
bentford

1
Alt कमांड मेरे लिए Alt + F और Alt + B doesn't काम करते हैं। मैं बैश चला रहा हूं
शेरविन असगरी

@ मेरे लिए, दिलचस्प रूप से Esc + f और Esc + b मेरे लिए काम करते हैं, लेकिन मैं Esc को दबाए नहीं रख सकता और कई बार f या b दबा सकता हूं ; 'f' या 'b' को बाद की प्रेस पर डाला जाता है।
केनी एविट

10

मेरे यूके मैक पर, ALT + कर्सर बाएँ / दाएँ एक शब्द पीछे / आगे चला जाता है। बिल्कुल आवश्यक।


6

SS64 का प्रयास करें । यह वेबसाइट केवल कमांड लाइन संदर्भ के लिए महान है।

इस SS64 पेज से लिया गया OS X CLI कीबोर्ड शॉर्टकट ।

Bash Keyboard Shortcuts

Moving the cursor:
  Ctrl + a   Go to the beginning of the line (Home)
  Ctrl + e   Go to the End of the line (End)
  Ctrl + p   Previous command (Up arrow)
  Ctrl + n   Next command (Down arrow)
   Alt + b   Back (left) one word
   Alt + f   Forward (right) one word
  Ctrl + f   Forward one character
  Ctrl + b   Backward one character
  Ctrl + xx  Toggle between the start of line and current cursor position

Editing:
 Ctrl + L   Clear the Screen, similar to the clear command
 Ctrl + u   Cut/delete the line before the cursor position.
  Alt + Del Delete the Word before the cursor.
  Alt + d   Delete the Word after the cursor.
 Ctrl + d   Delete character under the cursor
 Ctrl + h   Delete character before the cursor (backspace)
 Ctrl + w   Cut the Word before the cursor to the clipboard.
 Ctrl + k   Cut the Line after the cursor to the clipboard.
  Alt + t   Swap current word with previous
 Ctrl + t   Swap the last two characters before the cursor (typo).
 Esc  + t   Swap the last two words before the cursor.
 Ctrl + y   Paste the last thing to be cut (yank)
  Alt + u   UPPER capitalize every character from the cursor to the end of the current word.
  Alt + l   Lower the case of every character from the cursor to the end of the current word.
  Alt + c   Capitalize the character under the cursor and move to the end of the word.
  Alt + r   Cancel the changes and put back the line as it was in the history (revert).
 Ctrl + _   Undo

 TAB        Tab completion for file/directory names
For example, to move to a directory 'sample1'; Type cd sam ; then press TAB and ENTER. 
type just enough characters to uniquely identify the directory you wish to open.

History:
  Ctrl + r   Recall the last command including the specified character(s)
             searches the command history as you type.
             Equivalent to : vim ~/.bash_history. 
  Ctrl + p   Previous command in history (i.e. walk back through the command history)
  Ctrl + n   Next command in history (i.e. walk forward through the command history)
   Alt + .   Use the last word of the previous command
  Ctrl + s   Go back to the next most recent command.
            (beware to not execute it from a terminal because this will also launch its XOFF).
  Ctrl + o   Execute the command found via Ctrl+r or Ctrl+s
  Ctrl + g   Escape from history searching mode

Process control:
 Ctrl + C   Interrupt/Kill whatever you are running (SIGINT)
 Ctrl + l   Clear the screen
 Ctrl + s   Stop output to the screen (for long running verbose commands)
 Ctrl + q   Allow output to the screen (if previously stopped using command above)
 Ctrl + D   Send an EOF marker, unless disabled by an option, this will close the current shell (EXIT)
 Ctrl + Z   Send the signal SIGTSTP to the current task, which suspends it.
            To return to it later enter fg 'process name' (foreground).

Emacs mode vs Vi Mode    
All the above assume that bash is running in the default Emacs setting, if you prefer this can be switched to Vi shortcuts instead.

Set Vi Mode in bash:
$ set -o vi

Set Emacs Mode in bash:    
$ set -o emacs

नोट: Alt कुंजी शॉर्टकट का उपयोग करने के लिए >> टर्मिनल प्राथमिकताएं खोलें >> सेटिंग्स टैब >> कीबोर्ड >> टिक "मेटा कुंजी के रूप में उपयोग करें विकल्प"

टर्मिनल प्राथमिकताएँ


1
"मेटा कुंजी के रूप में उपयोग करें विकल्प" ने मेरे लिए काम किया।
साइबर-भिक्षु


1

वास्तव optionमें, OS X टर्मिनल में मेटा की कुंजी को मैप करने की आवश्यकता नहीं है , option+ left-arrow, option+ की right-arrowजगह क्रमशः Alt+ Fऔर Alt+ B। अन्य सामान्य रूप से उपयोग किए जाने वाले शॉर्टकट अन्य प्लेटफार्मों पर कार्यान्वित किए गए सभी काम करते हैं। कुंजी escकी मूल कार्यक्षमता का अनुकरण कर सकते हैं Alt, लेकिन यह escएक संशोधक के रूप में उपयोग करके थोड़ा असुविधाजनक हो सकता है , साथ ही आप इसे पकड़ नहीं सकते हैं escऔर बार-बार दबा सकते हैं Bया F, आपको इसे हर बार फिर से ऊपर ले जाने और इसे वापस धक्का देने की आवश्यकता है।

टी एल; डॉ

option+ left-arrow= एक शब्द वापस

option+ right-arrow= एक शब्द आगे


विकल्प chords मेरी ओएस एक्स टर्मिनल में काम नहीं करते।
केनी एविट

0

आपको मेरी प्रोफ़ाइल में रुचि हो सकती है: https://github.com/lingtalfi/mac-terminal-shortcuts

यह निम्नलिखित (सहज) शॉर्टकट प्रदान करता है:

ALT-left: move one word backward
ALT-right: move one word forward
CTRL-left: move to the beginning of the line
CTRL-right: move to the end of the line
ALT-backspace: kill one word backward
ALT-del: kill one word forward
ALT-up: set word after cursor to uppercase
ALT-down: set word after cursor to lowercase
CTRL-backspace: Same as ALT-backspace
CTRL-del: Same as ALT-del
home: move to the beginning of the line
end: move to the end of the line
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.