4

is there a way to use vim/vi in the vim command line? Sometimes I write a long command in vim such as:

:!./script /home/user/pet --flag=1 

and I want to change for instance "user" by "other". What I usually do is to navigate the command line with right arrow which is time consuming and even more when I want to go to the beginning of the line. I would like to have something like "0" to go there or w/b to move by words. Or use j/k to go to the next/previous command.

Thanks.

5
  • What is your shell? Most have shortcuts for those things, like these in Bash: ice2o.com/bash_quick_ref.html Commented Mar 29, 2013 at 16:23
  • (It's just a matter of learning a different set of keystrokes) Commented Mar 29, 2013 at 16:23
  • 1
    I am using the zsh but what I want is to edit a command in the vim command line Commented Mar 29, 2013 at 16:26
  • Ohhh.. I misunderstood. Sounds like what you want is q:, the cmdline-window Commented Mar 29, 2013 at 16:27
  • 1
    Duplicate of stackoverflow.com/q/7186880/329063. Commented May 10, 2013 at 12:44

4 Answers 4

6
:h cedit 
  • in command line, type ctrl-F(default) to enter command window.
  • or in normal mode type q:

(for search, type q/)

Sign up to request clarification or add additional context in comments.

Comments

5

Vim has a feature called the "commandline window". You can enter it with Control-F by default when you're already on the commandline, or q: from normal mode, edit the commandline using vim commands, and press enter to execute. It also contains your command history so that you can yank previous commands if you like. See :help cmdline-window for more information.

Comments

2

I'm not aware how you can use Vim commands to edit a command directly on the command line, but if you enter the command window q: you get can use regular Vim editing to edit commands.

From there you can execute commands by hitting <CR> or use Ctrl-C to copy the command to the regular command line.

1 Comment

When downvoting please leave a comment. Thanks.
0

If you run set -o vi you will have vim capabilities in your command line. Just put 'set -o vi' in your .bashrc file or equivalent to have it by default.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.