Delete until second forward slash in vim - vim

I would like to delete https:// from a url
Here is a sentence with the url https://www.google.com.
Should be replaced with
Here is a sentence with the url www.google.com.
I would think the motion is dt2/ but that doesn't work because / is a special character.
What is the shortest way to delete https:// here?

You have the count and motion backward, you need d2t/. til is a motion, and can be done any count of times. t2 just means "go to the next 2".
Also, til only goes up until the second slash. If you want to delete the second slash as well, use find inline as in d2f/.

Related

Change going forward and backward when searching for a character in a line

When I use vim to find a letter in a line I use the f key and then to repeat the motion forward I have to use ; and to repeat the motion backwards I have to use ,. However, I would like to do change this and go forwards with , and backwards with ;. What exactly would I have to put in my vimrc?
You don't need to put anything in your .vimrc; this already exists. You may need to change the way you search for characters though.
If you use f and t to search for characters, ; goes forward, while , goes backwards.
However…
If you use F and T to search for characters, , goes forward, while ; goes backwards.

Remove qutation mark sring from URL with HTACCESS

We are seeing a strang thing where bots are sending odd URLs. They are adding an alexa URL in the url we have. We are looking to remove that part of the URL so it just has everything before the odd URL addition
So we want to go from
www.example.com/search/Linux/page/6/”http:/www.alexa.com/siteinfo/www.example.com“/page/900
to
www.example.com/search/Linux/page/6/
removing the: ”http:/www.alexa.com/siteinfo/www.example.com“/page/900
Due to it having the quotes, we I am unsure what htaccess rule would work to rewrite the URL, but am open to suggestions.
Not sure where the requests are coming from, only see them with our 404 monitor.
If these requests are triggering a 404 (as they should be) then you are essentially already "blocking" such requests - they won't get inadvertently indexed by search engines.
However, if a third party side is mistakenly linking to you with these erroneous links then you might be losing traffic. You can redirect to remove the erroneous portion of the URL.
Due to it having the quotes, we I am unsure what htaccess rule would work to rewrite the URL, but am open to suggestions.
There's nothing particularly special about matching quotes in the URL. However, the quotes used in your question are not the "standard" double-quotes. The opening quote is "U+201D: RIGHT DOUBLE QUOTATION MARK" and closing with "U+201C: LEFT DOUBLE QUOTATION MARK". This is not a problem, we can check for all three.
For example, using mod_rewrite at the top of the .htaccess file to remove the part of the URL from the first quote character onwards:
RewriteEngine On
# Remove everything from the first double quote onwards
RewriteRule ^([^"”“]+)["”“] /$1 [R=301,L]
The $1 backreference contains the part of the URL-path before the first double quote character.
The original query string (if any) is preserved.
Test first with a 302 (temporary) redirect to avoid potential caching issues.
Alternatively, if your URLs are limited to a known subset of characters, eg. a-z, A-Z, 0-9, _ (underscore), - (hyphen), / (slash - path separator) then check for valid chars instead. For example:
# Remove everything from the first "invalid character"
RewriteRule ^([\w-/]+)[^\w-/] /$1 [R=301,L]

VIM: How to delete 3 words from the end of line in normal mode?

What is the shortest combo?
P.S. I usually do ACtrl+wCtrl+wCtrl+wEsc.
In other words, I have to jump into Insert mode.
P.P.S. d3b doesn't work.
This sequence of commands,
$3bD
is the shortest way to do it I can think of at the moment but it leaves out an ugly trailing space.
$3gelD
is another way that gets rid of the trailing space.
You can also think outside the box and play with spaces instead of words:
$3F D
$ 3b D which translates to
$ to the end of a line
3 three of whatever is next
b backward three [one without modifier] words
D delete the characters under the cursor until the end of the line
In addition, you can also use the normal command in ex mode to achieve the same
:norm! $3bD
$3bD
Or
$3bDx
...if you also want to delete the trailing space.
Go to the end of the line, go back 3 words, then delete to the end of the line: $ 3b D
or
Go to the end of the line, delete back 3 words, then delete the extra character: $ 3db x
As others have mentioned, $3bD is the shortest, and $3bDx will suffice to remove the remaining whitespace, assuming it's exactly one space or tab.
In order to account for all whitespace, $3gelD can be used. This option has the benefit of cleaning up properly in most cases, but it fails when a line contains exactly 3 words because the 3ge motion jumps back to the previous line.
An alternative approach is based on daw. Since 3daw acts forward, either $daw.. or $3b3daw must be used. For 3 words, $daw.. is shorter and probably more desirable, but $3b3daw is more Vim-esque and can easily be extended to more words.
b, ge, and w can be replaced with B, gE, and W in order to remove WORDs instead of words.

Vim: delete until character for all lines containing a pattern

I'm learning the power of g and want to delete all lines containing an expression, to the end of the sentence (marked by a period). Like so:
There was a little sheep. The sheep was black. There was another sheep.
(Run command to find all sentences like There was and delete to the next period).
The sheep was black.
I've tried:
:g/There was/d\/\. in an attempt to "delete forward until the next period" but I get a trailing characters error.
:g/There was/df. but get a df. is not an editor command error.
Any thoughts?
The action associated with g must be able to act on the line without needing position information from the pattern match that g implies. In the command you are using, the delete forward command needs a starting position that is not being provided.
The problem is that g only indicates a line match, not a specific character position for it's pattern match. I did the following and it did what I think you want:
:g/There was/s/There was[^.]*[.]//
This found lines that matched the pattern There was, and performed a substitution of the regular expression There was[^.]*[.] with the empty string.
This is equivalent to:
:1,$s/There was[^.]*[.]//g
I'm not sure what the g is getting you in your use case, except the automatic application to the entire file line range (same as 1,$ or %). The g in this latter example has to do with applying the substitution to all patterns on the same line, not with the range of lines affected by the substitution command.
I'd just use a regex:
%s/There was\_.\{-}\.\s\?//ge
Note how \_. allows for cross-line sentences
You can use :norm like this:
:g/There was/norm 0weldf.
This finds lines with "There was" then executes the normal commands 0weldf..
0: go to beginning of line
w: go to next word (in this case, "was")
e: go the end of the word (so cursor is on the 's' of "was")
l: move one character to the right (so we don't delete any of "was")
df.: delete until the next '.', inclusive.
If you want to keep the period use dt. instead of df..
If you don't want to delete from the beginning of the line and instead want to do sentences, the :%s command is probably more appropriate here. (e.g. :%s/\(There was\)[^.]*\./\1/g or %s/\(There was\)[^.]*\./\1./g if you want to keep the period at the end of the sentence.
Use search and replace:
:%s/There was[^.]*\.\s*//g

how to rewrite in a htacess file

im into SEO and friendly URL's and im trying to create a rule in my htacess file and i need help...
Basically, i have a list of alphabet letters. If the users selects one letter, the db will show all the lyrics that starts with that letter...
so if i click C, there will be a list of lyrics and the the first is 'Car and blues'
So, from this
htpp://www.website.com/lyrics.php?letter=C
i want to do this:
http://www.website.com/lyrics/C/
so far, this is what i have
RewriteRule ^lyrics/$ /lyrics.php?letter=$1 [L]
the rule should be smart enough to pick everything that comes after 'lyrics', in between the 2 slashes, and not what comes after...
Thanks
the rule should be smart enough to pick everything that comes after 'lyrics', in between the 2 slashes, and not what comes after...
Your rule as it stands is looking for exactly lyrics/ with no possibility of anything before or after it (as defined by the ^ and $).
Assuming you're using letters A-Z in only capitals, you can use this:
RewriteRule ^lyrics/([A-Z])/?$ /lyrics.php?letter=$1 [L]
This will look for a single capital letter after the lyrics/ and send that value to the rewrite URL and also match both cases of having a trailing / or not.
the rule should be smart enough to pick everything that comes after
'lyrics', in between the 2 slashes, and not what comes after...
I'd suggest you look into using regular expressions to format your url. See this link

Resources