What follows autocmd
is the ex command (those that start with the colon). To simulate the execution of a normal mode command, use :normal
. The problem is that you cannot pass <CO>
(and not <Ctrl-O>
) directly to :normal
, it will be interpreted as literal characters (<, then C, then r), which is not a very significant normal command. You have two options:
1.Paste the literal character ^ O
Use control v control o to get one:
au BufEnter *.pdf normal! ^O
2.Use :execute
to build your command
This way you can get a more readable result with a shielded sequence:
au BufEnter *.pdf exe "normal! \<co>"
In any case, this is not the most suitable team. <CO>
just jumps to the previous location in the jump list, so your buffer stays open. I would do something like:
au BufEnter *.pdf bdelete
Instead. However, I have another solution for you.
Create another team with a map, say gO . Then use your PDF reader directly or a utility like open
if you are on MacOS X or Darwin (not sure if other Unix systems have this and what it's called). It's just like double-clicking the file icon is passed as an argument, so it will open your default PDF reader or any other application configured to open any default file, such as an image or so.
:nnoremap gO :!open <cfile><CR>
This <cfile>
will be expanded to the file under the cursor. Therefore, if you want to open the file in Vim, use gf . If you want to open it by default application, use gO .
If you do not have this command, or if you prefer only a PDF solution, create a map your preferred command:
:nnoremap gO :!FoxitReader <cfile> &<CR>