Skip to content
This repository was archived by the owner on Mar 5, 2020. It is now read-only.

Option g:minisnip_backreffirst #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion autoload/minisnip.vim
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ function! s:SelectPlaceholder() abort
let @s=substitute(@s, '\V' . g:minisnip_backrefmarker . '\(\d\)',
\"\\=\"'\" . substitute(get(
\ s:placeholder_texts,
\ len(s:placeholder_texts) - str2nr(submatch(1)), ''
\ g:minisnip_backreffirst ?
\ str2nr(submatch(1)) :
\ len(s:placeholder_texts) - str2nr(submatch(1)), ''
\), \"'\", \"''\", 'g') . \"'\"", 'g')
" evaluate what's left
let @s=eval(@s)
Expand Down
12 changes: 10 additions & 2 deletions doc/minisnip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ Default: '\\~'

When this is present, followed by a single digit `n`, in a placeholder that
also starts with |'g:minisnip_evalmarker'|, it will be replaced with the `n`th
to last previous placeholder value, surrounded by quotes. Here is an example
of how it can be used: >
placeholder value, according to |'g:minisnip_backreffirst'|, surrounded by
quotes. Here is an example of how it can be used: >
#ifndef {{+INCLUDE_GUARD+}}
#define {{+~\~1+}}

Expand All @@ -135,6 +135,14 @@ of how it can be used: >
This will automatically fill the `#define` line with the value entered on the
`#ifndef` line upon jumping to it.

-------------------------------------------------------------------------------
*'g:minisnip_backreffirst'*
Default: 0

If set to 0, backreferences will be replaced with the `n`th to last
placeholder value. If set to a non 0 value, the `n`th from first placeholder
will be used instead.

-------------------------------------------------------------------------------
*'g:minisnip_finalstartdelim'*
*'g:minisnip_finalenddelim'*
Expand Down
1 change: 1 addition & 0 deletions plugin/minisnip.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let g:minisnip_finalenddelim = get(g:, 'minisnip_finalenddelim', '-}}')
let g:minisnip_evalmarker = get(g:, 'minisnip_evalmarker', '~')
let g:minisnip_donotskipmarker = get(g:, 'minisnip_donotskipmarker', '`')
let g:minisnip_backrefmarker = get(g:, 'minisnip_backrefmarker', '\\~')
let g:minisnip_backreffirst = get(g:, 'minisnip_backreffirst', 0)

" this is the pattern used to find placeholders
let g:minisnip_delimpat = '\V' . g:minisnip_startdelim . '\.\{-}' . g:minisnip_enddelim
Expand Down
2 changes: 2 additions & 0 deletions syntax/minisnip.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ endif
" Get the minisnip defined delimiters
exe "syntax match minisnipKeyword /" . g:minisnip_startdelim . "/"
exe "syntax match minisnipKeyword /" . g:minisnip_enddelim . "/"
exe "syntax match minisnipKeyword /" . g:minisnip_finalstartdelim . "/"
exe "syntax match minisnipKeyword /" . g:minisnip_finalenddelim . "/"

highlight default link minisnipKeyword Keyword

Expand Down