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.
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.
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.
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.
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
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With