1
vote
1answer
11 views

Insert a line of text before lines matching a regex in vim

I'm attempting to add a column to an HTML table using vim so I need to add a pair of <td> tags the line before each </tr>. So far I have :186,$s/ <\/tr>/<td><\/td> \n ...
0
votes
3answers
37 views

set chars to uppercase between parenthesis

let's assume in vim I have following lines: all what (strong) people have to do is pushing (heavy) weights over (and over) again in order to gain muscles and I need to convert words inside ...
3
votes
1answer
42 views

How do you perform a 2d search in vim?

I'm looking for lines in a file that match a 2-dimensional pattern. For instance, given the following input file: aaaba aabaa aaaba aaaaa aaaaa I'd like to use a pattern like ab ba ab to match ...
3
votes
3answers
233 views

Using vim to delete all lines except those that match an arbitrary set of strings

I use vim to remove all lines except those that match a particular string, e.g. :g!/[string that I want to remain in the editor]/d Works great. But what I really want, and haven't found anywhere, ...
0
votes
1answer
40 views

Vim experts: how to find a number within a range based on two numbers? Eg “777” matches “667:888”

I need to search for numbers in a text with Vim. The numbers I need to find are often within a range based on two numbers and I need to match that range based on a single number. For example, in my ...
1
vote
3answers
68 views

Standardize \n and \r in Vim's search/replace syntax

In Vim, one searches for newlines as \n, but newlines in the replacement-string must be entered as \r. I understand that there are reasons for this behavior, but for my purposes I just find it ...
0
votes
1answer
36 views

In Vim, why does searching “/A\n\zsB” work, but not syntax highlighting “:syn match Statement 'A\n\zsB'”?

Assume the following text file: A B Or in other words, a file containing only the string A\nB. Let's see if I can match any B preceded by A and a newline. Simple enough. I can do this sucessfully ...
1
vote
1answer
140 views

How to “reuse” a regex find and replace in Vim

I have a plain text file with entries as firstAuthorLastName_titleFirstWord_YYYY that I change to firstAuthorLastNameYYYYtitleFirstWord with the following s// command in Vim.^[1] ...
5
votes
1answer
123 views

Non-greedy regular expression to convert command tags

Background Consider the following text: There are three types of font families: serif, sans serif, and teletype. To switch between these families, use <cmd>rm</cmd> for serif, ...
1
vote
1answer
84 views

Is it possible to alias regexp substrings in vim?

I want to find and replace pattern containing floating point numbers using vim. I found this nice regular expression for such numbers: [-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? This expression makes ...
1
vote
2answers
104 views

Regex to match only if beginning of line isn't something?

I have some lines that I'd like to match and some lines I'd to exclude from matching in a file. I'd like to not match remote access</a> (main card) and would like to match anything ...
1
vote
1answer
48 views

Vim global block move by patterns

I just came across this example in Learning the vi and Vim Editors: .Rh 0 "Get status of named file" "STAT" .Rh "SYNTAX" ... .Rh "DESCRIPTION" ... .Rh "PARAMETERS" ... The command to move ...
0
votes
1answer
172 views

VIM: Yank multiple non-continous chunks of text into a registers

I have some lines of text that follow a pattern and some that don't. I'd like to copy the lines that follow this pattern and then copy/yank them into a register so that I can paste them as is ...
1
vote
2answers
589 views

vim submatch - trying to put quotes around a string

I'm trying to use the vim submatch command to put quotes around all strings of characters in a line of text, and it doesnt work. Here's what I'm doing :s:\a*\a:\(submatch(0)\):g All it does is ...
0
votes
1answer
352 views

unclear as to what submatch does in vim

Im unclear as to what the submatch({nr}) expression in vim does. The manual says the following: submatch({nr}) *submatch()* Only for an expression in a |:substitute| command. ...
0
votes
1answer
58 views

vim search for strings in bracket

I have bunch of strings like this: [some_strings_in_square_bracket]$ some_strings_not_in .. [some_strings_in_square_bracket]$ some_strings_not_in .. [some_strings_in_square_bracket]$ ...
0
votes
1answer
83 views

Is there a way to filter out filenames from vim's “oldfiles”, perhaps using a pattern?

I use vim's :browse oldfiles a lot to edit files I've recently worked with. However, there are some files, such as git's auto-generated COMMIT_EDITMSG, which clutter that list and which I never need ...
2
votes
1answer
98 views

Vim delete lines that contain word A but not word B

In vim I need to find all lines that contain one word, but do NOT contain another word and delete them. I've seen plenty of :g, :g! and :v talk while trying to figure this out but nothing that gives ...
3
votes
2answers
950 views

Is there a pattern like ^ in vim?

In Vim normal mode, the 0 command takes you to the first column on the line and ^ takes you to the logical start of line (e.g. the first non-whitespace character). In the regex world, ^ matches the ...
0
votes
2answers
621 views

Remove lines not containing a word in Vim

In Vim I often find I'm only interested in lines containing a certain string of text and want to delete all other lines. It's easy to match lines containing a string: :s/^.*foo.*\n// What I ...
0
votes
1answer
70 views

Misbehavior in regular expression in VIM

I am having a problem with a regular expression on vim. I have a pattern as follows: http:\/\/\(\w\+\.\?\)\+ [matches http://(AS MANY WORDS FOLLOWED BY DOT OR NOT ENCOUNTERS) e.g. ...
0
votes
1answer
357 views

Vim regex for selecting everything after column N on a line

I'm looking for a regex that will select all text on a line from the 51st character to the end for lines exceeding 50 characters in length. I need the regex to not include the first 50 characters of ...
0
votes
1answer
54 views

Regex accross multiple files in vim

I need to replace a certain word across multiple files in vim, I've found that I'm able to do it if I open each file in a buffer, but when trying to open all of the files that need replacing vim ...
2
votes
2answers
113 views

Vim regex for wrapping visually selected digits with HTML tags

I have a bunch of text I need to format via HTML, my main problem being that there's a bunch of digits at the beginning of certain words that I need to wrap with HTML tags. I'm trying to think up a ...
1
vote
3answers
133 views

How to remove text from vim

I want to remove all the words that ending with abc Example: 111abc 222def 333abc 444def 555abc 666def From here I want to delete all the words that ending with abc. so I tried this ...
1
vote
1answer
42 views

Jump to the next line that has a statement after an if()

A previous dev liked to put single statements on the same lines as their relevant if()s. I'm trying to find these lines now to fix them! I thought that the following regex would find them, but it ...
2
votes
3answers
99 views

using vims pattern-multi-items {n} to match the 5th space in a line

With this entry from our crontab 1 3 1 * * find /var/log/tomcat/* -mtime +61 -type f -delete I want to match the 5th space char so I can separate the command part from the time field part. Cron ...
1
vote
2answers
2k views

Vim, Find and replace `^(.*)` with `^{.*}`

I'm trying to find and replace caret open_parentheses some_content close_parentheses (i.e.^(.*)) with caret open_curly_bracket the_same_content close_curly_bracket (i.e. ^{.*} but I have issues. 1) I ...
1
vote
1answer
500 views

Find/replace underscored words to camelCase words using regex?

I have a ton of text files that are tagged with underscore-connected words like @some_text, but I would like to convert those to tags in camel case, like @someText. How can I use regex (either in vim ...
0
votes
1answer
152 views

Converting between a vim replace and a perl pie replace

So I have a file test.txt, that contains, home -> range If I edit the file in vim and run the command %s/^\(.*\)->\(.*\)$/\2 ::= \1 ;/g it converts the file to range ::= home ; which is ...
1
vote
2answers
96 views

Vim pattern for replacing ftp links with local

Question I'm going to be sorting through a large mass of html files and replacing links to an ftp site with local links. I am using vim and I am trying to figure out a pattern to use with ...
3
votes
2answers
558 views

How can I find/replace instances of double hyphens (--) with triple hypens (---) in vim?

I know there's probably a way to do that using regex, but I can't quite seem to figure out regex in vim. I tried searching: /-\{2} but it catches triple hyphens, too. I also can't just do a ...
0
votes
2answers
547 views

VI make every first letter that comes after a underscore uppercase

Found this site: http://unix.t-a-y-l-o-r.com/VMswitch.html And it works for the first character but my lines are line this this_is_a_string And I would like this This_Is_A_String Any ...
0
votes
1answer
412 views

Is changing case with regular expression supported in editors other than Vim?

Today I had the need to change all url encoded strings like %BF to lower case ones like %bf. My first reaction is to write some Ruby scripts to do this conversion, and I began to consider use the gsub ...
0
votes
1answer
130 views

How do I create a shortcut for a find and replace command in vim?

I have a vim (well, sed really) find and replace pattern I use for resetting the AUTO_INCREMENT property in mySQL CREATE TABLE statements: :%s/AUTO_INCREMENT=[0-9]*/AUTO_INCREMENT=1/g I use this ...
1
vote
1answer
76 views

Issues with Vim Regex

I have a list of variables I want to compare in the form acceptEncoding == copy. authorization == copy. cacheControl == copy. contentEncodin == copy. contentLength == copy. ... and I want to ...
10
votes
1answer
3k views

vim delete all lines that do NOT contain a certain word

In vim I can delete all lines that contain the word "price" with this :g /price/d How can I delete all lines that do NOT contain the word "price"?
2
votes
3answers
209 views

How to capture the result of a regex-powered command in Vim normal mode?

I want to find the number of times 'x' is present in my file, so I submit %s/x//gn and get the correct answer. How can I capture the resultant count into a variable using vimscript on the ...
1
vote
2answers
404 views

Fast regular expression that checks the number of times a character appears on a line in Vim?

Suppose I have a pipe-delimited text file. I suspect that one of the columns might have an embedded pipe character ('|'). I know there are 8 columns in the file, and each row should have 8-1 = 7 pipe ...
2
votes
4answers
1k views

How to find the line with the maximum number of columns/characters in Vim/gVim?

I'm currently using gVim on Windows XP, and I have 2 follow-ups to my core question: What is the best method of finding the line with the most characters? My current method: I use the regex search ...
7
votes
2answers
5k views

How to search for one of two similar strings in Vim?

This is a pretty simple regex question, I think. In Vim, if I want do a search that matches planA or planB, I know that I can do this: /plan[AB] This works because the regex allows for either A or B ...
3
votes
1answer
801 views

Fix YAML syntax highlighting in VIM

The YAML syntax highlighting in Vim 7.3 isn't great. Putting an apostrophe in a line of text triggers quote highlighting even when there's no quote. The same thing happens in other files sometimes ...
1
vote
1answer
345 views

Add constant value to numeric XML attribute

Background Add a constant value to numbers matched with a regular expression, using vim (gvim). Problem The following regular expression will match width="32": /width="\([0-9]\{2\}\)" Question ...
1
vote
1answer
165 views

How do I find all lines with more than N occurences of a character using Vim

I'm trying to located all lines in a file where the | (pipe) character occurs more than 21 times. The | character is a field delimiter, so there is no specific number of characters that may fall ...
8
votes
4answers
3k views

Can I use perl regular expressions in the vim command line?

I want to use perl regular expressions on the vim command line. For example, to capitalize the words on the current line, you could type: :s/(\w+)/\u$1/g
2
votes
2answers
574 views

How to replace one line in vim?

I have an ipv6 hosts file. No I want to add a comment symbol # to each line that having "google.com.hk". How could I do this in vim? I thought it would be something like ...
8
votes
1answer
2k views

How do I do a block search-and-replace with Vim?

I have text in Vim hit Ctrl+V to put VIm in block mode highlight the text I want type : this gives the this prompt :'<,'> I add to the prompt my regex s/ /*/g. This leaves me with ...
1
vote
2answers
1k views

VIM Regex replacing words

Which regex do I have to use in VIM to replace all words 'to' from a text with the word 'foo'? (I don't want to replace 'to' when it happens in a word like 'together').
0
votes
3answers
214 views

Replace line with only part of the line

I have a large table from Wikipedia (from the wiki source), and I want to extract a single column, I have it open in vim, and what I want to extract looks something like this |col||[[what I ...
5
votes
1answer
691 views

Is there an opposite of :g in vim?

I know how to do something to every line that matches a pattern, using :g. Is there a way to do something to every line that does not match the pattern? For example, suppose I want to delete every ...