Main Page | Report this Page
Computers Forum Index  »  Computer - Editors  »  Modifying file names in a :map command in Vim...
Page 1 of 1    

Modifying file names in a :map command in Vim...

Author Message
Matt...
Posted: Sun Sep 06, 2009 5:25 pm
Guest
Can someone help me make this work. This is in my filetype.vim.

au BufNewFile,BufRead *.tex :map <F5> :!latex "%" && yap fnamemodify
("%", ":r").dvi<CR>

That should be on one line. What I want to do is, when I load a *.tex
file in Vim, I want Vim to automatically map a compile & view command
to the <F5> key.
The view command needs a .dvi extension. The program is receiving
"fnamemodify( . . ." as the file name. I need fnamemodify() to be
evaluated before it's passed to the shell and it's just not happening.

Thanks!
Matt
 
Gary Johnson...
Posted: Tue Sep 08, 2009 2:16 am
Guest
Matt <mgregory22 at (no spam) gmail.com> wrote:
Quote:
Can someone help me make this work. This is in my filetype.vim.

au BufNewFile,BufRead *.tex :map <F5> :!latex "%" && yap fnamemodify
("%", ":r").dvi<CR

That should be on one line. What I want to do is, when I load a *.tex
file in Vim, I want Vim to automatically map a compile & view command
to the <F5> key.
The view command needs a .dvi extension. The program is receiving
"fnamemodify( . . ." as the file name. I need fnamemodify() to be
evaluated before it's passed to the shell and it's just not happening.

Just as you used "%" to get the current file name for latex, you can use
"%:r.dvi" to get the name of the dvi file for yap.

au BufNewFile,BufRead *.tex :map <F5> :!latex "%" && yap "%:r.dvi"<CR>

To use fnamemodify() to construct the file name, you'd have to use
:execute to evaluate the entire command and expand() to evaluate "%",
something like this (all on one line):

au BufNewFile,BufRead *.tex :map <F5> :exe '!latex "%" && yap' fnamemodify(expand("%"), ":r").'.dvi'<CR>

--
Gary Johnson
 
Matt...
Posted: Wed Sep 09, 2009 2:51 am
Guest
Thanks Gary! Those file name expansion characters have been confusing
me lately, because they don't seem to work all the time. For example,
if I do a ":echo %" (without the quotes) it gives me an "Invalid
expression: %" error. I thought I could print the file name with
that. I mean, I know there's Ctrl-g, but sometimes I like to test
things with print statements. I don't know, but thanks for the reply!

Matt


On Sep 7, 6:16 pm, Gary Johnson <garyj... at (no spam) eskimo.com> wrote:
Quote:
Matt <mgregor... at (no spam) gmail.com> wrote:
Can someone help me make this work.  This is in my filetype.vim.

  au BufNewFile,BufRead *.tex :map <F5> :!latex "%" && yap fnamemodify
("%", ":r").dvi<CR

That should be on one line.  What I want to do is, when I load a *.tex
file in Vim, I want Vim to automatically map a compile & view command
to the <F5> key.
The view command needs a .dvi extension.  The program is receiving
"fnamemodify( . . ." as the file name.  I need fnamemodify() to be
evaluated before it's passed to the shell and it's just not happening.

Just as you used "%" to get the current file name for latex, you can use
"%:r.dvi" to get the name of the dvi file for yap.

    au BufNewFile,BufRead *.tex :map <F5> :!latex "%" && yap "%:r.dvi"<CR

To use fnamemodify() to construct the file name, you'd have to use
:execute to evaluate the entire command and expand() to evaluate "%",
something like this (all on one line):

    au BufNewFile,BufRead *.tex :map <F5> :exe '!latex "%" && yap' fnamemodify(expand("%"), ":r").'.dvi'<CR

--
Gary Johnson
 
 
Page 1 of 1    
All times are GMT
The time now is Mon Dec 07, 2009 6:52 am