Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于使用%<加文件扩展名出错 #1

Closed
hongyuanjia opened this issue Sep 15, 2016 · 5 comments
Closed

关于使用%<加文件扩展名出错 #1

hongyuanjia opened this issue Sep 15, 2016 · 5 comments

Comments

@hongyuanjia
Copy link

你好!AsyncRun非常好用!!点赞!之前我一直都是用VimShell,感觉速度上还是不够快,虽然也可以异步进行。
我主要用Vim来写Markdown,然后用Pandoc来转换成为Tex或直接输出PDF。我在_vimrc中加入了

nnoremap <silent> <Leader>ppd :AsyncRun pandoc --output %<.pdf %:p <CR>

但是由于在%<后面出现了.pdf,AsyncRun就会直接认为是%<.pdf这一个文本。请问如何才能解决这个问题?谢谢

@skywind3000
Copy link
Owner

skywind3000 commented Sep 15, 2016

你好,由于解析的时候我将会空格分割的参数看成一个整体来解析,没法在一个字符串中替换包含的部分,否则有歧义,比如:
%:p 可能是 %:p 单独,也可能是%和:p,这样就没法解析了。

你可以写成个函数,来解决这个问题:

function! GeneratePdf()
    exec ":AsyncRun pandoc --output " . fnameescape(expand('%<')) . ".pdf %:p"
endfunc

noremap <silent> <leader>ppd :call GeneratePdf()<cr>

如此即可,或者你也可以写成个批处理文件,里面用 $VIM_FILENAME 等宏来实现转换,然后用
AsyncRun 来调用。

@skywind3000
Copy link
Owner

skywind3000 commented Sep 15, 2016

更新了一个版本,现在参数同样接受下面这些变量:

$VIM_FILEPATH  - File name of current buffer with full path
$VIM_FILENAME  - File name of current buffer without path
$VIM_FILEDIR   - Full path of current buffer without the file name
$VIM_FILEEXT   - File extension of current buffer
$VIM_FILENOEXT - File name of current buffer without path and extension
$VIM_CWD       - Current directory
$VIM_RELDIR    - File path relativize to current directory
$VIM_RELNAME   - File name relativize to current directory 
$VIM_CWORD     - Current word under cursor
$VIM_CFILE     - Current filename under cursor
$VIM_GUI       - Is running under gui ?
$VIM_VERSION   - Value of v:version
$VIM_COLUMNS   - How many columns in vim's screen
$VIM_LINES     - How many lines in vim's screen

只是使用的时候,要用 $(...) 把他们包裹起来,这样就不会出现歧义了,那么使用最新版,针对你的问题,直接把 %< 换成 $(VIM_FILENOEXT) 即可:

nnoremap <silent> <Leader>ppd :AsyncRun pandoc --output $(VIM_FILENOEXT).pdf %:p <CR>

@hongyuanjia
Copy link
Author

感谢!已经可以使用啦!

@skywind3000
Copy link
Owner

嗯,觉得好用请帮投个票:
http://www.vim.org/scripts/script.php?script_id=5431

@hongyuanjia
Copy link
Author

必须的!已经投啦!“Life-Changing“!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants