SmartCase


Ⅰ. 插件描述

replacing words while keeping original lower/uppercase style

Ⅱ. 基本信息

创建日期:  2005-09-20
使用用户:  6
Github星:  1
插件作者:  Yuheng Xie

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin '/smartcase'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle '/smartcase'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug '/smartcase'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/vim-scripts/SmartCase

Ⅳ. 文档说明

An example, you may want to replace any FileSize appears in your program into LastModifiedTime. Since it appears everywhere as both uppercases and lowercases, you have to write it several times:

  :%s/FileSize/LastModifiedTime/g      " function names
  :%s/file_size/last_modified_time/g   " variable names
  :%s/FILE_SIZE/LAST_MODIFIED_TIME/g   " macros
  :%s/File size/Last modified time/g   " document/comments
  ......

This script copes with the case style for you so that you need write just one command:

  :%s/fileA?size/=SmartCase("LastModifiedTime")/ig

An alternative way:
  first search for the string:  /cfileA?size
  then run a command:  :%SmartCase "LastModifiedTime"

By the way, SmartCase can also cope with the circumstance where you want to replace the string's case style while keeping its words. For example:
  FileSize => file_size
  LastModifiedTime => last_modified_time
  ......
This can be done with the following command:

  :%s/(ul+){2,}/=SmartCase(0,"reference_style")/g

To sum up: the first argument to SmartCase is the reference words, the secend argument is the reference styles, if the second argument omitted, it's submatch(0).

添加新评论