GNU/Linux >> LINUX-Kenntnisse >  >> Linux

Wie verwende ich vi, um einen Befehl im Terminal unter Linux zu bearbeiten?

Wenn Sie Bash verwenden, versuchen Sie es mit edit-and-execute-command Befehl. Standardmäßig ist dies Ctrl-x Ctrl-e zugewiesen (geben Sie Strg-x, dann Strg-e ein).

Dies sollte den in Ihrer Umgebung angegebenen Editor öffnen. Alles, was sich beim Beenden im Puffer befindet, wird in der Shell ausgeführt - einschließlich mehrzeiliger Befehle.


Wenn Sie zsh verwenden der Shell-Befehl heißt edit-command-line . Es ist standardmäßig nicht gebunden, also fügen Sie Ihrer Konfiguration etwas wie das hier hinzu:

bindkey "^X^E" edit-command-line

Jetzt Strg+x Strg+e funktioniert genauso wie in bash außer dass der Befehl nicht vor Return ausgeführt wird wird geschlagen.


Sie können dies tun, indem Sie den vi-Bearbeitungsmodus einstellen. Wenn Sie Bash verwenden, können Sie Folgendes eingeben oder in Ihre Shell-Konfigurationsdateien einfügen:

set -o vi

Sie können dann, genau wie in vi, den Befehlsmodus und den Einfügemodus verwenden.

Wenn bereits ein Befehl in der Zeile steht (Aufruf durch Drücken der Pfeiltaste nach oben, CTRL-R , fzf usw.), ist ein nützlicher Befehl v im normalen Modus auf der Shell, weil es den Standardeditor startet, um den Befehl zu bearbeiten.

Ein Spickzettel aus diesem Kern:

.---------------------------------------------------------------------------.
|                                                                           |
|                          Readline VI Editing Mode                         |
|                     Default Keyboard Shortcuts for Bash                   |
|                               Cheat Sheet                                 |
|                                                                           |
'---------------------------------------------------------------------------'
| Peteris Krumins ([email protected]), 2008.01.08                          |
| http://www.catonmat.net  -  good coders code, great reuse                 |
|                                                                           |
| Released under the GNU Free Document License                              |
'---------------------------------------------------------------------------'

 ======================== Keyboard Shortcut Summary ========================

.--------------.------------------------------------------------------------.
|              |                                                            |
| Shortcut     | Description                                                |
|              |                                                            |
'--------------'------------------------------------------------------------'
| Switching to COMMAND Mode:                                                |
'--------------.------------------------------------------------------------'
| ESC          | Switch to command mode.                                    |
'--------------'------------------------------------------------------------'
| Commands for Entering INPUT Mode:                                         |
'--------------.------------------------------------------------------------'
| i            | Insert before cursor.                                      |
'--------------+------------------------------------------------------------'
| a            | Insert after cursor.                                       |
'--------------+------------------------------------------------------------'
| I            | Insert at the beginning of line.                           |
'--------------+------------------------------------------------------------'
| A            | Insert at the end of line.                                 |
'--------------+------------------------------------------------------------'
| c<mov. comm> | Change text of a movement command <mov. comm> (see below). |
'--------------+------------------------------------------------------------'
| C            | Change text to the end of line (equivalent to c$).         |
'--------------+------------------------------------------------------------'
| cc or S      | Change current line (equivalent to 0c$).                   |
'--------------+------------------------------------------------------------'
| s            | Delete a single character under the cursor and enter input |
|              | mode (equivalent to c[SPACE]).                             |
'--------------+------------------------------------------------------------'
| r            | Replaces a single character under the cursor (without      |
|              | leaving command mode).                                     |
'--------------+------------------------------------------------------------'
| R            | Replaces characters under cursor.                          |
'--------------+------------------------------------------------------------'
| v            | Edit (and execute) the current command in the text editor. |
|              | (an editor defined in $VISUAL or $EDITOR variables, or vi  |
'--------------'------------------------------------------------------------'
| Basic Movement Commands (in command mode):                                |
'--------------.------------------------------------------------------------'
| h            | Move one character right.                                  |
'--------------+------------------------------------------------------------'
| l            | Move one character left.                                   |
'--------------+------------------------------------------------------------'
| w            | Move one word or token right.                              |
'--------------+------------------------------------------------------------'
| b            | Move one word or token left.                               |
'--------------+------------------------------------------------------------'
| W            | Move one non-blank word right.                             |
'--------------+------------------------------------------------------------'
| B            | Move one non-blank word left.                              |
'--------------+------------------------------------------------------------'
| e            | Move to the end of the current word.                       |
'--------------+------------------------------------------------------------'
| E            | Move to the end of the current non-blank word.             |
'--------------+------------------------------------------------------------'
| 0            | Move to the beginning of line                              |
'--------------+------------------------------------------------------------'
| ^            | Move to the first non-blank character of line.             |
'--------------+------------------------------------------------------------'
| $            | Move to the end of line.                                   |
'--------------+------------------------------------------------------------'
| %            | Move to the corresponding opening/closing bracket.         |
'--------------'------------------------------------------------------------'
| Character Finding Commands (these are also Movement Commands):            |
'--------------.------------------------------------------------------------'
| fc           | Move right to the next occurance of char c.                |
'--------------+------------------------------------------------------------'
| Fc           | Move left to the previous occurance of c.                  |
'--------------+------------------------------------------------------------'
| tc           | Move right to the next occurance of c, then one char       |
|              | backward.                                                  |
'--------------+------------------------------------------------------------'
| Tc           | Move left to the previous occurance of c, then one char    |
|              | forward.                                                   |
'--------------+------------------------------------------------------------'
| ;            | Redo the last character finding command.                   |
'--------------+------------------------------------------------------------'
| ,            | Redo the last character finding command in opposite        |
|              | direction.                                                 |
'--------------+------------------------------------------------------------'
| |            | Move to the n-th column (you may specify the argument n by |
|              | typing it on number keys, for example, 20|)                |
'--------------'------------------------------------------------------------'
| Deletion Commands:                                                        |
'--------------.------------------------------------------------------------'
| x            | Delete a single character under the cursor.                |
'--------------+------------------------------------------------------------'
| X            | Delete a character before the cursor.                      |
'--------------+------------------------------------------------------------'
| d<mov. comm> | Delete text of a movement command <mov. comm> (see above). |
'--------------+------------------------------------------------------------'
| D            | Delete to the end of the line (equivalent to d$).          |
'--------------+------------------------------------------------------------'
| dd           | Delete current line (equivalent to 0d$).                   |
'--------------+------------------------------------------------------------'
| CTRL-w       | Delete the previous word.                                  |
'--------------+------------------------------------------------------------'
| CTRL-u       | Delete from the cursor to the beginning of line.           |
'--------------'------------------------------------------------------------'
| Undo, Redo and Copy/Paste Commands:                                       |
'--------------.------------------------------------------------------------'
| u            | Undo previous text modification.                           |
'--------------+------------------------------------------------------------'
| U            | Undo all previous text modifications.                      |
'--------------+------------------------------------------------------------'
| .            | Redo the last text modification.                           |
'--------------+------------------------------------------------------------'
| y<mov. comm> | Yank a movement into buffer (copy).                        |
'--------------+------------------------------------------------------------'
| yy           | Yank the whole line.                                       |
'--------------+------------------------------------------------------------'
| p            | Insert the yanked text at the cursor.                      |
'--------------+------------------------------------------------------------'
| P            | Insert the yanked text before the cursor.                  |
'--------------'------------------------------------------------------------'
| Commands for Command History:                                             |
'--------------.------------------------------------------------------------'
| k            | Move backward one command in history.                      |
'--------------+------------------------------------------------------------'
| j            | Move forward one command in history.                       |
'--------------+------------------------------------------------------------'
| G            | Move to history line N (for example, 15G).                 |
'--------------+------------------------------------------------------------'
| /string or   | Search history backward for a command matching string.     |
| CTRL-r       |                                                            |
'--------------+------------------------------------------------------------'
| ?string or   | Search history forward for a command matching string.      |
| CTRL-s       | (Note that on most machines Ctrl-s STOPS the terminal      |
|              | output, change it with `stty' (Ctrl-q to resume)).         |
'--------------+------------------------------------------------------------'
| n            | Repeat search in the same direction as previous.           |
'--------------+------------------------------------------------------------'
| N            | Repeat search in the opposite direction as previous.       |
'--------------'------------------------------------------------------------'
| Completion commands:                                                      |
'--------------.------------------------------------------------------------'
| TAB or = or  | List all possible completions.                             |
| CTRL-i       |                                                            |
'--------------+------------------------------------------------------------'
| *            | Insert all possible completions.                           |
'--------------'------------------------------------------------------------'
| Miscellaneous commands:                                                   |
'--------------.------------------------------------------------------------'
| ~            | Invert case of the character under cursor and move a       |
|              | character right.                                           |
'--------------+------------------------------------------------------------'
| #            | Prepend '#' (comment character) to the line and send it to |
|              | the history.                                               |
'--------------+------------------------------------------------------------'
| _            | Inserts the n-th word of the previous command in the       |
|              | current line.                                              |
'--------------+------------------------------------------------------------'
| 0, 1, 2, ... | Sets the numeric argument.                                 |
'--------------+------------------------------------------------------------'
| CTRL-v       | Insert a character literally (quoted insert).              |
'--------------+------------------------------------------------------------'
| CTRL-r       | Transpose (exchange) two characters.                       |
'--------------'------------------------------------------------------------'


 ===========================================================================

.---------------------------------------------------------------------------.
| Peteris Krumins ([email protected]), 2008.01.08.                         |
| http://www.catonmat.net  -  good coders code, great reuse                 | 
|                                                                           |
| Released under the GNU Free Document License                              |
'---------------------------------------------------------------------------'

Linux
  1. So verwenden Sie den Su-Befehl unter Linux

  2. So verwenden Sie den Befehl wget wie ein Profi im Linux-Terminal

  3. So verwenden Sie den Linux-Bildschirmbefehl

  4. So verwenden Sie den Befehl ldconfig unter Linux

  5. So verwenden Sie den ipset-Befehl unter Linux

So verwenden Sie den Befehl sysctl unter Linux

So verwenden Sie den Befehl zum Herunterfahren von Linux

So verwenden Sie grep unter Linux

So verwenden Sie den Mkdir-Befehl unter Linux

So verwenden Sie den Jobs-Befehl unter Linux

So verwenden Sie den Bildschirmbefehl unter Linux