QGU

Quantum Gravity Unitarity

0%

Visual Assist like keybindings for Vim

After developing in Visual Studio at work for a few years, I have been spoiled by the convenience of a few shortcuts to navigate around the code. When I get back to Vim at home, my muscle memory can't help to press the same key combinations. To help this situation a little bit, I have created to some of the commonly used shortcuts in Vim to map to the same functionality as Visual Assist. It works surprisingly good so far. Here are a set of key bindings I'll set up in this post:

Key Function
Shift-Alt-g Open a file
Shift-Alt-o Search for a symbol
Shift-Alt-f Search for all references
Alt-o Jump between headers and sources

TL;DR

1. Install Ctags and Cscope
2. Install CtrlP plugin for Vim
3. Generate tags in the root folder of the project
4. Generate Cscope database in the root folder of the project
5. Setup keybindings and Cscope auto load in vimrc ## Open Files with CtrlP
• Required plugin/executable: CtrlP

CtrlP is a great plugin to search files in folder, to use the keybinding, simply map the key combinations to invoke CtrlP command:

CtrlP works great with Ctags by invoking CtrlPTag. It works simply with another key mapping:

Note that tag file is needed to make it work properly, to generate tags file, simply run the ctags at the root folder of the :

Similarly to search for symbols, searching for symbols within the file can be done with CtrlPBufTag command, adding the following key mapping to vimrc:

Find all References with Cscope

• Required plugin/executable: Cscope

Generate Cscope database file

We'll need to generate a database file for Cscope with command cscope –Rb at the root folder of the project. It will generate cscope.out database that will be used later in Vim.

Using Cscope in Vim

Cscope is a built-in feature for Vim. After generating the Cscope database, we can add it to Vim with :cs add cscope.out. Now, the cscope should be good to go. To search for all the references of a symbol, simply type :cs find s [symbol]

Keybindings

Typing all the command with Cscope is too much work, a few keybindings has been provided by the Cscope tutorial, with the vim file provided, you can simply search the references with Ctrl+\ s with the symbol under the cursor.

Further optimization

Search result selection is far from optimal, we'll have to type the selection in command to jump to the specific item. It would be ideal to have something similar to Ctrl-P' s output selection