tmsvg / pear-tree Goto Github PK
View Code? Open in Web Editor NEWA Vim auto-pair plugin that supports multi-character pairs, intelligent matching, and more
License: MIT License
A Vim auto-pair plugin that supports multi-character pairs, intelligent matching, and more
License: MIT License
The readme says:
If you would like to pair, say, /* with */ or , it works just as well.
However, if I type either /*
or <!--
, nothing is inserted after it. Pairing other things, like (
, {
, "
, etc work as expected. I am using Vim 8.1.
Example (with | as cursor position):
"foo.|
Then inserting "
results in:
"foo."|"
pear-tree doesn't recognize, that this double quote is intented to close the previous one. An automatically closed double quote directly after a punctuation character most often is not what you want.
Possible solutions:
Otherwise an excellent plugin. Thank you very much.
Regards
At the moment, pear-tree makes writing VimL really annoying — it tries to pair the initial quote of a Vim comment. Some sort of heuristic may be a good plan here!
Consider an example: Insert mode, cursor is at |
...other party is focused on a single issue (usually bEV|)
^
After pressing Esc, it would be handy to have:
...other party is focused on a single issue (usually bEV)|
^
Or, maybe even attempt telepathy and add space that is likely to follow:
...other party is focused on a single issue (usually bEV) |
^
What do you think?
It would be really cool if pear-tree inserted spaces like auto-pairs does.
Example from jiangmiao/auto-pairs:
Insert spaces before closing characters, only for [], (), {}
input: {|} (press <SPACE> at |) output: { | } input: {|} (press <SPACE>foo} at |) output: { foo }| input: '|' (press <SPACE> at |) output: ' |'
I use a lot of C++ and I do not want bracket completion for angular brackets, namely '<' and '>'. Is there any way to disable this? I couldn't find any.
Thanks in advance.
I ran into issues when configuring comment pairs for Haskell. Overlapping pairs were handled strangely.
Configuration:
let g:pear_tree_pairs = {
\ '{': {'closer': '}'},
\ '{-': {'closer': '-}'},
\ '{-#': {'closer': '#-}'}
\ }
Expected behavior:
input: {
output: {|}
input: {|}
(press - at |)
output: {-|-}
input: {-|-}
(press # at |)
output: {-#|#-}
Actual behavior:
input: {
output: {|}
input: {|}
(press - at |)
output: {-|-}
input: {-|-}
(press # at |)
output: {-#|#-}-}
When inside quotes, entering {
does not trigger the closer }
.
Expected:
"|"
"{|}"
Actual:
"|"
"{|"
Hi,
I frequently encounter this errors:
Error detected while processing function pear_tree#insert_mode#OnInsertCharPre[1]..<SNR>201_CorrectTraverser:
line 2:
E121: Undefined variable: b:traverser
Error detected while processing function pear_tree#insert_mode#OnInsertCharPre[1]..<SNR>201_CorrectTraverser:
line 2:
E121: Undefined variable: b:traverser
Error detected while processing function pear_tree#insert_mode#OnInsertCharPre[1]..<SNR>201_CorrectTraverser:
line 2:
E121: Undefined variable: b:traverser
Error detected while processing function pear_tree#insert_mode#OnInsertCharPre[1]..<SNR>201_CorrectTraverser:
line 2:
E121: Undefined variable: b:traverser
Error detected while processing function pear_tree#insert_mode#OnInsertCharPre[1]..<SNR>201_CorrectTraverser:
line 2:
E121: Undefined variable: b:traverser
Unfortunately I cannot consistently reproduce this error. It seems to me that the variable creation is delayed, because if I exit and reenter INSERT mode, the variable b:traverser
is defined.
let b:pear_tree_pairs = {
\ '(': {'closer': ')'},
\ '[': {'closer': ']'},
\ '{': {'closer': '}'},
\ "``": {'closer': "''"},
\ '$': {'closer': '$'}
\ }
Pear-tree is able to successfully enter the matching pair, but imap <C-l> <Plug>(PearTreeJump)
does not work with the dollar sign.
Background info: Used for LaTeX equations
Like the title says: other plugin that uses CR key (for ex: vim-clap
) is broken if used together with pear-tree
, somehow pear-tree
will intercept it first and doesn't bubble
it further downstream.
Error detected while processing function pear_tree#insert_mode#TerminateOpener[10]..pear_tree#insert_mode#CloseSimpleOpener[1]..129_ShouldCloseSimpleOpener:
line 23:
E712: Argument of count() must be a List or Dictionary
I just installed this to try it, this is the default behavior I'm getting trying to type any type of opener ( e.g.
{, [, etc) inside a quote.
Seemingly I should be able to do this by default without error, and then configure as needed for higher orders in the future, what do I do here?
Hi,
I added '<*>': {'closer': ‘</*>’, ‘not_if’: [‘br’, …]}
to g:pear_tree_pairs
to enable auto-close for HTML tags, and it worked fine.
But I noticed, in JSX, there are tags that can take both form <Foo></Foo>
and <Foo />
, so that I can not simply add Foo
to not_if
condition.
I thought it would be nice to disable auto-closing when an opener ends with />
. But I could not find a way to configure such a condition.
Could you tell me whether there is a way to achieve the above condition?
Anyway, thank you for publishing such a great plugin! I think this is the most sophisticated auto-close plugin.
e.g. pressing (
would insert )
only after pressing any other key
I want to mention that this is the first module that does auto-pairing right. I've been using and searching for a good auto-pairing plugin for ~5 years and I discovered this one last week. Before this module I used auto-pairs which is the most popular one, looking at the amount of starts, but I do think this module is definitely underrated. The logic of closing is exactly what I have been looking for and finally somebody did it right! Thanks again for this module and I really want to contribute to the module! Is there a global list of TODOs that has to be done or do you also have plannings for the feature? Maybe I could help out n_n
Something different: I did found a scenario that might not have been noticed by people yet, but when I have this scenario in HTML (where |
indicates the cursor):
<div class="|>
I do expect the result to be:
<div class="|">
Do you think this is fixable at core level? I really hope so. I know this doesn't work right now as expected because pear-tree doesn't insert when typing something when there are characters on the right of cursor.
I really was about to give up on Auto Pairing - tried quite a few but up to now all in my way more than helpful, guess I was 'holding it wrong'.
Yours is doing it right pretty much all the time, such an amazing experience!
Thanks again!
For example, in C++, we need a semicolon at the end of every line, so if I call the function Foo with parameter 24, by using this plugin, I will have:
Foo(24|)
Notice '|' is where the cursor is, and I want to move it after ')' so that I can add ';'.
An option to toggle this would be handy: cb1185d
Hello, I'm new to all this, but the auto-completed closing bracket disappears if I press enter while the cursor is in between the brackets. Is this supposed to happen, and how do I prevent it?
Not sure, whether this is a duplicate of #33, but this completely reliably breaks automatic switch on of :Educate
from vim-textobj-quote (see preservim/vim-textobj-quote#20).
I'm trying to configure pear-tree to use a <*>
opener with .tsx
files, so I need to support JSX tags as well as Typescript notation.
In particular, I need to support typescript generics, so something like below should not be expanded:
useHook<AppState>( ...someArgs)
And something like below should be expanded:
return <div></div>
Currently my setting looks like:
let g:pear_tree_pairs = {
\ '<*>': { 'closer': '</*>',
\ 'not_if': ['br', 'hr', 'img', 'input', 'link', 'meta',
\ 'area', 'base', 'col', 'command', 'embed',
\ 'keygen', 'param', 'source', 'track', 'wbr'],
\ 'not_like': '{[^}]*$\|/$',
\ 'until': '[^a-zA-Z0-9-._]',
\ 'not_at': ['[^> ]<[^>]*'],
\ 'not_in': ['String']
\ }
\ }
I'm using 'not_at': ['[^> ]<[^>]*']
to detect whether the tag fits in the right place - basically searching for whether the opener is preceded by a non-space or angle bracket. However, this doesn't work when typing something like test<T>
because at l:text_before_opener
is determined by length of opener.
Does it make sense to have this be determined by the full match?
Using <Plug>(PearTreeSpace)
often leads to the cursor being one space away from the closing string. It would be good if <Plug>(PearTreeJump)
ignored this space and just moved past the closing string:
{% foo| %}
-> {% foo %}|
I got an error when writing JSdoc for javascript.jsx filetype.
so when I type the second *
in /**
, this error happened.
Error detected while processing function pear_tree#insert_mode#TerminateOpener[36]..pear_tree#GetRule:
line 2:
E712: Argument of get() must be a List or Dictionary
Javascript has the concept of template literals that let you run functions on backtick strings before the argument and literals are joined. This is a popular pattern, especially with libraries like Styled Components.
pear-tree fails to detect the initial backtick as opening the string (presumably because it's attached to the word to the left). For example:
const Row = styled.div`
display: flex;
`
In this case, the initial backtick attached to the div
wouldn't generate the matching pair. Also, when manually typing the closing backtick, pear-tree detects it as the start of an expression and generates a second backtick on the third line.
Would it be possible to support this functionality?
Thanks!
Fantastic plugin!
Just wondering whether it's possible to make it work with hyphenated tags? At the moment the plugin only uses the text before the first hyphen in the closing tag.
Example of current behaviour:
<todo-item></todo>
Desired behaviour:
<todo-item></todo-item>
Thanks!
If you activate
set keymap=russian-jcukenmac
and try to write a word хорошо
you end up with the [орошо
хъХЪэЭ
letters are affected, instead of russian letter I get:
х [
Х {
ъ ]
Ъ }
э '
Э "
Currently the (PearJumpTree) command invokes pear_tree#GetSurroudingPair()
to get positions to jump past, and it works as long as the pairs are located on the same line/ cursor is within an actual pair.
Was wondering if it would be possible to modify (or add a new) command so that if #GetSurroundPair()
is empty, it could then search for the next closer and jump past it.
Ex:
foo() {
ThisAllWorks("as Expected"); | [cursor] //Will jump the \" and \) correctly,
//however will not jump out to the closing \}
} // <-Here->
Executing a macro where <esc>f<something>
happens goes into insert mode.
For instance let's say we have (^ denotes where the cursor is):
foo("bar")
^
Executing a macro ciwfoo^[f)i, 1^[
makes:
foo("foo"))i, 1
instead of
foo("foo", 1)
After some fair amount of debugging the issue seems to be going away after removing the plugin which makes me think the autocmds for InsertEnter
or CursorMovedI
cause this.
Otherwise when I select an entry in the completion menu it will results in a newline.
Thanks.
I've had to disable roxma/vim-paste-easy because, with both it and pear-tree installed, if I type both an opener and a closer in less than a second (eg. function_with_no_arguments()
or results = []
), I wind up with a doubled closer.
I don't know enough about Vim's architecture and VimL to know which side should be responsible for fixing it, but I'd advise at least mentioning it in the README in case anyone else trips over it, experiments with the smart pairing options (which have no effect), and then concludes that pear-tree is broken without investigating further.
So, I'm trying to add the following mapping (for ReasonML's interpolated strings, that look something like {bleh| this |bleh}
):
" ~/.vim/ftplugin/reason.vim
let b:pear_tree_pairs = extend(deepcopy(g:pear_tree_pairs), {
\ '{*|': {'closer': '|*}'}
\ }, 'keep')
However, only {
is getting paired — and I don't see a <Plug>(PearTreeOpener_|)
mapping. Is this a bug, or am I mis-reading the docs?
I installed the plugin using vim-plug in neovim on my Debian system. My neovim version is v0.3.4. The autopairing is just not working at all. Please help. Thanks in advance.
Is there a way to jump backwards, inside the nearest pair?
Thanks for the great plugin
Title is not very accurate because I wanted to avoid using a "clickbaity" title. The problem is that the closer is not inserted for an opener
which ends with a pattern similar to ass*|
.
To reproduce, compare the behaviour of:
let b:pear_tree_pairs = extend(deepcopy(g:pear_tree_pairs), {
\ 'ass*|': {'closer': ' end'}
\ }, 'keep')
with
let b:pear_tree_pairs = extend(deepcopy(g:pear_tree_pairs), {
\ 'bss*|': {'closer': ' end'}
\ }, 'keep')
For example, doing :set filetype=c
in an HTML file should make it so that HTML tags are no longer paired.
After a pair has been inserted and nothing but a newline is entered, pushing the closing character down a line, the closing character disappears until insert mode is exited. The issue does not seem to happen when anything is entered between the pair. I've tried disabling all other plugins and settings but the issue still remains.
My .vimrc
:
set omnifunc=syntaxcomplete#Complete
set completeopt+=menuone,noselect,noinsert
set nocompatible
set autoindent
" set cursorline " This is nice but makes vim slow in some case
set synmaxcol=90 " Limit syntax highlighting to amount of columns (you might want to disable this if you're on a fast system
set colorcolumn=90
set nofoldenable
set foldmethod=syntax
set history=100
set hlsearch
set incsearch
set ignorecase
set laststatus=2
set nospell
set noerrorbells
set noswapfile
set number relativenumber
set numberwidth=1
set tabstop=2
set showmatch
set shiftwidth=2
set timeoutlen=1000 ttimeoutlen=0 "This makes visual blocks fast
set updatetime=100
set viminfo+=n~/.vim/.viminfo "Different folder for viminfo file (disable if not on linux)
let mapleader="§"
" Latex support
let g:tex_flavor="latex"
" Keybindings
"""""""""""""""""""""""""""""""
" Resource .vimrc
nnoremap <silent> <Leader>up :source ~/.vimrc<CR>
" NERDTree
nnoremap <silent> <Leader>e :NERDTreeToggle<CR>
" ALE
nnoremap <silent> <Leader>al :ALELint<CR>
nnoremap <silent> <Leader>af :ALEFix<CR>
" Next marker
nnoremap <silent> <Leader>n /<+++><CR>cf>
inoremap <silent> <Leader>n <Esc>/<+++><CR>cf>
" Previous marker
nnoremap <silent> <Leader>N ?<+++><CR>cf>
inoremap <silent> <Leader>N <Esc>?<+++><CR>cf>
" Place marker
inoremap <silent> <Leader>m <+++>
nnoremap <silent> <Leader>m i<+++>
" Used to finish tab completion when enter is pressed
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" Bind popup navigation to ctrl-j and ctrl-k
inoremap <expr> <C-j> ((pumvisible())?("\<C-n>"):("j"))
inoremap <expr> <C-k> ((pumvisible())?("\<C-p>"):("k"))
" Cancel search
nnoremap <CR> :noh<CR><CR>
" Tags
nnoremap <Leader>tp :ptag<CR>
nnoremap <Leader>tc :pclose<CR>
"""""""""""""""""""""""""""""
"
" Colors
colorscheme onedark
call plug#begin('~/.vim/plugged')
Plug 'ctrlpvim/ctrlp.vim'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'w0rp/ale'
Plug 'tpope/vim-fugitive'
Plug 'sheerun/vim-polyglot'
Plug 'ap/vim-css-color'
Plug 'scrooloose/nerdtree', {'on': 'NERDTreeToggle' }
Plug 'vim-scripts/AutoComplPop'
Plug 'tpope/vim-surround'
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-commentary'
Plug 'wincent/terminus'
Plug 'mattn/emmet-vim'
Plug 'rust-lang/rust.vim'
Plug 'janko/vim-test'
Plug 'christoomey/vim-tmux-runner'
Plug 'qnighy/lalrpop.vim'
Plug 'christoomey/vim-tmux-navigator'
Plug 'tpope/vim-repeat'
Plug 'mileszs/ack.vim'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'Yggdroot/indentLine'
call plug#end()
command! Conf :sp ~/.vimrc
autocmd BufEnter * syntax on
autocmd BufEnter *.tsx set filetype=typescript.vim
filetype plugin on
Arrow left and right key turn into enter and type C or D character
but when I commented at these settings, my arrow keys work fine again
"imap (PearTreeBackspace)
"imap (PearTreeExpand)
"imap (PearTreeFinishExpansion)
Hi, first of all, this plugin is amazing.
I'm wondering whether it would be possible to extend it with support for pairing in command line mode. It might be useful when inputting strings or parentheses for function arguments.
(defun f (x)
""|)
<CR>
I get:
(defun f (x)
""
|
)
expected:
(defun f (x)
""
|)
this doesn't expand that way:
foo(bar()|)
gives (as expected):
foo(bar()
|)
there's some fishy interaction with the quotes
I've noticed that the smart openers and smart closers don't quite work when there is an unpaired paren or bracket within a comment. For example:
// :( <- miscellaneous unpaired paren inside a comment
test(|)
I'd expect if I were to press )
, that the cursor would then move to
test()|
Is it possible to ignore comments when deciding whether to use the smart closers or not?
...specifically, endwise.vim, a vital plugin for languages like ruby and viml that use end
(and its variants) to close code blocks.
A quickfix is to change:
imap <buffer> <CR> <Plug>(PearTreeExpand)
to
exec "imap <buffer> <CR> ".maparg("<CR>", "i")."<Plug>(PearTreeExpand)"
...though this adds an extra blank line, for example, typing def foo<CR>hi!
produces:
def foo
hi!
end
...so this isn't a full solution.
This plugin, along with its great config, is the only one of its type that actually does what I want so I'm pretty invested in resolving this! I'd be happy to take it on myself I wanted to file an issue first to get your thoughts and see if you'd even be amenable to a PR.
Hi! awesome plugin:
Imagine editing some markdown buffer, and:
```sh|```
If I press (PearTreeExpand) I would like to get:
```sh
|
```
Instead I get:
```sh
|```
Maybe put this behind some rule option (to only apply to ```).
Thanks!
Hi there,
Is there a way to disable the mapping which remove the closing character and restore it automatically when quitting insert mode.
I use jk as and it doesn't work.
with <CR> and <ESC>
func main() {
//Do something
}
with <CR> and jk
fun main() {
// quitting insert mode with jk doesnt' fill automatically the closing character
After expanding a bracket by pressing enter (like {), if i input a closing bracket, it wont remove the bracket auto created by the plugin.
I set g:pear_tree_repeatable_expand
to 0 since that feature is a bit broken for my use cases.
I use neovim 4.3, but im pretty sure this bug happens on vim too.
How to reproduce:
let g:pear_tree_repeatable_expand=0
expected result:
{
}
actual result:
{
}
}
Very annoying when i want to keep typing without leaving insert mode.
If I have, for instance, this configuration:
let b:pear_tree_pairs = { '“': {'closer': '”'}, '‘': {'closer': '’'} }
And then I type “
(U+201C) in insert mode (by pressing AltGr+v
in my Brazilian keyboard) the corresponding ”
(U+201D) is not inserted. Same for ‘
(U+2018) and ’
(U+2019) pairs.
Great plug in makes the experience amazing!
I'm trying to do this, which doesn't work
aug test
au!
au FileType html.twig let b:pear_tree_pairs = {
\ '<*>': {
\ 'closer': '</*>',
\ 'not_if': ['br', 'hr', 'img', 'input', 'link', 'meta', 'area', 'base', 'col', 'command', 'embed', 'keygen', 'param', 'source', 'track', 'wbr'],
\ }
\}
aug END
I tried this & still the <*>
expansion doesn't work but everything else works
aug test
au!
au FileType html.twig let b:pear_tree_pairs = extend(deepcopy(g:pear_tree_pairs), {
\ '<*>': {
\ 'closer': '</*>',
\ 'not_if': ['br', 'hr', 'img', 'input', 'link', 'meta', 'area', 'base', 'col', 'command', 'embed', 'keygen', 'param', 'source', 'track', 'wbr'],
\ }
\}, 'keep')
aug END
If I set it globally it works thought
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.