lh-cpp is an heterogeneous suite of helpers for C and C++ programming.
It provides the following things:
an API to build even more complex wizards and advanced features
An exhaustive list of all options is also available.
For help using this plugin for the first time, please take a look at :h lh-cpp-first-steps
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 |
<cr>
in the middle of a pair of curly-bracket will expand into {\n<cursor>\n}
.«»
represents a marker/placeholder, it may be expanded with other characters like <++>
depending on your preferences..vimrc
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.
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 ,
.
In the same idea, <LocalLeader><LocalLeader>if
surrounds the selection with if (
and ) {\n«»\n}«»
.
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.
Note: in all the following mappings, ,
is actually the localleader that
lh-cpp sets to the comma characcter if it isn't set already.
tpl
expands into template <<cursor>>«»
;<m-t>
inserts typedef
, or typename
depending on what is before the cursor ;<m-r>
inserts return
, and tries to correctly place the semicolon, and a placeholder, depending on what follows the cursor ;<c-x>be
, <c-x>rbe
replace (foo<cursor>)
with (foo.begin(),foo.end()<cursor>)
(or rbegin
/rend
) ;<c->se
: attempt to fill-in a switch-case
from an enumerated type ;,sc
| ,dc
| ,rc
| ,cc
| ,lc
surround the selection with ; static_cast<<cursor>>(<selection>)
, dynamic_cast
, reinterpret_cast
, const_cast
, or boost::lexical_cast
;,,sc
| ,,dc
| ,,rc
| ,,cc
try to convert the C-cast selected into the C++-cast requested ;#d
expands into #define
, #i
into #ifdef
, #e
into endif
, #n
into #include
;,0
surrounds the selected lines with #if 0 ... #endif
;,1
surrounds the selected lines with #if 0 ... #else ... #endif
;:KeepPoundIfPath 0
(or 1
) will clean a #if 0/1...#else...#endif
construct to match either the true or the false path.pub
expands into public:\n
, pro
expands into protected:\n
, pri
expands into private:\n
;vir
expands into virtual
;firend
is replaced by friend
;<m-s>
inserts std::
, <m-b>
inserts boost:
;?:
expands into <cursor>? «» : «»;
;<C-X>i
will look for the symbol under the cursor (or selected) in the current ctag database and it will try to automatically include the header file where the symbol is defined.<M-i>
will look for the symbol under the cursor (or selected) in the current ctag database and it will try to automatically prepend it with its missing complete scope.[[
and ][
and been overridden to jump to the start/end of the current
function -- the default mappings were defined in C in mind, and they are
unable of this. See the related v_if
and o_if
mappings from lh-dev -- see the demo.copy-constructor
,
default-constructor
,
destructor
,
assignment-operator
(see :h :Constructor
).(bg):cpp_std_flavour
, or
the analysis of $CXXFLAGS
, or through the analysis of CMake CXXFLAGS
variables (this will require
lh-cmake, and the project to be
configured to CMake.)I'll try to maintain an up-to-date documentation of the snippets as most of them have options.
<c-x>u
: shows the list of functions for which there is neither a declaration, nor a definition:Constructor
(that takes the following parameters: init
, default
, copy
, assign
), or :ConstructorInit
, :ConstructorDefault
, :ConstructorCopy
, AssignmentOperator
. They'll analyse the list of know attributes (from a ctags database) to generate the related construction functions.<home>
and <end>
to mimic how these keys behave in VC++.,i
and ,a
to select the current parameter (in a list of parameters).:NameConvert
that permits to change
the naming style of a symbol. The possible styles are: upper_camel_case
,
lower_camel_case
, snake
/underscore
, variable
, local
, global
,
member
, constant
, static
, param
, getter
, setter
)ActivateAddons lh-cpp
flavor 'LucHermitte/lh-cpp'
git clone git@github.com:LucHermitte/lh-vim-lib.git
git clone git@github.com:LucHermitte/lh-style.git
git clone git@github.com:LucHermitte/lh-tags.git
git clone git@github.com:LucHermitte/lh-dev.git
git clone git@github.com:LucHermitte/lh-brackets.git
git clone git@github.com:LucHermitte/searchInRuntime.git
git clone git@github.com:LucHermitte/mu-template.git
git clone git@github.com:tomtom/stakeholders_vim.git
git clone git@github.com:LucHermitte/alternate-lite.git
git clone git@github.com:LucHermitte/lh-cpp.git
Bundle 'LucHermitte/lh-vim-lib'
Bundle 'LucHermitte/lh-style'
Bundle 'LucHermitte/lh-tags'
Bundle 'LucHermitte/lh-dev'
Bundle 'LucHermitte/lh-brackets'
Bundle 'LucHermitte/searchInRuntime'
Bundle 'LucHermitte/mu-template'
Bundle 'tomtom/stakeholders_vim'
Bundle 'LucHermitte/alternate-lite'
Bundle 'LucHermitte/lh-cpp'
Many people have to be credited:
class
,
singleton
, enum
(1&2, switch, for), abs-rel
-> is under Boost
Software Licence