0

I am using Vim bindings in bash (set -o vi) and I wanted to know if it is possible to use and save Vim macros on the command line. For instance, I would like to save a macro like this:

let @q = "0y$dd"

to yank and delete a line. If I save this macro in my .vimrc file it works within the Vim editor but not on the command line.

1
  • 1
    Fwiw, Try pressing the escape key and then the letter v while in command line. Commented Apr 1 at 10:52

3 Answers 3

1

Not possible. Bash -o vi mode has almost nothing to do with Vim, it does not support Vim macros and/or .vimrc.

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

Comments

1

Note that man bash strictly speaks about "vi-mode", not "Vim-mode". You can't expect Vim features.

A convenient workaround is to use Vim to edit your command line which works naturally when set -o vi is set. Go to Normal mode with Esc and press v to edit your command line in vi (which will be an alias to Vim in any reasonably modern system).

This starts your regular Vim and will source your vimrc with whatever commands you put in there.

After you're done editing your command, use :wq to run it or :q! to abort.

As to your macro, you could probably just use dd which will delete the entire line and put the deleted text in the unnamed register. The macro in your question differs from dd only in that register 0 will contain the yanked text (the deleted line without a linebreak).

Comments

1

Try the readline bindings :

set  -o vi
bind -m vi
bind $'"@q":"\e0y$dd"'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.