lh-brackets (ex- map-tool) provides various commands and functions to help design smart and advanced mappings dedicated to text insertion.
It is made of three sub-systems:
This subsystem provides a command that helps define INSERT-, NORMAL-, and VISUAL-mode mappings to insert any pairs of brackets-like characters.
<BS>
is hit from within the brackets (following placeholders will also be deleted) (this can be disabled by setting [gb]:cb_delete_empty_brackets
to 0)<CR>
is hit within an empty pair of curly-brackets {} (this can be disabled by setting [gb]:cb_newline_within_empty_brackets
to 0)-nl
) option), and then surround this selection with the pair of bracket-like characters.It is possible to:
-open
and -close
options),b:usemark
value),-trigger
option),-insert
, -visual
, and also -normal
)-nl
option),-normal
option),<F9>
(:h <Plug>ToggleBrackets
) ;:Brackets!
, or local to a buffer with :Brackets
. ;-but
option-pair
option)Here is an excerpt from the C&C++ brackets definitions, see the documentation for more help.
let b:usemarks = 1
let b:cb_jump_on_close = 1
:Brackets { } -visual=0 -nl
:Brackets { } -visual=0 -trigger=#{
:Brackets { } -visual=1 -insert=0 -nl -trigger=<localleader>{
:Brackets { } -visual=1 -insert=0
:Brackets ( )
:Brackets [ ] -visual=0
:Brackets [ ] -insert=0 -trigger=<localleader>[
:Brackets " " -visual=0 -insert=1 -escapable
:Brackets " " -visual=1 -insert=0 -trigger=""
:Brackets ' ' -visual=0 -insert=1
:Brackets ' ' -visual=1 -insert=0 -trigger=''
:Brackets < > -open=function('lh#cpp#brackets#lt') -visual=0
Note: This feature has been completely rewritten for the version 1.0.0 of map-tools. The old way of tuning the brackets insertion is no longer available.
By default, the mappings are active for most filetypes.
lh-brackets provides mappings (originally from auctex.vim) to replace a pair of bracket-characters by another pair of bracket-characters. See :h brackets_manipulations
for more information.
This subsystem provides functions and mappings to:
!mark!
, lh#marker#txt()
, and <Plug>MarkersMark
!jump!
, and <Plug>MarkersJumpF
<Plug>MarkersCloseAllAndJumpToLast
which is binded by default to <M-End>
(or <C-L>$
in terminal instancef of Vim).The marker/placeholder characters:
:h g:use_place_holders
).Jumping to the next/previous placeholder:
<M-Del>
(GUI) or <C-J>
(terminal) by default (see :h <Plug>MarkersJumpF
), or <M-S-Del>
/<C-L><S-Del>
to jump backward. Can be disabled by setting g:marker_define_jump_mappings
to 0.:h g:marker_prefers_select
, :h g:marker_select_empty_marks
),:h g:marker_select_current
, :h g:marker_select_current_fwd
),:h g:marker_center
),'wrapscan'
,As lh-vim-lib, map-tools provides a few functions of its own. All these functions are specialized into the definition of smart abbreviations and INSERT-mode mappings.
Function | Purpose |
---|---|
lh#map#no_context() , lh#map#no_context2() |
Core functions to define mappings that only expand outside of string, comment, and character contexts |
lh#map#4_these_contexts() |
Like lh#map#no_context() , except this time we can specify which text must be returned depending on the current context |
lh#map#insert_around_visual() |
This is the core surrounding function ; the surrounding text is not interpreted |
lh#map#surround() |
Interprets the !.*! mappings that are passed to lh#map#insert_around_visual() (!cursorhere! tells were to put the cursor). This function also recognises when the selected area is actually a marker/placeholder in order to not surround, but expand instead. |
lh#map#build_map_seq() |
Core function that interprets !.*! mappings |
lh#map#eat_char() , :I(nore)abbr |
Permits to define abbreviations that do not insert a whitespace when the <space> key is used to trigger the abbreviation |
lh#map#insert_seq() |
High level function that interprets !.*! mappings, and take the context into account |
Requirements: Vim 7.+ (7.4-849 in order to support redo), lh-vim-lib v5.3.0+, lh-style v1.0.0+ for unit testing.
With vim-addon-manager, install lh-brackets (this is the preferred method because of the dependencies)
ActivateAddons lh-brackets
or with vim-flavor (which also support dependencies)
flavor 'LucHermitte/lh-brackets'
or you can clone the git repositories
git clone git@github.com:LucHermitte/lh-vim-lib.git
git clone git@github.com:LucHermitte/lh-brackets.git
or with Vundle/NeoBundle:
Bundle 'LucHermitte/lh-vim-lib'
Bundle 'LucHermitte/lh-brackets'