Fixed vim and zsh
This commit is contained in:
1875
vim/plugins/ultisnips/doc/UltiSnips.txt
Normal file
1875
vim/plugins/ultisnips/doc/UltiSnips.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
vim/plugins/ultisnips/doc/demo.gif
Normal file
BIN
vim/plugins/ultisnips/doc/demo.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 MiB |
@ -0,0 +1,68 @@
|
||||
# Autojump from tabstop when it's empty
|
||||
|
||||
UltiSnips offers enough API to support automatic jump from one tabstop to
|
||||
another when some condition is encountered.
|
||||
|
||||
One example of applying that behaviour is jump on the next placeholder when
|
||||
current becomes empty when user types `<BS>` or another erase sequence when
|
||||
tabstop is active.
|
||||
|
||||
Let's imagine, that we have following snippet:
|
||||
|
||||

|
||||
|
||||
First placeholder, surrounded by braces, can be erased by user, but then
|
||||
surrounding quotes will left untouched, and user should remove quotes and
|
||||
one space, and only then jump to next placeholder, that equals to **5** total
|
||||
keypresses: <kbd>BackSpace</kbd> (erase placeholder), <kbd>BackSpace</kbd> and
|
||||
<kbd>Delete</kbd> (erase braces), <kbd>Delete</kbd> (erase space),
|
||||
<kbd>Ctrl+J</kbd> (jump to next placeholder).
|
||||
|
||||
However, with UltiSnips, it can be done via only one keypress:
|
||||
<kbd>BackSpace</kbd>:
|
||||
|
||||

|
||||
|
||||
## Implementation
|
||||
|
||||
Using awesome [vim-pythonx
|
||||
library](https://github.com/reconquest/vim-pythonx/blob/master/pythonx/px/snippets.py),
|
||||
which provides set of functions to make coding little bit easier.
|
||||
|
||||
```
|
||||
global !p
|
||||
import px.snippets
|
||||
endglobal
|
||||
|
||||
global !p
|
||||
# This function will jump to next placeholder when first is empty.
|
||||
def jump_to_second_when_first_is_empty(snip):
|
||||
if px.snippets.get_jumper_position(snip) == 1:
|
||||
if not px.snippets.get_jumper_text(snip):
|
||||
px.snippets.advance_jumper(snip)
|
||||
|
||||
# This function will clean up first placeholder when this is empty.
|
||||
def clean_first_placeholder(snip):
|
||||
# Jumper is a helper for performing jumps in UltiSnips.
|
||||
px.snippets.make_jumper(snip)
|
||||
|
||||
if snip.tabstop == 2:
|
||||
line = snip.buffer[snip.cursor[0]]
|
||||
snip.buffer[snip.cursor[0]] = \
|
||||
line[:snip.tabstops[1].start[1]-2] + \
|
||||
line[snip.tabstops[1].end[1]+1:]
|
||||
snip.cursor.set(
|
||||
snip.cursor[0],
|
||||
snip.cursor[1] - 3,
|
||||
)
|
||||
endglobal
|
||||
|
||||
context "px.snippets.make_context(snip)"
|
||||
post_jump "clean_first_placeholder(snip)"
|
||||
snippet x "Description" b
|
||||
`!p jump_to_second_when_first_is_empty(snip)
|
||||
`func (${1:blah}) $2() {
|
||||
$3
|
||||
}
|
||||
endsnippet
|
||||
```
|
BIN
vim/plugins/ultisnips/doc/examples/autojump-if-empty/demo.gif
Normal file
BIN
vim/plugins/ultisnips/doc/examples/autojump-if-empty/demo.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 97 KiB |
BIN
vim/plugins/ultisnips/doc/examples/autojump-if-empty/snippet.gif
Normal file
BIN
vim/plugins/ultisnips/doc/examples/autojump-if-empty/snippet.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 223 KiB |
@ -0,0 +1,52 @@
|
||||
# Aliases for snippets
|
||||
|
||||

|
||||
|
||||
Let's imagine we're editing shell file and we need to debug some vars.
|
||||
|
||||
Essentially, we will end up with snippet like that, that will automatically
|
||||
insert location of the debug statement and variable name.
|
||||
|
||||
Example of that snippet is shown below:
|
||||
|
||||
```
|
||||
snippet pr "print debug" bw
|
||||
`!p
|
||||
prefix = t[1] + ": %q\\n' "
|
||||
prefix = "{}:{}: {}".format(
|
||||
os.path.basename(px.buffer.get().name),
|
||||
str(px.cursor.get()[0]),
|
||||
prefix
|
||||
)
|
||||
`printf 'XXXXXX `!p snip.rv=prefix`$1 >&2
|
||||
endsnippet
|
||||
```
|
||||
|
||||
Now, we want to use same debug snippet, but dump variable to the file.
|
||||
How can we do it?
|
||||
|
||||
Simple, declare new snippet in that way:
|
||||
|
||||
```
|
||||
post_jump "px.snippets.expand(snip)"
|
||||
snippet pd "Description" b
|
||||
pr$1 >${2:/tmp/debug}
|
||||
endsnippet
|
||||
```
|
||||
|
||||
This snippet will expand `pr` snippet automatically (note `pr$1` part) after
|
||||
jumping to the first placeholder (jump will be done automatically by UltiSnips
|
||||
engine).
|
||||
|
||||
`px.snippets.expand(snip)` is declared in that way:
|
||||
|
||||
```python
|
||||
def expand(snip, jump_pos=1):
|
||||
if snip.tabstop != jump_pos:
|
||||
return
|
||||
|
||||
vim.eval('feedkeys("\<C-R>=UltiSnips#ExpandSnippet()\<CR>")')
|
||||
```
|
||||
|
||||
`px.buffer.get()` and `px.cursor.get()` are simple helpers for the
|
||||
`vim.current.window.buffer` and `vim.current.window.cursor`.
|
BIN
vim/plugins/ultisnips/doc/examples/snippets-aliasing/demo.gif
Normal file
BIN
vim/plugins/ultisnips/doc/examples/snippets-aliasing/demo.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 MiB |
@ -0,0 +1,50 @@
|
||||
# Dynamic tabstop generation
|
||||
|
||||

|
||||
|
||||
UltiSnips at the present day is more than snippet engine. It's more like
|
||||
constructor, where you can implement some complex features without prior
|
||||
feature implementation in the snippet by itself.
|
||||
|
||||
One of that features is dynamic tabstop generation.
|
||||
|
||||
Consider case, where you want set of snippets for inserting latex rows of
|
||||
various lengths. No-brainer solution is just implement snippet for every
|
||||
row length you're possible will want, like this:
|
||||
|
||||
```
|
||||
snippet tr9 "LaTeX table row of length nine"
|
||||
$1 & $2 & $3 & $4 & $5 & $6 & $7 & $8 & $9
|
||||
endsnippet
|
||||
```
|
||||
|
||||
But soon it becomes a burden to maintain that kind of snippets.
|
||||
|
||||
Gladly, tabstops can be generated by using anonymous snippet expansion:
|
||||
|
||||
```
|
||||
global !p
|
||||
def create_row_placeholders(snip):
|
||||
# retrieving singlee line from current string and treat it like tabstops
|
||||
# count
|
||||
placeholders_amount = int(snip.buffer[snip.line].strip())
|
||||
|
||||
# erase current line
|
||||
snip.buffer[snip.line] = ''
|
||||
|
||||
# create anonymous snippet with expected content and number of tabstops
|
||||
anon_snippet_body = ' & '.join(['$' + str(i+1)
|
||||
for i in range(placeholders_amount)])
|
||||
|
||||
# expand anonymous snippet
|
||||
snip.expand_anon(anon_snippet_body)
|
||||
endglobal
|
||||
|
||||
post_jump "create_row_placeholders(snip)"
|
||||
snippet "tr(\d+)" "latex table row variable" br
|
||||
`!p snip.rv = match.group(1)`
|
||||
endsnippet
|
||||
```
|
||||
|
||||
Snippet is declared via regular expression and will expand to any required
|
||||
number of fields in row.
|
BIN
vim/plugins/ultisnips/doc/examples/tabstop-generation/demo.gif
Normal file
BIN
vim/plugins/ultisnips/doc/examples/tabstop-generation/demo.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
Reference in New Issue
Block a user