I am trying to create a macro to use it globaly. I have inserted this command to my .vimrc file
let @c='<esc>:r c.c'
or
let @c=':r c.c'
but in both cases when I use "@c" on any file it only prints 'c>:r c.c' on the the file
I am trying to create a macro to use it globaly. I have inserted this command to my .vimrc file
let @c='<esc>:r c.c'
or
let @c=':r c.c'
but in both cases when I use "@c" on any file it only prints 'c>:r c.c' on the the file
Try adding a '^M
' at the end of your macro, then "@c
" should work. Else ':@c
' should work as mentioned by ebenezer. You should use Ctrl+VEnter to insert '^M
'.
let @c=':r c.c^M'
Best way would be to record the macro first and then save it to the .vimrc
.
If these doesn't work, you can check the content of your register c
using "cp
and see if there is something missing.
This is described in another answer. Try something like this:
let @c = ':r c.c'
and then, in your file, use
:@c
to execute it.
If you want to include special characters in your macro (like Escape or Enter) then use a non-literal string (double quotes, not single quotes) and the correct syntax. See :help expr-string
. You could use raw special characters, as @Amit suggests, but this will make your vimrc file hard to read.
Assuming that you are starting in Normal mode and want to type @c, there is no need to start off with an Escape.
For testing purposes, I tried
:let @c = ":echo 'foo'\<CR>"
and it worked as expected. I even added this line (without the leading :) to my vimrc file just to make sure, and tested it that way. This should work:
:let @c = ":r c.c\<CR>"