Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

Klocwork Refactoring in Vim

Klocwork Refactoring in Vim

The C/C++ Klocwork Refactoring plug-in for Vim is part of the Command Line tools desktop analysis package. See Installing Klocwork for details on installing a desktop analysis plug-in.

Note: These instructions assume that you have already set up a Klocwork project as described in Getting started with kwcheck for C/C++.
Note: The VIM refactoring plug-in no longer performs rename refactoring.

Installing the refactoring plug-in for Vim

Note: The C/C++ refactoring plug-in for Vim supports Vim 7.2 and later.

Copy the following file: <install path>Klocwork <Version> Command Line/plugins/kwrefactor.vim

to one of the following locations:

  • (Unix) $HOME/.vim/plugin
  • (Windows) $HOME\vimfiles\plugin

where $HOME is the home directory being used by Vim. Note that you may need to create the \vimfiles\plugin directory under your Vim home directory.

Tip: You can find your home directory with this Vim command:
:echo $HOME

Setting up your environment

The refactoring plug-in needs to know where the Klocwork Command Line tools are installed, as well as where the build specification is located. The build specification stores build settings for your project. The plug-in saves this information after each Vim session.

If no build specification has been saved in a previous session, or the saved build specification is incorrect, then the refactoring plug-in will search:

  1. in the current directory for.kwlp/buildspec.txt
  2. in the current directory forkwinject.out

If no build specification is found, the refactoring plug-in goes one directory up and continues from point 1.

Specifying the path to the Command Line tools installation

Use the following command to manually specify the path to the Klocwork Command Line tools installation:

:SetKwHome <command_line_tools_install>

Specifying the path to the build specification

Use the following command to manually specify the location of the Klocwork build specification:

:SetKwSpec <build_specification_file>

Using the refactoring plug-in

Just start a new Vim session, place your cursor or select some code, and apply the appropriate refactoring.

In Vim, use these hot-keys:

Command Hot-key
Help Ctrl+k, h
Extract Function Ctrl+k, xf
Inline Function Ctrl+k, if
Inline Variable Ctrl+k, iv
Introduce Variable Ctrl+k, nv
Optimize Headers Ctrl+k, oh
Rename Ctrl+k, r
Tip: If you're lucky enough to be using gVim, try the right-click and Klocwork menus.

See Klocwork Refactoring for specific examples.