p00f / cphelper.nvim

Neovim helper for competitive programming. Use https://sr.ht/~p00f/cphelper.nvim instead
MIT License
133 stars 9 forks source link

cpp template for solution.cpp #24

Closed anurag3301 closed 2 years ago

anurag3301 commented 2 years ago

Hey I wanted to create a template for solution.cpp and inject the following code. This is whats inside ~/.config/nvim/templates/cptemp.cpp


#include<bits/stdc++.h>
#define FOR(n) for(int i=0; i<n; i++)

using namespace std;

int main(){

}

I followed online guide and added following in my nvim config

vim.cmd("autocmd BufNewFile solution.cpp 0r ~/.config/nvim/templates/cptemp.cpp")

If I create a file with nivm solution.cpp its working but in cphelper it isn't. Cphelper is still creating blank solution.cpp.

If I am doing something wrong, How can I fix it. :)

p00f commented 2 years ago

the event should be bufread, not bufnewfile (because the file has already been created)

anurag3301 commented 2 years ago

It works fine when the file is created after :CphReceive, but it add the code to any time I open an existing solution.cpp image

As I can understand its autocmd BufRead It will trigger every time I read the file.

p00f commented 2 years ago

ah right, should be fixed now (with bufnewfile)

btw you can just use snippets instead of workarounds like these - which are also useful for other standard procedures

anurag3301 commented 2 years ago

Yeah, I'll look for snippet way. But it would be really great if we have an option to inject a custom boilerplate code for the solution.cpp. A lot of people have their own boilerplate code specifically for competitive programming. I think It can be done when cphelper creates the solution.cpp file

p00f commented 2 years ago

then put your boilerplate in a snippet - it'll even place your cursor in the right position when you select it


#include<bits/stdc++.h>
#define FOR(n) for(int i=0; i<n; i++)

using namespace std;

int main(){
    int t; cin >> t;
    while(t--) {
        // CURSOR HERE
    }
}