You need to do 3 things:
- fix your mapping to run the command properly
- create a mapping local to a specific buffer by using the
<buffer>
option fornnoremap
. - load the mappings for just a specific filetype.
First fix the mapping by using executing the command as single ex command by using <bar>
and removing :
's & <cr>
's. We also remove the filereadable portion because we just wrote the file.
nnoremap <buffer> :up!<bar>!latexmk -pdf<cr>
or you can use an expressing mapping like FDinoff suggested.
Note the <buffer>
option on the mapping. This makes the mapping only available to the current buffer not every buffer.
Now we need to make sure this mapping only works for tex
filetypes. This can be done via an autocommand in your .vimrc
like so:
autocmd FileType tex nnoremap <buffer> :up!<bar>!latexmk -pdf<cr>
The other way option is by creating a filetype plugin. (see :h ftplugin
for more details)
A simple example is do create a file named, ~/.vim/ftplugin/text.vim
and place your mappings inside like so:
nnoremap <buffer> :up!<bar>!latexmk -pdf<cr>
I personally lean more towards the ftplugin approach but having a everything in your .vimrc
file can be nice.