Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I repeat the last external command

Tags:

vim

I would like to have the following behavior for a key in vim (for example the F8 key):

Find the most recent ex command starting with :! and repeat it.

For example, if my command history is

(...)
:!python abc.py
/hi
:%s/hi/ho/g
:w

then by pressing F8 I would like vim to run :!python abc.py

like image 968
mitchus Avatar asked Feb 12 '26 01:02

mitchus


2 Answers

:!! repeats the last :!{cmd}. You can map it to F8 like so:

:nnoremap <F8> :!!<CR>
like image 185
Martin Tournoij Avatar answered Feb 14 '26 14:02

Martin Tournoij


You could try the following mapping:

nnoremap <F8> q:?^!<CR><CR>

Explanation:

  • q: - open the command-line window
  • ?^! - search for a line starting with !
  • <CR><CR> - hit enter twice to execute that command
like image 43
mMontu Avatar answered Feb 14 '26 16:02

mMontu