Command gg=G (to indent lines) has no effect in vi[m] on Linux RH - indentation

I would like to indent lines in files (SQL files, XML...),
and in spite of all that I searched and tried, for some reason
on my Linux servers the command gg=G does nothing (all my lines
keep their first character stuck against the left part of my
terminal...), but displays the message "X lines indented" anyway !
Under Windows where I use gvim it works perfectly.
What does it depend on ? My shiftwidth is well set to 8,
I don't know what else I should check... (some config file
maybe ?, no idea)

Make sure you set set nocompatible and filetype plugin indent on in your .vimrc. Open your XML file and enter :set filetype?. Vi(m) should recognize your file now as XML file (if it does not, tell Vi(m) that the currently open file is an XML file by specifying :set filetype=xml). Try to indent your source code now with gg=G.

Related

Getting Bad configuration option: \377\376h

I am setting my systems for codecommit. but getting following error
I followed the below link :
https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-ssh-windows.html
/c/Users/Prasanna/.ssh/config: line 1: Bad configuration option: \377\376h
/c/Users/Prasanna/.ssh/config: terminating, 1 bad configuration options
here is the config file
Host git-codecommit.*.amazonaws.com
User ********
IdentityFile ~/.ssh/codecommit_rsa
Am I missing anything to configure ?
You probably have some illegal characters in the config file. I had this problem while creating a config file on Windows. Unfortunately, simply opening the file in a Windows text editor may not show the illegal characters.
I was able to find this problem by running cat filename from a Bash prompt in Windows (git bash) and was able to fix it by running dos2unix filename in git bash. The same may work for you as well.
Just had the same issue. Open the file with Notepad++. On the bottom right it tells you the encoding the file is in. It has to be UTF-8 without BOM. You can fix that via selecting a new encoding at the top and saving the file.
This happened to me today, and I just recreated the config file and put my configs there, it works.

CLion standard input while debugging

What I'm trying to do is basically:
./myProgram < myData.txt
While I'm debugging with CLion IDE. I just can't find the option to do so.
A similar question - but product-specific to MSVS
I had the same problem and it seems that CLion is not handling standard inputs yet.
I got around this problem by changing the input stream before running my program.
As an example if you want to input a file stream inside your stdin you can write in your main:
std::ifstream in("ABSOLUTE_PATH_TO_YOUR_FILE");
std::cin.rdbuf(in.rdbuf());
Then you can find a way to toggle this stream change when you want. Note that for files you will need to provide absolute path since the application is run from a different directory than the current one.
I hope this can help until CLion provides a real solution.
Assuming your input file is myData.txt, you can reopen/reuse the stdin stream using freopen
freopen("myData.txt","r",stdin);
if you want to do the same with your output:
freopen("myOutput.txt","w",stdout);
this will work for std::cin, printf, etc...
You can find more information about this here: http://www.cplusplus.com/reference/cstdio/freopen/
By the way, there is already a feature request for this. If you are interested, you can vote here so it gets prioritized:
https://youtrack.jetbrains.com/issue/CPP-3153
As of CLion 2020.1 this feature is built in:
Input redirection
If you need to redirect input from a file to the
stdin of your application, you can now do that. Use a new field in the
configuration called Redirect input from. Enter:
A relative path (CLion will prepend with the Working directory path).
An absolute path (will be remapped for remote configurations).
Or macros (like FilePrompt).
Still Clion don't have the feature like pycharm where we can give input in terminal while debugging the code.
But it has an option to give input through a .txt file while debugging.
Image of debug setting window
Click the setting icon in the debug console (on upper left corner) to open the setting of debugging. Then check the "Redirect input from" box and select the input file path and click "OK".
Here you go!
Now you can give input from the text file while debugging the code.
For me, CLion creates the executable in a file called 'cmake-build-debug'. Check out my file structure in the pic.
Then, I just opened up my terminal and went to the directory containing the executable and used this command to pipe in the text file:
./FirstProject < ../hw1.txt

Qt: QProcess result doesn't match result at prompt

I'm trying to execute the following command from Qt:
explorer /select,C:\Temp Folder\temp.wav
This should show the file temp.wav as selected in an Explorer window. It works correctly when run from the command prompt.
However, when I try the following in Qt:
QProcess::startDetached(
"explorer",
QStringList("/select,C:\\Temp Folder\\temp.wav")
);
it doesn't work -- it opens Explorer but puts me in the "My Documents" folder. If I rename the folder to one without a space (TempFolder), it works correctly.
I've tried escaping the space in the folder name, placing quotes around the entire path, and many other combinations without success. Many combinations work correctly in cmd but do not seem to work when called through QProcess::startDetached.
The most confusing part is that the code I'm trying to copy is from QtCreator source code where they use something similar to open up a file in the Explorer window. Theirs successfully opens files with spaces in the path, but I just can't seem to recreate it!
When you make such call:
QProcess::startDetached("explorer",
QStringList("/select,C:\\Program Files\\7-Zip\\7z.exe"));
Qt transforms the argument string into the:
explorer "/select,C:\Program Files\7-Zip\7z.exe"
which is not a valid option to open Explorer and select the given file. This happens, because your single argument has space(s) and Qt escapes it with quotes.
To fix this problem you need to make the following call:
QProcess::startDetached("explorer",
(QStringList() << "/select," << "C:\\Program Files\\7-zip\\7z.exe"));
i.e. pass two arguments. This will produce the following string:
explorer /select, "C:\Program Files\7-Zip\7z.exe"
which is valid and will do what is intended.

Loading google.vim indent file in Vim

I am attempting to use the google.vim (and on vim.org) indent style for my c++ project, but I can't seem to load it. I installed google.vim using vundle and opened up a cpp file and noticed that my tabstops, shiftwidths, etc did not change. If you set global ts and sw parameters, are they not overwritten? How do you force a certain indention when editing a file in vim? I want everything in my vimrc file to be overwritten by the google.vim file when I edit a cpp file.
Running the :filetype command in vim reveals this information:
detection:ON plugin:ON indent:ON
The bottom line is that I don't understand how to tell vim to use my google.vim file located under ~/.vim/vundle/google.vim/indent/google.vim. From what I have read, vim detects that filetype of your current file and uses the appropriate .vim file for syntax and indentation. So would I then have to rename my google.vim file to something like cpp.vim?
In most cases I like to use a tabstop of 3 and a shiftwidth of 3, so I set these in my .vimrc file. However, when I edit a cpp file, I want all my settings to be changed from what I have set globally to what the google.vim file sets.
You must rename the file from google.vim to cpp.vim, as indicated in the description of the plugin on vim.org.
General explanation:
Adding filetype plugin indent on to your ~/.vimrc allows Vim to detect the filetype of the files you edit (usually based on the file extention) and source filetype-specific plugins and indent scripts.
The idea is simple: you edit a file with {{LANGUAGE}} filetype and Vim tries to source any ftplugin/{{LANGUAGE}}.vim and indent/{{LANGUAGE}}.vim it finds in your runtimepath.
Because the filetype of your file is cpp, Vim will blissfully ignore your google.vim indent script so… you must rename it to cpp.vim for it to work.
Or you could rename all your C++ files foobar.google and teach Vim to recognize *.google files but, well… it doesn't sound right ;-)

How to feed Visual Studio Clang-Format plugin with clang-format file?

So I downloaded, installed, and inserted into path the clang formatting plugin. I also tested it and it works for Google (Mozilla, etc.) formatting options out of the box, yet I cannot get it working with my .clang-format file. (I've put my file into the same folder as my source file, changed its encoding into UTF-8, also tried to put it into clang install folder, add file into project, write its contents inside '{key:value}' yet formatting does not happen). So how do you feed formatting file to chrome-format extension?
My file contents:
{ BasedOnStyle: "LLVM", IndentWidth: 4 }
My file name:nm.clang-format
Go to Tools->Options->LLVM/Clang->ClangFormat and put file in the Style option field.
Then place your style file named .clang-format (this is the full filename, not an extension) either in the source file's directory or one of its parent directories. Windows Explorer won't let you create filenames with leading . so you need to go to the console for this.
If like me you got confused later on where the .clang-format was living, use procmon to track the file reads of clang-format.exe
For the record, it seems that if both "Fallback Style" and "Style" are set to "file", no formatting will happen even if the style file is at its correct location. Setting "Fallback Style" to something different than "file" (e.g. "none") helps.
In VS2019 works if the clang-format file is named as .clang-format.
It must be .clang-format, not .clang-format.txt or clang-format.txt.