Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Find text in a specific column

Tags:

find

vim

When searching for text in Vim (specifically gVim, but it shouldn't matter), how do you specify what column to search? I'm looking for values in one column only.

like image 693
Adam Neal Avatar asked Nov 25 '09 14:11

Adam Neal


People also ask

How do I go to a specific column in vim?

You can use the cursor function. For example, to jump to column 25 of line 15, you can use :call cursor(15,25) . This does give an answer to the question and it's convenient having the Ex command alternative for scripting.

How to find particular word in Vi?

To find a character string, type / followed by the string you want to search for, and then press Return. vi positions the cursor at the next occurrence of the string. For example, to find the string “meta,” type /meta followed by Return.

How to search for a string in vim?

Perform a basic search in Vim If you are in insert mode, simply press the 'ESC' key. To perform a basic search of the string or text that you want, move to the beginning of the file and simply press the forward-slash ( / ) key. Then type the search string and press ENTER on the keyboard to start searching.


2 Answers

Even, if I tend to use the same solution as roe, you can also use \%c -> :h /\%c

EDIT: For those who don't find the documentation very explicit.

Let say my buffer contains

dog
1dog
12dog
123dog
1324dog
12345dog
132465dog

Then, :echo search('\%5cdog') would give me: 5 (the line number 5).

You could also set 'hlsearch' to on -> :set hlsearch and observe the which text matches on /\%5cdog, /\%<5cdog and \%>5cdog

like image 149
Luc Hermitte Avatar answered Oct 01 '22 11:10

Luc Hermitte


If you're talking about character columns, then you might have luck with /^.\{33\}mytext/ which will search your file for 'mytext' beginning at column 34. Note that the number in the search is one less than the column you want (it's matching 33 characters of anything at the beginning of the line, followed by your text).

like image 45
falstro Avatar answered Oct 01 '22 10:10

falstro