0

I have a file with long lines and need to see/ copy what the values are in a specic location(s) for the whole file but copy the rest of the line.

If the text width is small enough, ~184 columns, I can use :set colorcolumnnum to highlight the value. However over 184 characters it gets a bit unwieldy scrolling.

I tried :g/\%1237c/y Z, for one of the positions I needed, but that yanked the entire line.

eg for a smaller sample :g/\%49c/y Z will yank all of line 1 and 2 but I want to yank, or copy, the character at that column ie = on line 1 and x on line 2.

vim: filetype=help foldmethod=indent foldclose=all modifiable noreadonly
Table of Contents *sfcontents* *vim*   *regex* *sfregex*  
*sfsearch* - Search specific commands
|Ampersand-replaces-previous-pattern|
|append-a-global-search-to-a-register| 
*sfHelp*  Various Help related commands
Steve
  • 388
  • 1
  • 3
  • 14
  • Can you maybe include an example of what’s in the file you’re trying to copy from? I can’t quite tell from the question what exactly it is that you’re trying to do. – Ben Klein Dec 11 '13 at 02:19
  • Don't think I have the ability to attach files and posting a 1500 character wide example wouldn't do it :) but the answer after yours gave the answer. The file looks like the folloiwn (Nowrap mode) and I want the U on it's own and the final D which in the file are at positions U=56 and D=265, another file has the D at position 1265. 2929122011000000000006410240024097 U 000000 000000 00000000 D – Steve Dec 11 '13 at 22:21

1 Answers1

2

There are two problems with your :g command:

  1. For each matching line, the cursor is positioned on the first column. So even though you've matched at a particular column, that position is lost.
  2. The \%c atom actually matches byte indices (what Vim somewhat confusingly names "columns"), so your measurement will be off for Tab and non-ASCII characters. Use the virtual column atom \%v instead.

Instead of :global, I would use :substitute with a replace-expression, in the idiom described at how to extract regex matches using vim:

:let t=[] | %s/\%49v./\=add(t, submatch(0))[-1]/g | let @@ = join(t, "\n")

Alternatively, if you install my ExtractMatches plugin, I'd be that short command invocation:

:YankMatchesToReg /\%50v./
Community
  • 1
  • 1
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Ingo. Thanks muchly that sorted the issue – Steve Dec 11 '13 at 22:30
  • Ingo I tried to concatenate the YankMatchestoReg as I have several bits I need. I can merge later if necessary but wondering if there is a way to do it. I tried the following where line 1 has D at char pos 265 virtual Attempt 1 YankMatchesToReg /\%5v./x | :YankMatchesToReg /\%265v./X Result of "xp (Result on 1 line) 12M Attempt 2 YankMatchesToReg /\%5v./x then YankMatchesToReg /\%265v./X Result of "xp (Display doesn't show it but results are on separate lines) 1 2 M D Should look like on separate lines 1 D 2 M – Steve Dec 20 '13 at 00:55
  • It's hard to follow (in the unformatted comments) what you want, but the command will always append new matches on separated lines. – Ingo Karkat Dec 20 '13 at 08:49