Ⅰ. 插件描述
Turn lines into printf statementsⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'mptre/vim-printf'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'mptre/vim-printf'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'mptre/vim-printf'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/mptre/vim-printf
Ⅳ. 文档说明
# vim-printf
Turn a line consisting of tokens separated by commas into a printf statement.
A token is recognized as a sequence of any characters except for whitespace and
comma but with respect to balanced brackets and parentheses.
Installation
Use the package feature introduced in Vim 8.0 or do what you did for the other
plugins you have installed.
FAQ
How do I change the pattern for a filetype?
The pattern used,
specified by b:printf_pattern
,
can be altered for a given filetype.
Below is a list of sensible patterns for different filetypes.
If your favorite filetype is missing,
feel free to submit a pull request.
au FileType awk let b:printf_pattern = 'printf "%s\n", %s'
au FileType c let b:printf_pattern = 'printf("%%s: %d\n", __func__, %s);'
au FileType go let b:printf_pattern = 'fmt.Printf("%+v\n", %s)'
au FileType java let b:printf_pattern = 'System.out.format("%d%%n", %s);'
au FileType python let b:printf_pattern = 'print("%s" %% (%s))'
au FileType ruby let b:printf_pattern = 'printf("%p\n", %s)'
au FileType sh let b:printf_pattern = 'printf ''%s\n'' %s'
au FileType vim let b:printf_pattern = 'echom printf("%s", %s)'
See the [documentation] for further reference on how the pattern is interpreted.
How do I map the
:Printf
command to a key?
Add this to your vimrc and replace <Leader>p
with your desired key:
nnoremap <Leader>p :Printf<CR>
License
Copyright (c) 2018 Anton Lindqvist.
Distributed under the MIT license.