0

I've been using vim for a little while and I'm doing some LaTeX with it, using Tectonic as the engine.

What I was doing to generate the pdf (without leaving the editor)

:call system("tectonic main.tex")

this works but it's extremely repetitive. After reading a little about it, I've managed to create a simple mapping.

map <C-t> :call system("tectonic main.tex") <CR> 

Which is less repetitive, but still has a hard-coded filename. Is there a way to specify that the map should be applied to the current file? Also can one concatenate operations so it saves (:w) first then applies tectonic?

3

You are looking for :h expand():

expand({expr} [, {nosuf} [, {list}]])               *expand()*
        Expand wildcards and the following special keywords in {expr}.
        'wildignorecase' applies.

        When {expr} starts with '%', '#' or '<', the expansion is done
        like for the |cmdline-special| variables with their associated
        modifiers.  Here is a short overview:

            %       current file name
            #       alternate file name
            #n      alternate file name n
            <cfile>     file name under the cursor
            <cword>     word under the cursor
            <cWORD>     WORD under the cursor

        Modifiers:
            :p      expand to full path
            :h      head (last path component removed)
            :t      tail (last path component only)
            :r      root (one extension removed)
            :e      extension only

        Example:
            :let &tags = expand("%:p:h") . "/tags"

You could use something like this:

nnoremap <C-t> :call system("tectonic " . expand('%'))<CR>

To chain it with the :w command you can use an escaped pipe like this:

nnoremap <C-t> :w \| call system("tectonic " . expand('%'))<CR>

Also remember to use nore in your mapping and to give a mode (here n)

  • 1
    Thanks! This is really what I was looking for! (Also thanks for nnoremap!) – Aristu Sep 26 '18 at 12:50
  • What about :make & 'makeprg' here? – D. Ben Knoble Sep 26 '18 at 13:46
  • 1
    @D.BenKnoble That would be the right way to go indeed but I assumed that if OP doesn't know about expand() they are probably still learning how to use Vim and will have time to learn the basic feature before they begin to use :make (and I was being lazy, ok :) ) – statox Sep 26 '18 at 13:55
  • 2
    @statox when im not being lazy maybe ill write my own answer :P – D. Ben Knoble Sep 26 '18 at 13:56

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.