Sometimes, we put our bare "if" statements into the code without adding the curly braces if it is composed of only one expression. Unlike Sublime Code Completer, it is a hassle to put the enclosing parenthesis or curly braces around my statements in the Jetbrains Products. I mean
if (something)
statement
when I pressed to "{", I want for ide to put the enclosing one at the end of the statement instead of putting adjacent to the newly put opening one.
Not like this:
if (something) {}
statement
Intended form:
if (something){
statement
}
Is there a way to configure as wanted?
As far as I know, there is not a way to enclose a code block exactly the way you are looking for, but there is a similar feature available without too much more work. If you simply select the code you would like to wrap and enter an opening bracket, IntelliJ will wrap your code in the brackets and place both the brackets on their proper line given your coding style.
Related
Let say I have a block of code like this:
await store.dispatch(getLicensesThunk('content', submission))
And I want to delete everything inside the getLicensesThunk excluding the parenthesis, what command should I use?
await store.dispatch(getLicensesThunk())
I currently use d% for this, but it will delete the parenthesis as well, which is not something I want.
await store.dispatch(getLicensesThunk)
d% can't do what you want because it is "inclusive", which means that it includes the characters at the beginning and end of the motion and therefore that it will swallow your parentheses.
Vim has a special kind of motion that can be used after an operator called "text objects". They are described under :help text-object, which is one of the most mind-blowing sections of the built-in documentation.
The one you are looking for is :help i( for "inner parentheses":
di(
Use di( to delete everything inside parentheses. This also works for double quotes (di") and a few more paired characters.
The cursor can be anywhere between the parentheses.
How to enclose curly braces in parenthesis in vim?
Initial string:
{a: b}
Final string:
({a: b})
The string possibly span multilines:
{
a: b
}
Assuming you are in normal mode and on any curly bracket character (opening or closing).
The manual/vanilla version (without any bracketing plugin) would be
c%(^R")
With:
^R meaning CTRL+R
the default register (") being filled with the content of the dictionary.
ca{ that should be used instead of c% if you're anywhere within the dictionary.
With my lh-brackets plugin, I would use v%( or vi{( -- unlike the vanilla version, will leave the default register unmodified.
With the popular surround plugin, I guess (I may be wrong as I've been using my plugin for decades) it would be something like ys%( or ysa{(.
PS: the fact your dictionary spans on several lines doesn't make any difference here.
With the vim-surround plugin you can visually select the text first e.g. va{, then surround with parentheses using S). I find it easier to remember this visual surround sequence v{motion}S<char> than the other options
I'm trying to ask a question on our friendly neighboring site, math.stackexchange.com and I'm new to mathjax and couldn't get what I need from this: https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference so I have come here for help.
I'm trying to show lambda is an element of the set (2,3) but I can't get the curly brackets/braces to be it. I can write it using parentheses, but not brackets (it makes a difference).
currently, I have $\lambda \in (2,3)$ but what I need are for those parentheses to be curly braces, and I can't figure it out.
Thanks!
MathJax is largely a subset of LaTeX, so when in doubt, refer to TeX documentation.
In this case, you need to know that curly braces are a common delimiter in TeX, and so they have to be escaped if you literally mean curly braces.
So, what you need is $\lambda \in \{ 2,3 \}$. Make sense?
I'm using (mac)vim with tex-suite and would like to have a single regex command (or any other way) to do the following thing:
Change
\textcolor{green}{some random text}
into
some random text
This should be done for all occurrences of \textcolor{green}{} in my tex file...
Any idea?
EDIT: I need it to recognize matching braces. Here an example :
\textcolor{green}{
with $v_\text{F}\sim10^6$m.s$^{-1}$ the massless Dirac fermions
velocity in pristine graphene}.
In my experience, things like this most often crop up during editing, and you might have the search for \textcolor{green}{ already highlighted.
In such a scenario, :global is usually my weapon of choice:
:g//norm d%diBvaBp
diBvaBp: diB (delete inner block), vaB (select block), p (put)
If you have surround.vim installed (recommend it!) you could remove the pair of braces simply doing dsB (delete surrounding {})
:g//norm d%dsB
Of course, you can combine it like
:g/\\textcolor{green}{/norm d%dsB
I just noted a potential issue when the target patterns don't start at the beginning of a line. The simplest way to get around that is
:g//norm nNd%diBvaBp
A more involved way (possibly less efficient) would be using a macro:
/\\textcolor{green}{
gg
qqd%diBvaBpnq
Followed by something like 100#q to repeat the macro
:%s,\\textcolor{green}{\([^}]\+\)},\1,g
Updated as per your updated question:
:%s,\\textcolor{green},\r-HUUHAA-&,g
:g/\\textcolor{green}/normal 0f\df}lvi{xhP$xx
:%s/\n-HUUHAA-//
Quick explanation of how it works:
Put all \textcolor{green} lines onto a line of their own, with 'special' marker -HUUHAA-
Use visual selection vi{ to select everything in between the {}, paste it outside and delete the now empty {}.
Delete leftover stuff including the marker.
I am using Vim to write my LaTeX files, and figured I'd make a few snippets to help me along. It's been no problem writing simple snippets (like one for begin, one for figure etc.), but then when I tried making one to set the title (with a default value including some curly brackets ({and }), I have this problem. The goal of my snippet is that it creates the following text:
\title{My name\\\texttt{me#email.com}}
I want all the text inside the outmost curly brackets (the ones belonging to title) to be a placeholder. I try to accomplish this by writing the snippet as follows:
\title{${1:My name\\\texttt{me#email.com}}}${2}
My problem, however, is that snipMate seems to use only the name and the email (omitting the closing bracket for the texttt command) as a placeholder.
SnipMate has some known problems with these things, the parsing for nested
braces just doesn't work. Maybe someone knows how to do this, but in the
meantime I suggest you creating two snippets, one for \title and another for
\texttt — just to simplify things a bit.
snippet \ti
\title{${1:My name}}
snippet \te
\texttt{${1:me#email.com}}