3

I have a question regarding a plugin called Vimfiler. What I want is to open a .doc/.docx file using MS Word from Vimfiler. For this, I added the following

call vimfiler#set_execute_file('doc,docx', '/Applications/Microsoft Word.app')

to .vimrc. Even if I pressed Return after choosing a .doc file on Vimfiler, MS Word did not start. I also attempted to select the open action by pressing a after choosing a .doc file, but the same result as before.

Can anyone tell me how to proceed?

MacVim on El Capitan

2

In your specific case, it is likely OSX already associates .doc and .docx files with MS Word. So you can use that to your advantage, using vimfiler_execute_system_associated, which is mapped to x:

x                       <Plug>(vimfiler_execute_system_associated)

Just pressing x on the filename should be enough.

  • Wow! x worked! It worked even without the mapping you suggested. Thanks so much! – T_T Feb 9 '16 at 10:42
3

I don't have Word or Windows so I tried solving your issue with Libreoffice and .odt files. The following code seems to work:

call vimfiler#set_execute_file('odt', 'libreoffice')
augroup vimfiler_mapping
    autocmd!
    autocmd FileType vimfiler nmap <buffer> x <Plug>(vimfiler_execute_vimfiler_associated)
augroup END

Maybe you could tweak the code for your needs:

call vimfiler#set_execute_file('doc', 'path/to/MS Word')
augroup vimfiler_mapping
    autocmd!
    autocmd FileType vimfiler nmap <buffer> x <Plug>(vimfiler_execute_vimfiler_associated)
augroup END

The autocmd installs a buffer-local mapping on the x key whenever you open a buffer whose filetype is vimfiler.
And as muru explained in the comment, the call to the function vimfiler#set_execute_file() appends a new item in the dictionary g:vimfiler_execute_file_list whose values are command names designated to open the files with the extension stored inside the associated keys.

For more information, see:

:help vimfiler#set_execute_file()
:help <Plug>(vimfiler_execute_vimfiler_associated)
:help g:vimfiler_execute_file_list
  • 2
    You should probably map to some other key instead of <cr> (maybe x?) , and vimfiler#set_execute_file appends to this dictionary, so perhaps the function call is more appropriate. – muru Feb 9 '16 at 8:35
  • @muru You are right, the call to the function is a better solution as it appends to the dictionary instead of overwriting it. I also changed the key to x. – saginaw Feb 9 '16 at 8:51
  • @muru Sorry I deleted it because I found yours much simpler and more efficient. I didn't realize there was already a built-in mapping for what the author of the question wanted. I've undeleted it now. – saginaw Feb 9 '16 at 9:23
  • 1
    Well, vimfiler_execute_system_associated serves a different purpose. With vimfiler_associated (which is what OP and you are interested in), you don't have to change settings which might affect other programs - the association is purely within Vim. With system_associated, a change in association affects other programs as well (and has to be done outside Vim). – muru Feb 9 '16 at 9:25

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.