What is your compiler flags when using Vim for C++? Where do you put them?
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
What is your compiler flags when using Vim for C++? Where do you put them?
Название |
---|
In .vimrc file. Here is mine....
autocmd vimEnter *.cpp map <F8> :w <CR> :!clear ; g++ --std=c++17 %; if [ -f a.out ]; then time ./a.out; rm a.out; fi <CR>
I put it in my .vimrc but when I press F8, it doesn't run. Where does the output show? How to input numbers? Do you have multiple input and output files?
It works fine for me. Where did you put .vimrc file ? are you sure it is on your home directory. you can just make it like, vim ~/.vimrc or vim /home/USERNAME/.vimrc
Ya, I put it in my home directory.
I don't use Vim but if you are compiling from the command line you can make an alias so that you can type "bd" instead of "g++ -Wall ...". On Linux you can modify the .bash_aliases. On Windows you can modify $PROFILE by adding a function to it like:
and then you can simply type "cl xxx.cpp" to compile.
I want to compile and run within Vim but thanks!
BTW, how do you modifly $PROFILE? Just a question, was wondering...
can you please help me .. i want to compile by such that it opens a new terminal screen so that i can compair my code and its output
Did you set up .vimrc?
yes but its compiling and running my code in same terminal i.e by first closing my vim and then running my code and then after that again opening my vim.. i want that the output must be shown by opening new terminal window ..like in codingblocks ide... is it possible?? help:)
You can use
:term CMD
to open a terminal in a new window and execute a command in that window. E.g. try:term ls
. Replace that with your command you want to run, e.g. the command to compile or run your program. Obviously you can also make a keybinding for that command.F9
for Compile and RunF5
for Compile ( never use this :p )F2
for saving fileI save and run inside Vim. Also, when creating a new file it asks for a template that I should load , which is saved in
.vim/template
and it fetches.cpp
types which you can easily changeAnd just in Case :
Hope it helps!
When I press F9, it says that '.' is not recognized as an internal or external command, operable program or batch file. shell returned 1. How to solve this problem?
Here is my .vimrc
By any chance, are you on Windows?Edit : Sorry Never came across such error , Did you try compiling first , then running by terminal command
./file_name
How to compile first and how to run it in terminal?
As mentioned above,
F2
to save your code,F5
you can compile your code,( if there's no error, there will be a file created in your current directory with name of your current cpp file name )./filename
in the directory file is savedThanks!
Is there any solution for windows, it's working in linux but showing error in powershell
thank you! But is this the same for VIM in windows too?! Where the .vimrc file is named as _vimrc.
I would (in normal mode) type ":version" and then a list of files will appear. Towards the bottom, it will say "user vimrc file: " then that file name. If you don't see that, first create one.
How to set up a C++ template for a GVIM on Windows for competitive programming? Please I have tried so hard, but I haven't found any solution.
What do you mean by template? Is it like sublime in which you type in the "template", the template appears in the file?
Yes.
Blog
which font do u use for vim?
What is up hackerman44.
sorry for getting blocked! by the way, i just needed an answer! so i commented, plz do reply!
I use Consolas 15
I would like to have a vim plugin to include code snippets.
On some keypress a listing of the files of a configured directory should be displayed. I can choose one. If choosen, that file should be copied into my current edited file, maybe at cursor position.
Any suggestions? Or how to write such one?
Or does somebody know how to use/extend NERDTree for that purpose? File listing and choosing is perfect, but I don't know how to read a file on keypress. Instead I have to open it, copy content, close it, then paste content.
Surly there is a better way.
I don't exactly know how to do this in Vim, but whenever I need to copy a whole file I just do
xsel -b < FILE
.Hey. I've done exactly the thing you are describing. With a key binding I can choose between all my prewritten algorithms, choose one, and it will be copied into the file at the current position.
Take a look here: https://github.com/jakobkogler/Algorithm-DataStructures (The Readme also contains a GIF with a short demonstration)
The path to the directory is hard-coded to my algorithms, but you can also change it to something different in the
autoload/alg_ds.vim
file.This is cool, with preview! Thanks a lot.
You might wanna try UltiSnips. It works just like snippets in VS Code and Sublime. You can even add a tab trigger with a few lines of vim script.
bruh! can u share your vimrc file ?
Not sure if it really helps, but anyway:
Use terminal and Makefile.
P.S. I don't know, why one dollar automatically replace to three dollars, and have no idea, how to write exactly one dollar, sorry(
can u share ur github link for the makefile and can u share how does it work on windows
Ok, link.
Idk, how does it work on windows. I advise you to install any Unix system, it's more useful for programming.
I am new here. Is there any reason why using vim is better than sublime? There are many good settings and automations that you can do with sublime.
What editor you use is up to your personal preference. An editor might be better for me, but worse for you. Find one that you like, learn how to use it and stick to it.
The reason I use Vim, is because it is small, fast, directly available in the terminal, available on every server, modal editing is awesome, huge possibilities of configuration and extension, one editor for everything, ...
Also I doubt that Sublime has a feature that you can't have in Vim. Well, maybe one feature: being beginner friendly :-)
Seems appropriate. But why not just use the custom invocation provided by CodeForces itself?
Advantages that you have by developing locally:
simplest form of compiler flag
I use
just press for compiling and for executing. :P
it's working, but how can i run, compile and save from a single command??
All you have to do to compile is press . Then, you can press for executing where you can input your data. For saving a file go to normal mode by pressing then type
If you want to close and save that file in normal mode, you can press
Hope that this helped!
How can i compile & run pressing a single function ?? i have a source but it only compile & runs C++11 .But i want it for C++17 .
If you want to press a single button and have it compile and execute and have C++17 with -O2 and -Wall put
in your .vimrc.
But, how can i add this --stack,268435456 in vimrc for compiling & running at the same time !?
Then use
But when i try to add bits/stdc++.h , it doesn't work and shows error.
It works for me though
which compiler are u using for C++ ?
I am using MinGW version 9.2.0 on Windows.
bruh! i am also using tmw's vimrc but when i first compile (with bits/stdc++.h header) with F9, and then execute my cpp file with F10, the compilation is done quickly, but the problem is=> if i use a F5 to compile & run (that u provided me in this post
autocmd filetype cpp nnoremap :w !g++ -std=c++17 -O2 -Wall % -o %:r -Wl,--stack,268435456 && %:r.exe
), the performance is laggy and why does it takes more than 4 seconds to compile first and then run. Any fix to reduce the time with appropriate compilation flag?
Precompiled headers.
i did that also, but didn't work! u can check on your windows also. thanks!
For the F5 command try using this
when i tried your code, it says the system cannot find the file specified. shell returned 1?? what should i do??
I think his config is for linux. You may change
./a.out
to./a.exe
. I'm not using windows so not 100% sure.How to include timeout in the command so that it automatically terminates in case of infinite loop..?
autocmd filetype cpp nnoremap :w !timeout 3s g++ -ulimit -Wall -Wno-unused-result -std=c++17 -O2 % -o %:r && ./%:r
Above command works fine for running code but timeout does'nt work.
Did you consider using a text editor with vim keybindings?
https://github.com/xuhdev/SingleCompile is a Vim plugin made to compile and run single files and it's really good because it support a lot of languages. iirc it runs synchronously (that means it stops vim while your program is running)
In Neovim and Vim >= 8 asynchronous tasks were introduced, and i use this plugin ( https://github.com/skywind3000/asyncrun.vim ) because is simpler to configure. But with it you have to define a compile command for every programming language... To simplify everything i made an external bash script that is called by AsyncRun when I press F9. It automatically detects the language and calls the right compiler.