LucHermitte / lh-cpp

C&C++ ftplugins suite for Vim
Other
130 stars 10 forks source link
brackets cpp snippets vim vim-plugins

lh-cpp Build Status Project Stats

Features

lh-cpp is an heterogeneous suite of helpers for C and C++ programming.

It provides the following things:

Text insertion facilities

Brackets

The insertion of pair of brackets-like characters is eased thanks to lh-brackets.

In mode INSERT VISUAL NORMAL
keys Expands into .. Surrounds the selection with ... 2 Surrounds the current ...
( (<cursor>)«» (<selection>) word
[ [<cursor>]«» 1 1
[ after a [ [[<cursor>]]«» n/a n/a
] before ]] close all ]] n/a n/a
<localleader>[ [<selection>] word
{ {<cursor>}«»3 {<selection>} word
<localleader>{ {\n<selection>\n}«» line
< <<cursor>>«» after #include, or template on the same line
" (1 double quote) "<cursor>"«» 1 1
"" "<selection>" word
' '<cursor>'«» 1 1
'' (2 single quotes) '<selection>' word
; closes all parenthesis after the cursor -- if there is nothing else
Notes:

Code snippets

INSERT-mode snippets abbreviations

There exist, over the WWW, a lot of configurations and mappings regarding C programming. Once again you will find shortcuts for if, else, elif (I know it is not a C keyword, but else if are), for, while, do, switch, and main. In C++, snippets are also provided for try, catch, and namespace. What is unique is the fact that when you type if in insert mode, it will automatically expand into ...

if () {
}

... in respect of the context. I.e.: within comments or strings (delimited by single or double quotes) if is not expanded. If keyword characters precede the typing, if is not expanded as well. Thus variables like tarif can be used without getting any headache.

Most of these same snippets, and a few variations, are also provided as template-files for mu-template. This time, you just need to type the first letters of the snippet/template name, and trigger the expansion (with <c-r><tab> by default). If several snippets match (like c/for, c/fori, cpp/fori and cpp/for-iterator when you try to expand fo), mu-template will ask you to choose which (matching) snippet you want to expand.

Instruction surrounding mappings

In visual mode, ,if wraps the selection within the curly brackets and inserts if () just before. In normal mode ,if does the same thing under the consideration that the selection is considered to be the current line under the cursor. Actually, it is not ,if but <LocalLeader>if, with maplocalleader assigned by default to the coma ,.

Expression-condition surrounding mappings

In the same idea, <LocalLeader><LocalLeader>if surrounds the selection with if ( and ) {\n«»\n}«».

Other notes

All the three mode oriented mappings respect and force the indentation regarding the current setting and what was typed.

More precisely, regarding the value of the buffer relative option b:usemarks (cf. lh-brackets), if could be expanded into:

if () {
    «»
}«»

The exact style (Alman, Stroustroup, ...) regarding whether brackets are on a new line, or not, can be tuned thanks to lh-dev :AddStyle feature.

Miscellaneous shortcuts

Note: in all the following mappings, , is actually the localleader that lh-cpp sets to the comma characcter if it isn't set already.

Templates

I'll try to maintain an up-to-date documentation of the snippets as most of them have options.

Wizards and other high-level features

Syntax highlighting

Miscellaneous

Installation

Credits

Many people have to be credited:

License

See also