How to make Vim format C++ code automatically as I type - c++

I have setup clang-format to reformat the current line/selection when I press Ctrl-K in Vim (see the official documentation how to do that). However, it's annoying to be constantly pressing Ctrl-K whenever I edit a line.
Is there a way to make Vim call clang-format as I type or edit code automatically, without me having to press Ctrl-K? In other words, probably after each key stroke in insert mode?
I haven't seen anybody setup vim this way --- what are the potential problems with this setup?

Related

Is there a shortcut to run current code block, without selecting?

Many other IDEs have a feature to run the code block your cursor is placed in. According to the docs, SAS EG has the following shortcut:
Run the selected code -> F3
But is there a shortcut for the following?
Run code block your cursor is placed in -> X
It's tedious to have to constantly reach for the mouse to click-drag-select, then hit F3.
Preemptive thank you from the laziest lizard on earth.
No, there is no shortcut (or way to create such a shortcut). SAS requires you to highlight it.
However, there are some options to make this easier. You can see the SAS EG documentation for some keyboard shortcuts; one option, for example, is to use code folding (Alt + numeric keypad hyphen) to collapse the current data step/proc step/macro, and then you can easily highlight that one line (with shift-end, as it places your cursor at the start of the line).
Also see this question and answer about SAS Enhanced Editor, which has the same basic solution, plus some other ideas.

How to highlight everything up to a certain point

I am new to SAS Enterprise Guide, and I'm beginning to get familiar with some of the useful keyboard shortcuts. I just figured out that Shift+F8 highlights the current step and F8 runs it, but I was wondering if there is a way to set up a shortcut that highlights the current step AND everything before it.
For those of you familiar with RStudio, what I'm looking for is analagous to the "Run all chunks above" option.
Thanks!
I've tried looking at the Macros menu to see if there is an existing option, but I didn't find one.
CTRL+SHIFT+HOME will select everything from a line up to the start of the program

Why isn't my terminal running my updated C++ code?

I am a new programmer and I am trying to use the terminal on my Mac to compile and run the C++ code I write using the Sublime text editor.
I am able to get my code to run using the terminal, however, whenever I make changes to my code on sublime and then re-compile it on my terminal, my terminal doesn't recognize my changes and keeps on running my original code.
Does anyone know what might be happening?
Thank you so much!
I can think of two possibilities that spring immediately to mind. If you're changing your code in the editor, and that's not being reflected in the compilation, then it's likely to be one of the following. Either:
you're not saving the file in the location you think you are; or
you're not saving the file at all.
The easiest way to tell if one of these is the case is to introduce an error into your code(a), like:
int my hovercraft = full of eels;
and make sure the compiler complains about it.
If you're not saving it at all, do so. If you're saving it in the wrong place, you can usually find out where just by doing a Save As and seeing where the default location is.
If you're annoyed that you have to save, and that computers should just "work"(b), Sublime Text has an auto-save feature that may come in handy, courtesy of one Lucy Bain. Instructions (paraphrased) are duplicated here in case that site ever disappears:
Open Sublime
Find Settings and edit the user window (under Sublime Text 2 > Preferences for Mac, just Preferences for Windows).
Add the line "save_on_focus_lost": true.
Save and close the file.
At that point, whenever you click away from a particular file, it should save it.
(a) Some developers seem to have little trouble doing this without even trying :-)
(b) A not unreasonable expectation for a Mac user :-)

WebStorm opens files on AutoScroll to source

wondering if I could have the same behavior as Brackets like it previews the code on the right side but only opens the file if we do some edits.
Helpful when I'm just going through the files and not really changing anything but then at the end I've to close all.
Is there a setting in web storm that can help achieve the same behavior like brackets
Currently I may only suggest to use View | Quick Definition to preview file content instead of opening (has to be invoked for each file, which is possibly not what you are willing to do).
Other than that: https://youtrack.jetbrains.com/issue/IDEA-130918 -- star/vote/comment to get notified on progress.
P.S.
As stated in this comment they seems to worked on something like that already but quite possibly did not finished it for IDEA v14 release: in build 138.2502 there was an option to open file in "preview panel" first (and if satisfied -- move to editor) instead of opening in editor straight away. But it still a bit different to what Sublime does.

Vim Folding with RainbowParentheses

So, I've looked everywhere for a good rainbow parentheses plugin that will give different level parentheses different colors. I really like the couple that I've found, because they both do a good job of customizability while highlighting the right thing. It supports more than parentheses; chevrons, braces and brackets all get highlighted, which I really like.
It seems like there are quite a few plugins for this!; I'm currently using oblitum's because his is optimized for dark backgrounds (I often work straight from the shell).
So, following the tip at the github for that plugin, I have the "always on" snippet in my .vimrc. But when the always on block is above "syntax enable" it doesn't show {} as being highlighted for cpp files. When the always on block is below syntax enable, folding doesn't work. I think its the nature of the plugin that makes it do this; it goes though the file and adds coloration information. I notice that if I use the command :syntax enable after I've loaded the file when its not recognizing folds, then it does recognize the folds. But at this point, it removes the coloration that rainbow parentheses put on it.
In my .vimrc, I have the follow pertinent lines:
syntax enable
set foldmethod=syntax
set foldenable
set foldlevel=100
let g:rainbow_operators=2
au FileType c,cpp,objc,objcpp call rainbow#activate()
I think that, from looking at syntax files that come with vim, such as c.vim, you can see that certain blocks are annotated as folding. I bet that if you could just write a regex based upon it, you could identify characters as syntactic groups. Then you could just define a colorscheme for it. In fact, the rainbow plugin is actually calling "syn region" commands, so I think that this route is very doable, I'm just not that knowledgable with vim scripting.
Can anybody help me modify possibly the plugin or come up with a script or something that achieves both?
Sorry the lateness, I've tried to solve it at Fix disabled folding (issue #2)
I dimly remember having had the same or a similar problem.
Also XML code highlighting was broken IIRC.
I put 'always on' off, and activated the colored parentheses only when I needed it.
So my working solution was just a shortcut to toggle the plugin on and off.