is there any 'Normal mode' command to repeat last command runs in 'command-line mode'?
for example i move up a line in 'command-line mode' with :m -2 and later i want to move up some other lines.
is there any normal mode to repeat :m -2 without type :# in 'command-line mode'.
Just hit #:.
See :help #: for help.
Related
I want to use <leader>e to return to normal mode from whatever mode I am in. For insert mode I use
inoremap <leader>e <esc>
I wanted the same thing to exit command line mode, so I wrote
cnoremap <leader>c <esc>
However, when it exits command line mode, it tries to execute whatever what written past the command line. However, when I just use <esc> normally, it exists command line mode without executing anything. I usually have to press <enter> to execute the command.
Can anyone help me understand what is going on here, and what I can do to get the behavior I want.
Thanks!
According to help:
CTRL-[ *c_CTRL-[* *c_<Esc>* *c_Esc*
<Esc> When typed and 'x' not present in 'cpoptions', quit
Command-line mode without executing. In macros or when 'x'
present in 'cpoptions', start entered command.
It seems "in macros" applies to right-hand side of a mapping too (well, it's not "typed"). You can use CTRL-C instead as it will never execute the command:
*c_CTRL-C*
CTRL-C quit command-line without executing
So just do:
cnoremap <leader>c <c-c>
I am trying to add this to my vimrc but I am getting problems one it inserts {{{ at the beginning of my vimrc whenever I open it and also it apparently has 'c' in the regiser as the last pressed key so it deletes the first 2 lines when I press j
And when I run the command it complains that
"A{{{\ is missing a quotation mark and is not a command.
This gave me tip. map execute command vim
You don't need use :execute "normal! ..." if you are using nnoremap. This will work.
nnoremap <C-[> A{{{<Esc><CR>
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
:!! repeats the last :!{cmd}. You can map it to F8 like so:
:nnoremap <F8> :!!<CR>
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
nnoremap <F8> :!<UP><ENTER>
I am trying to execute a normal mode command Ctrl-n or j from Ex mode. Normally, one would do this using the :normal command. For example, the following command moves the cursor one line down.
:normal j
So does the following command. Note: ^N is typed by pressing Ctrl-v Ctrl-n.
:normal ^N
But the following command does not work. This command seems to have no effect on the buffer.
:normal <C-n>
However, when I create a new Ex command for Ctrl-n using the following command, it works!
:command Down <C-n>
Even this works, although normal is redundant here.
:command Down normal <C-n>
Now, I can use the Ex command :Down to move the cursor one line down.
My question is why does the <C-n> syntax not work with the :normal command but works with the :command command?
use :exec and escape the <c-x>:
for example:
:exec "normal \<c-n>"
in fact the instruction you can find in :h :normal help doc:
to use |:execute|, which uses an
expression as argument. This allows the use of
printable characters to represent special characters.
Example: >
:exe "normal \<c-w>\<c-w>"
Your question is probably academic (or you are trying to solve another problem) but, for what it's worth, you can already do :+ and :join.
How can you execute a command again listed in the
:history
option in vim. There are numbers shown. Is the only way to copy the command by hand, then re-enter it? Or is there something like in shell script.
:history is only there for you to look at it.
To re-execute a previous command, you have two options:
Use <Up> and <Down> at the command prompt:
:m10
(do stuff)
:<Up>
Use the "command-line window":
You can call it with q: and navigate with search and use the beautiful normal mode commands we all love.
Position the cursor on a line and hit <CR> to re-execute the command.
Edit a command and hit <CR> to execute the new command.
You can quit the command-line window with :q.
See :help cmdline-window.
I use q: shortcut in normal mode to open interactive command history window. You just move to the right command and execute it by pressing Enter. You can find more information and other ways of accessing history here.
What I like to do is type the first few characters in the command and press <UP>. For example if you want to repeat an edit command of the file file.txt you could:
:e fil<UP><ENTER>
If the first <UP> does not give you the command you want, keep pressing<UP> until you find the command you were looking for.
If Vim is compiled with +eval you can use histget( {history} [, {index}])
:exe histget('c', 15)
That isn't exactly convenient to type, so you can also create a user-defined command:
:com -nargs=1 HI exe histget('c', <args>)
Thereafter you can use HI {index} to execute the history entry:
:HI 15