default_brackets.md

January 15, 2021 · View on GitHub

Default bracket mappings

By default, lh-brackets comes with a few ready-to-use mappings:

The default mappings can be inhibited with the options (bpg):cb_no_default_brackets, g:cb_enable_default and g:cb_disable_default. See :h :Brackets-default.

Global mappings

The following mappings apply to all filetypes (unless specified otherwise, or specialized).

in modeinsertvisualnormal
keysexpands into ..surrounds the selection with ... 2surrounds the current ...
((<cursor>)«»(<selection>)word
[[<cursor>]«»11
<leader>[[<selection>]word
{{<cursor>}«»3{<selection>}word
<leader>{{\n<selection>\n}«»line
" (1 double quote)"<cursor>"«»11
"""<selection>"word
''<cursor>'«»411
'' (2 single quotes)'<selection>'word
<leader><<<selection>>word

Notes:

  • 1 Not defined to avoid hijacking default vim key bindings.
  • 2 The visual mode mappings do not surround the current marker/placeholder selected, but trigger the INSERT-mode mappings instead.
  • 3 No newline is inserted by default. However, hitting <cr> in the middle of a pair of curly-brackets will expand into {\n<cursor>\n}.
  • 4 This mapping is neutralized for text filetypes -- the list of text-filetypes is defined in lh#ft#is_text()
  • «» represents a marker/placeholder, it may be expanded with other characters like <++> depending on your preferences.
  • These mappings can be disabled from the .vimrc by setting g:cb_no_default_brackets to 1 (default: 0)

C and C++ mappings

See lh-cpp documentation for the complete mappings table.

The main differences from the global table are:

  • } jumps to the next non whitespace/newline character that is a } if g:cb_jump_over_newlines equals to 1 (default case). If you want to jump after the } only if it's exactly right after the cursor, then set g:cb_jump_over_newlines to 0 in your .vimrc. See #26. When not jumping, } is simply inserted.

  • In visual mode, <localleader>{ surrounds the selection with a pair of curly brackets (and newlines are introduced).

  • <tt> is recognized as an opening bracket (I use it a lot to write Doxygen code instead of \c when I need to type several things).

  • ; will try to close parenthesis -- set (bpg):[{ft}_]semicolon_closes_bracket to 0 to inhibit this setting.

  • <bs> take care of semi-colons after the closing curly-bracket -- set (bpg):[{ft}_]semicolon_closes_bracket to 0 to inhibit this setting.

in modeinsert
keysexpands into ..
< after #include, template, typename, _cast or standard types<<cursor>>;
{ after struct, class, enum or union{<cursor>};
[ after a [[[<cursor>]]«»
] before ]]close all ]]

Notes

  • For < to expand into <|> after standard types like std::vector, lh-cpp v2.2.1+ is required

HTML mappings

The main differences from the global table are:

  • Typing < twice results in &lt;, and <> results in &gt;.
  • In visual mode, <localleader>< surrounds the selection with a pair of angle brackets.

Javascript mappings

The main differences from the global table are:

  • In visual mode, <localleader>{ surrounds the selection with a pair of curly brackets (and newlines are introduced).

Markdown mappings

New mappings are avaible.

in modeinsertvisualnormal
keysexpands into ..surrounds the selection with ... 2surrounds the current ...
__<cursor>_<++> 3_<selection>_word
_ after a ___<cursor>__<++>n/an/a
**<cursor>*<++> 3,4*<selection>*word
* after a ***<cursor>**<++>n/an/a
` `<cursor>`<++> 5`<selection>`word
~<del><cursor></del>«»11
<localleader>~<del><cursor></del>word

Notes:

  • 1 Not defined to avoid hijacking default vim key bindings.
  • 2 The visual mode mappings do not surround the current marker/placeholder selected, but trigger the INSERT-mode mappings instead.
  • 3 Within a pair of backquotes (code marker), formatting pairs are not expanded
  • 4 Right after spaces at the beginning of the line, * is not expanded: it will serve to start a new point in a bullet-list.
  • 5 When type after a dollar sign, backtick will get expanded into $`<cursor>`$<++>, and $ will move the cursor and consume any placeholder if typed between and backtick and an existing dollar.

Perl mappings

The main differences from the global table are:

  • In visual mode, <localleader>{ surrounds the selection with a pair of curly brackets (and newlines are introduced).
  • In visual mode, <localleader>< surrounds the selection with a pair of angle brackets.

Ruby mappings

  • In normal mode, <C-X>{ replace begin-end block by {-}, or the other way around.

(La)TeX mappings

New and specialized mappings are avaible.

in modeinsertvisualnormal
keysexpands into ..surrounds the selection with ... 2surrounds the current ...
((<cursor>)<++>(<selection>)word
( after a \\(<cursor>\)<++>n/an/a
{{<cursor>}<++>{<selection>}word
{ after a \\{<cursor>\}<++>n/an/a
[[<cursor>]<++>[<selection>]word
[ after a \\[<cursor>\]<++>n/an/a
<leader>[[<selection>]word
$$<cursor>$<++>11
<leader>$$<selection>$word

Notes:

  • 1 Not defined to avoid hijacking default vim key bindings.
  • 2 The visual mode mappings do not surround the current marker/placeholder selected, but trigger the INSERT-mode mappings instead.
  • In (La)TeX, <++> is used as a placeholder instead of «».

VimL mappings

New and specialized mappings are avaible.

in modeinsertvisualnormal
keysexpands into ..surrounds the selection with ... 2surrounds the current ...
((<cursor>)«»(<selection>)word
( after a \\(<cursor>\)«»n/an/a
<<<cursor>>«» 511
<leader><<<selection>>word
""<cursor>"«» 611

Notes:

  • 1 Not defined to avoid hijacking default vim key bindings.
  • 2 The visual mode mappings do not surround the current marker/placeholder selected, but trigger the INSERT-mode mappings instead.
  • 5 except after an if, a while, or within comments. Still this rule knowns an exception: within a string, or after a \, < is always converted to <>. Does not handle special characters like '< and '>
  • 6 except for comments, and special attention is given when the cursor is within strings