tags:

views:

107

answers:

4

How can you open the following PATH by ctrl-w-f to a new window?

Path

 /usr/masi/codes/11

The PATH refers to a file 11.tex. I need to use 11 instead of 11.tex because my LaTeX or pdflatex does not understand PATHs with tex when I input/include the file.

Possible solutions are

  • to add something to .vimrc
  • to use perhaps differently pdflatex
+1  A: 

It seems you'll need to override CTRL-W_f to add a extension. For instance, you could add the following in a tex-ftplugin:

nnoremap <buffer> <c-w>f :exe ':sp '.globpath('.', expand('<cfile>').'.*')<cr>

NB: this mapping is far from perfection. It's still need to glob on , and .*, to keep only one file (or none) if several match. And to support the no-match case.

Luc Hermitte
+1  A: 

I don't know about latex to answer from its side, but I don't see a setting to make Vim look for the path with extensions, so you will have to create a custom mapping. Unfortunately, there are no command-line equivalents to the gf and f style of commands, so you have to mimic something equivalent (sorry, untested).

function! OpenFile()
  try
    exec "normal! \<C-W>f"
  except
    if filereadable(expand('<cfile>').'.tex')
      split <cfile>.tex
    endif
  endtry
endfunction
nnoremap <silent> <C-W>f :call OpenFile()<CR>

You can put this in an ftplugin (with option for nnoremap) to restrict it to your latex files only.

Note: If you want to cover different cases such as gf, F, you will need a more sophisticated function, or just write different functions for each.

Irha
A: 

I use vim 7.2 and it really works with default settings. If i understand the problem well. It works with soft link and hard link both.

Vereb
+7  A: 

In Vim 7.2, you can set the suffixesadd to .txt as below:

:set suffixesadd=.tex,.latex,.java

see :help suffixesadd

Ayman
Thank you for your answer! It is exactly what I am looking for.
Masi