How to turn off automatic closing paren in Clion - settings

How do I turn off automatic closing parentheses (in C/C++)? There are "insert pair bracket" and "insert pair quote" options under Settings/Editor/General/Smart Keys. Both are unchecked. But I see nothing about parentheses. It wouldn't be a big deal if CLion would just overtype its automatic ones when I also type the closing paren. As is I end up with two closing braces every time. I spend more time configuring jetbrains products than I actually do writing code...zzzzzz.
Using CLion 1.2 on Linux. Thanks.

"Insert pair bracket" in Settings/Editor/General/Smart Keys does the job in Clion 1.2.4.

Related

vim: How to create a shortcut on ALT key to insert text while in insert mode?

I usually press alt + , to insert <, it works fine in my zsh terminal and on every other application, but unfortunatly not on vim or neovim.
I tried following but nothing worked:
map <M-,> "<"
map <M-,>='<'
I appreciate any help
Everything is wrong, here.
First, you can't expect any of those mappings to do anything in insert mode because the :map command creates mappings for normal, visual, and operator-pending modes, not for insert mode. The first thing to change is thus to use the proper :map variant:
imap <M-,> "<"
imap <M-,>='<'
Second, the left-hand side of a mapping (the keys you want to press) and the right-hand side (what you want Vim to press instead) are supposed to be separated by whitespace so your second example wouldn't produce a mapping to begin with. It asks Vim to list insert mode mappings that contain <M-,>='<', which is pointless.
Third, the right-hand side of a mapping is a macro, where every character is used as if you typed it. "<" would literally insert a double quote, an angle bracket, and a double quote. If you want the mapping to insert a <, use a <:
imap <M-,> <
Fourth, I've heard that Neovim handles the Meta/Alt key better than Vim so the mapping above is still likely to be problematic in Vim, depending on the OS or the keyboard layout. For example, in Vim on macOS with the AZERTY layout, the system translates Alt+, to ∞ before it even reaches Vim so <M- and <A- mappings simply don't work reliably.

How can I refactor an existing source code file to normalize all use of tab?

Sometimes I find myself editing a C source file which sees both use of tab as four spaces, and regular tab.
Is there any tool that attempts to parse the file and "normalize" this, i.e. convert all occurrences of four spaces to regular tab, or all occurrences of tab to four spaces, to keep it consistent?
I assume something like this can be done even with just a simple vim one-liner?
There's :retab and :retab! which can help, but there are caveats.
It's easier if you're using spaces for indentation, then just set 'expandtab' and execute :retab, then all your tabs will be converted to spaces at the appropriate tab stops (which default to 8.) That's easy and there are no traps in this method!
If you want to use 4 space indentation, then keep 'expandtab' enabled and set 'softtabstop' to 4. (Avoid modifying the 'tabstop' option, it should always stay at 8.)
If you want to do the inverse and convert to tabs instead, you could set 'noexpandtab' and then use :retab! (which will also look at sequences of spaces and try to convert them back to tabs.) The main problem with this approach is that it won't just consider indentation for conversion, but also sequences of spaces in the middle of lines, which can cause the operation to affect strings inside your code, which would be highly undesirable.
Perhaps a better approach for replacing spaces with tabs for indentation is to use the following substitute command:
:%s#^\s\+#\=repeat("\t", indent('.') / &tabstop).repeat(" ", indent('.') % &tabstop)#
Yeah it's a mouthful... It's matching whitespace at the beginning of the lines, then using the indent() function to find the total indentation (that function calculates indentation taking tab stops in consideration), then dividing that by the 'tabstop' to decide how many tabs and how many spaces a specific line needs.
If this command works for you, you might want to consider adding a mapping or :command for it, to keep it handy. For example:
command! -range=% Retab <line1>,<line2>s#^\s\+#\=repeat("\t", indent('.') / &tabstop).repeat(" ", indent('.') % &tabstop)
This also allows you to "Retab" a range of the file, including one you select with a visual selection.
Finally, one last alternative to :retab is that to ask Vim to "reformat" your code completely, using the = command, which will use the current 'indentexpr' or other indentation configurations such as 'cindent' to completely reindent the block. That typically respects your 'noexpandtab' and 'smarttabstop' options, so it use tabs and spaces for indentation consistently. The downside of this approach is that it will completely reformat your code, including changing indentation in places. The upside is that it typically has a semantic understanding of the language and will be able to take that in consideration when reindenting the code block.

ReSharper Keep existing line breaks not working

Under Formatting Style | Line Breaks and Wrapping | Preserve Existing Formatting I have "Keep existing line breaks" option checked. However, when I apply ReSharper Reformat Code function to file it removes my existing line breaks and places all the code in a statement on a single line.
Which setting could be annulling the "Keep existing line breaks" option and forcing the code on a single line?
I do have "Wrap long lines" under Line Wrapping unchecked but I don't think that should impact the "Keep existing line breaks" option.
Message = string.IsNullOrWhiteSpace(someString) ?
Properties.Resources.SomeResource : someBool ?
Message = Properties.Resources.SomeResource + Environment.NewLine + customMessage : customMessage;
After applying Reformat Code ReSharper function this statement with two line breaks becomes a single 240 character long line.
Visual Studio 2015
ReSharper 2017.1.3
I ran into a similar issue with the JetBrains CodeCleanup tool, take a look at the ternary operator formatting rules, for me it was the wrap_ternary_expr_style setting. I believe it's trying to fix the formatting of the ternary operator and since you don't have a max line length it condenses it down.

Dealing with backticks in PhpStorm / WebStorm

We recently changed our project boilerplates for using single quotes to using backticks. Working with backticks in *Storm on OSX is not as convenient as working with single quotes, thus we tried to come up with some solutions which still lack some convenience. We're looking for further ideas to find better solutions now.
How single quotes work in *Storm on OSX
typing one single quote results in two single quotes with the cursor in between ('|')
typing afterwards results in text between the single quotes ('what has been typed')
if 'surround selection on typing quote or brace' is true, selecting some text and typing a single quote results in
the text being wrapped in single quotes ('some text')
How backticks work in *Storm on OSX
typing one backtick results in one backtick (`), when pressing space you get two backticks with the cursor in between (`|`)
when typing a letter, you get two backticks with the cursor in between (`|`) except if the letter is a, e, o, u, i, then you'll get (à, è, ò, ù, ì) which is quite disturbing
when pressing space, you get two backticks with the cursor in between (`|`)
selecting some text and typing a backtick results in a backtick (`), which is also not what we'd like to have
Since a backtick is a dead key by default, I am struggled with the same issue.
Live Template
Currently I created a live template named it -- (double-dash) for a quick which prepares a backtick-surrounded string. Below you can find the settings I used for the template:
Abbreviation: --
Description: Backticks
Template text:
`$0$`$END$
Apply: JavaScript
Unfortunately PHPStorm/Webstorm does not provide a way to toggle the quote style. Similar to the case toggler (Edit -> Toggle Case)
Concerning the typing
Just use keystrokes <backtick> + <space>and type a text and you'll get `a text`.
Concerning surrounding
Create a Live Template called backticks with a content of `$SELECTION$`$END$, set the context to Javascript. Go to the keymap and search for 'Surround with Live Template'. Assign a key combination. Go back to the editor, select some text, press the just assigned
combination and press 'ENTER' to confirm selecting your 'backticks' template. This will wrap your text in backticks.

How can I record a "(" in a macro in vsVim?

I'm trying to record a macro that will type a small chunk of text that contains a parenthesis "(", whenever I try to play the macro it doesn't type the "();" at the end of the line.
My guess is that parenthesis in a macro may have some special meaning but in my case, I just wanna type in "(".
What's breaking my macro? How can I get the parenthesis to be typed?
(note: I'm using the Visual Studio vsVim plugin)
Edit: I can't remember the exact macro anymore, but it went something along the lines of this:
q a 5 j ^ 2 w i .EndInit(); esc q
It was supposed to append .EndInit(); on every 5th line but the output was just .EndInit.
Note that on other machine without the resharper plugin, this problem doesn't occur!
The most likely issue here is that R# is eating the ( keystroke. This means it never makes it to VsVim and hence doesn't get recorded as part of the macro.
The following issue tracks cleaning this up. It would include fixes for R# as well.
https://github.com/jaredpar/VsVim/issues/1393

Resources