In my .vimrc, I have the following exec command:

inoremap <C-f> <Esc>: silent exec '.!inkscape-figures create "'.getline('.').'" "'.b.vimtex.root.'/figures/"'<CR><CR>:w<CR>

where inkscape-figures create (figure) is a bash command. However, I want to include the following command

inkscape-figures watch

to be executed when I press CTRL+F in insert mode.

I dont understand the syntax of exec and I haven't found anything similar online.

  • Welcome to Vi and Vim! Can you clarify what parts you don’t understand? Have you read :help :execute and :help :map? – D. Ben Knoble Sep 16 '19 at 12:12

You seem to be under the impression that "exec" is used to execute external shell commands, but that's not the case.

The :execute command is simply used to run a Vimscript from a string, and this is used in this case to assemble a shell command-line from a string, to include arguments for the contents of the current line and also the path to the figures/ directory.

Then this is being passed to a :.! command, which runs the external command on a shell, passing the current line through the standard input, and then replacing the current line with the output produced by the external command. (See :help :range!, where . is being used as a range for the current line.)

However, I want to include the inkscape-figures watch command to be executed when I press CTRL+F in insert mode.

You can similarly use that as a filter, or use the :r! command to simply read the output of the external command, without any input, and pasting it below the current line.

For example:

:r!inkscape-figures watch

If that's what you want, you can map that to the Ctrl-F combination in insert mode using:

inoremap <C-f> <Esc>:r!inkscape-figures watch<CR>o

It seems you actually want to execute both commands with the Ctrl-F keypress. You can surely do that, either use the two commands in sequence with <CR> in between them, or execute both commands in a single shell separating them with ; or perhaps && (i.e. anything you can do on a shell.)

We'd need more details about what exactly you want to be able to give you a more detailed and complete answer, but hopefully this addresses your point about "exec" and gives you enough pointers to be able to come up with a useful mapping on your own.

  • Thank you very much, I have exactly been looking for this! – Aericura Sep 17 '19 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.