I use Vim in a C++ code with openmp sentences.
And in my ~/.vimrc
set ai " auto indent
my problem: when I use an openmp sentence (this begins with #
) the cursor jumps to the beginning of the line without the auto indent.
Example:
int main()
{
int idx = 100;
#pragma omp parallel private(idx) // jump to begin of line
, when I like this:
int main()
{
int idx = 100;
#pragma omp parallel private(idx) // This is OK
Can I set this in the autoindent in Vim?
First, go to the start point of codes to be formatted, then press v to start selection. Second, go to the end point. Third, press = to format the codes that have been selected. All braces and indentations will be aligned.
How to Turn On Auto Indent in Vim. To automatically indent when editing a file in Vim, enable the auto indenting feature using the :set autoindent flag in command mode: Press Enter, and this will auto-indent the file you are currently editing.
To tab or add the indentation at multiple lines, try “shift+dot” i.e., “.” Shortcut once. You will see it will add an indentation of one character at each selected line from the start. If you want to add indentation without stopping, then you have to try the “.” Key from the keyword after using “shift+.”.
By Juliet Kemp. April 20, 2021. Vim is a modal text editor that allows users to alter text in different modes. These different modes determine how the alphanumeric keys on keyboards function.
Vim puts a line in column 1 when it starts with #
(preprocessor directives), if cinkeys
contains #
.
So you can remove #
from cinkeys
to disable this feature:
:set cinkeys-=0#
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With