text example:
<div> test </div>
test test test
test <div> test
test test test
test </div> test
test test test
I want to select from <div> to </div>.
My search:
<div>\_.\{-}</div>
However..
1) it does not select <div> test </div> on the 1st line.
2) it does select from <div> on the 3rd line but not to the <div> on the 5th line but to the end of the 5th line.
What did I wrong?
in vim try this:
/<div>\_.\{-}<\/div>
you should escape the last /, so that let vim know that it belongs to the pattern.
it is /pattern/{offset}<cr> without the escaping, vim thinks the following chars are offsets.
Update
It works as you expected here. Using relative simple vim config:
https://github.com/sk1418/myConf/blob/master/common/base.vimrc
In the below screenshot, the command line output is from :echo #/ As you see, the highlighted text are exactly what you want.
Here you can use vat
See answer here, or :help at
Related
I have a simple input tags looking like this
<input type="password" name="repassword" placeholder="Enter password">
I want to use Sublime Text 3 and add a aria-label with the same code as in placeholder. The final result I want to be like this
<input type="password" name="repassword" placeholder="Enter password" aria-label="Enter password">
I put this regex inside the Search field <input.*?placeholder="(.*?)"
And this inside the Replace filed <input.*?placeholder=".*?" aria-label="$(1)"
But i end up with this <input.*?placeholder=".*?" aria-label="$(1)">
Update: I have enabled RedEx button in Sublime Text, this is not the problem. As searching is working great.
You have a couple of problems going on here.
The character sequence .*? doesn't have any special meaning in the replacement text, only in the original search. Thus including that in the replacement text just puts those exact characters back. If your intention is to put back the same text that was there originally, you need to capture it like you're doing with the placeholder text as well.
Secondly, the syntax for inserting captured text back is \1 or $1; $(1) is also not special and just injects those characters directly.
To extend your original example, you want to capture the first .*? as well as the second one, and change the replacement text to suit:
Find: <input(.*?)placeholder="(.*?)"
Replace: <input$1placeholder="$2" aria-label="$2"
Note that the first capture is numbered 1, the second 2 and so on.
I want to move cursor to content. I'm using ^ to move to first non-whitespace character, w to first word.
<div class="container">
| <div class="content">
<p>I love you.</p>
</div>
</div>
The pipe (|) shows the cursor position. How can I move it to content word? Like this:
<div class="container">
<div class="|content">
<p>I love you.</p>
</div>
</div>
Depends on a little but on what you want to do, but basically this can be done with:
f"w
f jumps to the char specified next, so f" jumps to the first quote, and the following w moves to the next word.
But usually you don't just want to go there, if you want to insert a word before "content", you can do it directly with:
f"a
If you want to change the content inside the quote just do the following:
ci"
Vim will automatically jump to the next quote.
There are more similar commands, so you should tell us what you want to do exactly!
If you're not on the right line, you can search with: /".\{-}\<\zs\w
Very simple I guess but I cannot get what I perceive to be the correct behavior out of zencoding in vim.
So what I am doing is.
1) selecting using visual a who line.
2) Using <C-e> (rebound) to use zencoding.
3) supply the tags to apply and enter.
What happens is saying using h2 occurs with all.
<h2>
My text
</h2>
However I want it like.
<h2>My Text</h2>
How can I get it like that?
Answer if selecting a line in vim with V (shift+v) zencoding completes a block encoding so "some text" becomes:
<h1>
some text
</h1>
where as using the singular v and then manually selecting text using h,j,k,l the result is inline:
<h1>some text</h1>
If anyone has any other neat tricks let me know.
Let's say I have the following snippet:
snippet divt
<div id="${1:div_id}">
${2:'some text'}
</div>
So when I type divt and hit tab twice "'some text'" should be selected, and when I hit tab once more I would like "some text" to be selected (witoutht single quotes). How can I do it?
Edit 1: Thanks for your answers. Probably this example makes more sense:
snippet divt
<div ${1:id="${2:div_id}"}>
</div>
Sometimes I want a div without an id, so i need to be able to delete the id="div_id" altogether. Sometimes i'd like to have an id, so that i can change div_id part only.
I am currently on a promoting trip for UltiSnips which I am maintaning. The snippet that does precisely that looks like this for UltiSnips:
snippet divt "div" b
<div ${1:id="${2:div_id}"}>
</div>
endsnippet
UltiSnips also comes with a converter script for snipMate snippets, so switching should be painless.
SnipMate unfortunately doesn't support nested placeholders but, as per #Benoit's advice, you could use another snippet while editing the second placeholder. Be sure to bring a spinning top with you, though.
I'm not sure what you want to achieve with some text vs 'some text' — both being treated exactly the same way in this context by every html parser on earth — but I would achieve that with a simple
snippet div
<div id="${1:div_id}">
${2}
</div>
and simply typing either
some text
or
'
which would be expanded to (| is the caret)
'|'
thanks to delimitMate or any other similar plugin then
'some text'
Or maybe use surround to change
some text|
into
'some text'
by typing
<Esc>v2bS'
With Surround you can also start with
some text
select it with
v2e
or something similar and type
S'
to add the quotes then select the line with
V
and type
S<div id="div_id">
to obtain
<div id="div_id">
'some text'
</div>
or do it the other way or... someone has to write a blog post with ALL the possible ways to achieve a given task in Vim.
I'm using Vim's surround and repeat plugins to wrap lines of text with html tags.
I'll use "yse<p>" and "ys$<p>", they both work fine.
I try to repeat the command with ".", and it shows <p> in the terminal, but whenever I press enter to execute the command, surround replaces what should be <p> and </p> with ^M.
My line looks like ^Mtext here^M
I recognize the character as a line ending, but I don't understand why surround won't wrap my line with the code it shows in the terminal (which is correct), but instead wraps my line with DOS line endings.
I'm using gVIM on windows XP, if that makes any difference.
surround.vim's documentation says:
The "." command will work with ds, cs, and yss if you install repeat.vim, vimscript #2136.
So if you are using yss it should work, but apparently other versions of "ys" aren't supported. Sounds like a good feature require to submit to the repeat.vim owner.
It's actually because <p> isn't really there when you repeat the command with .
Try this: Before you repeat the command with . first hit o to empty the command line area of any text, then hit .
You'll see that it is actually blank, which is why the cursor is on the first character.
To repeat the wrapping properly, you'll either have to type in <p> every time or record a quick macro.
Macro: ys$<p>
Paste that into vim, highlight it, and type "py
Now you can run the macro with #p