-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Snippets in neatvi #4
Comments
This won't be implemented in my fork because its too specific for LATEX, which I don't use. But I won't leave you empty handed either. In order to discover the full capability of customization you will have to write C code to do that. Here is an idea of how I would have done it.
Pick the key that is not in use, I used * for this example. Don't implement this kind of stuff in insert mode, it will be too difficult to time keys correctly, but if you really cut short for keys you can still try or just bind one key in insert, not a sequence like ",dmath". |
Thank you for the code, it works perfectly! Do I understand you right: if somebody wants such a feature, it's not possible to have it indenpendant of the language. The snippets must be integrated in the code with the shortcuts. Right ? |
Forget my last comment, I thought about it. I want to do some tests. I will try something the next days and I will close this issue as it is or close it with a suggestion if somebody else read this issue. |
I tried to customize it, and with your example it's pretty easy to add more snippets. I did the following:
Here I use After trying that solution, I have the impression that it's faster to insert some code when it's defined at compile time. The gain remains small. But the at the end it's possible to have an editor small in size and customizable. I already had a look at C code. Thank your for showing me how to implement some snippets! Perhaps what I wrote can give some ideas to other people. If there is no big problem in my code, I let you close this issue. |
You can control the cursor position using xrow and xoff variables. Function term_pos() prepares the move command and term_commit() actually does the thing. Normally you would not need to worry about those functions because they are called for you each draw update, unless you are doing something special. That said xrow and xoff is all you need. If you need to que commands in advance I'll have the function vi_argcmd() where you can que motion keys like hjlk (and more) in advance with an argument. |
Thank you for those information! I have begun to learn C code, I'll have a look next week. I have already tried but it didn't work. I will try again with those new information. Otherwise I will report what doesn't work. |
Sorry, for not responding until now. It's still on my list. I put this aside during holidays and tried to finish other stuffs. I have a look again on next week. |
Good point. Latest build versions were not very stable because I kept failing to find the correct solution to how to trim the syntax highlight to work only in range of the visible terminal cells. And there is bunch of things that makes it uneasy, variable length tabs, utf-8, double width characters, text direction. I kept breaking one of those while fixing the other. But now it should be stable. If you wanna have fun and test it out, make a file that consists of lines that are very long, probably like 30K characters and see performance difference between base neatvi version and mine. |
With your help, I was able to move the cursor. I got the following:
I will try to implement some shortcuts this way. I'm curious to try your improvements. But the problem is to have a file with lines of 30k characters. Does the content matter ? Could I create a file with for example:
and repeat it until I have 30k characters ? |
Yes, you can just repeat that pattern "for (i=4;i < 10; i++){ int i; i = 0; }" on a single line. You can copy it like so: 0y$ and then just hold p to paste it, then rinse and repeat until you have a huge line. It's pretty rare to find huge lines like this in code, but I had once saw such a huge comment in glad.c library which listed the supported opengl extensions and it was 15K characters on one line. I quickly noticed that vi's performance has become quite unbearable because of that line to I had to optimize it in my fork. Otherwise I would have probably not even know that it can be so bad. It also might help if you ever get some obfuscated javascript code from some website, usually it will have all the code on one huge line, etc ... |
I tried it, but honestly I can't see any difference. They are both very fast. Maybe if the same code is repeated, it's not a problem. Or I did something wron Thank you for your help, time now for me to implement my snippets... and enjoy your customizations! |
I find snippets to be very convenient and I would like to have the possibility to define snippets in neatvi. I know, it's rather a feature than a customization.
At the moment I use snippets in vim but without using plugins. So I think it would be possible to have snippets in neatvi. But I need the map feature from vi. I have the following in my
vimrc
for example:I bind
,dmath
toAfter the
<Esc>
key at the end, I use the commandO
to open a line above\end{displaymath}
so my cursor is at the right place to write Latex code.It's even possible to define some placeholders, for example:
In this case I want to insert
\frac{}{}
. After writing,fr
in insert mode,\frac{}{<++>}<++>
is inserted and the cursor is in the first curly brace. Then I have to define a shortcut to jump to the next<++>
. Perhaps it's not so powerful with some other snippets plugins, but it's enough for me and without the need to install a lot of dependencies.To use it, I rely on
map!
which is availabe in traditionnal vi. I did some tests, but it seems that the commandsmap
andmap!
don't exist. Another problem, I defined the snippets in thevimrc
and if I understand right, there is no configuration file, only theconfig.h
. For me it would be no problem to write my snippet directly in theconfig.h
.For more information and to see some animated examples: https://www.tomchaplin.xyz/blog/2019_02_10/Vim-for-LaTeX/ (go directly to: "placeholders").
Would be something like this possible ? Perhaps it's not even necessary to have the
map
feature, but the possibility to write some code in theconfig.h
.The text was updated successfully, but these errors were encountered: