Problems encountered when using neosnippet
Well, the problem is this. When using neosnippet to expand a snippet, neosnippet will generate tabstops. These tabstops are hidden according to the initialization plug-in code given by the author. The key to the problem is that if I expand a snippet, then Immediately save and exit the file. When you open the file again, you will find that the tabstop is inserted into the text. This feature makes me very depressed. This is the issue I submitted to the author on github
https://github.com/ Shougo/neosnippet.vim/issues/236#issuecomment-44950979
The author also told me that this is a feature, but when I finally asked how to solve the problem of tabstop being inserted into the text, he asked me to look at it
:help conceallevel
:help concealcursor
I have read it, but still don’t know how to solve this problem.
Actually, my question is, if tabstop is not inserted into the text
The picture below shows the tabstop that appears when a snippet is expanded (I have canceled the author's recommended settings, so the tabstop can be seen)
Next, immediately exit the text and reopen it, you will see the tabstop is inserted into the file
Those things are placeholders in the plug-in, please don't call them
tabstop
,因为tabstop
They have a specific meaning in vim. When you said this, it took me a long time to understand what you were talking about.First of all, those placeholders are definitely useful. When you expand the code snippet, the placeholders help you determine the location of the code that needs to be filled in. Personally, what I find puzzling is: you have expanded a code snippet, but you don’t finish filling it in but just close the file and open it again. Why is this? What a weird operating habit!
However, even vim has enough methods to deal with weird people. The stuff Shougo lets you see is called
conceal (text)
in vim, which in Chinese means "hidden characters". Those placeholders in Neosnippet are hidden characters, and you can adjust whether/how hidden characters are rendered.Hidden characters are not really hidden. It is a special syntax in vim syntax. You can use the syntax configuration command to set the visual state of hidden characters, so if you find that the setting of hidden characters is not exactly what you thought. , then maybe the syntax (color matching) you are using has settings in this regard. You can change it or dig in and take a look.
Let’s talk about the two options under normal circumstances:
conceallevel
和concealcursor
.When text is marked as "hidden characters",
conceallevel
determines how the text is displayed. It has four values:Set to
0
, not hidden, as it should be (this is the default, so the placeholder is still visible)is set to the character set in the
1
,每一块隐藏字符用一个特殊字符来替换,这个字符是由当前使用的语法配置设置的,如果语法高亮没有,那就使用listchars
option. If this is not available, the default replacement character is a spaceis set to
2
to completely hide the hidden characters (meaning that even the default spaces are not used), but if there is a replacement character set in the grammar configuration, use the setSet to
3
, hidden characters will not be displayed at all, regardless of any settings.So far, you may think that setting it to
3
最清爽了吧,但是你要小心,完全不显示隐藏字符就意味着一旦某些插件自作主张替你设置了隐藏字符,你是永远也看不到它们的!比如说我曾经用过一个 JSON 的语法高亮插件,不知道作者是怎么想的,他把所有的;
is the most refreshing, but you have to be careful. Not showing hidden characters at all means that once some plug-ins set hidden characters for you on their own initiative, you will never see them again. Can't get enough of them! For example, I once used a JSON syntax highlighting plug-in. I don’t know what the author thought. He set all;
as hidden characters, which made me confused. It’s been a long time…If you must not display hidden characters at all, then you must at least consider how to match it.
concealcursor
来使用。默认状态下,vim 不会对当前光标所在行的隐藏字符采取conceallevel
的设置,也就是说不管你怎么设置,当前光标所在行的隐藏字符都是会显示出来的,concealcursor
Determines whether hidden characters are displayed on the line where the current cursor is located in vim's four main modes (regular, insert, visual, command).This option is empty by default, so in the four modes, hidden characters will be displayed in the line where the current cursor is located. You can
n
i
v
c
四个值里挑选组合来设置你希望的方式。就拿你这个例子来说吧,比方说你希望除了插入模式以外,剩下的时候我都不希望看到这些占位符(隐藏字符),那就set concealcursor='nvc'
. If you know these code snippets well, it doesn't matter if you don't show hidden characters in insert mode.By the way, you can try UltiSnips. This plug-in is simpler than NeoSnippets and is fully compatible with NeoSnippets code snippets. It is very suitable for beginners (the functionality is definitely not bad).