I work a lot with files which contain data on fixed positions. Non-delimited "CSV" files if you will... Often, I'd like to highlight a specific column.
I tried
:match ErrorMsg /\%>30v.\+\%<40v/
but this runs extremely slow and only matches the first line. I suppose the file may be too large for this. Mind you, the files are very wide (around 40000 characters) but not very long (around 2000 lines). The data originates from old tools over which I have no control.
Example file:
63082
01089
75518 735301
53473 017146
37217
07
940376
762 2842
88331
40680 8928
645718
0131
03522
47210 27431
93837
8825072 49479415
52084 8940
0591705 205635
525429
65339 300
0397
1983
0
2605768
121991 648
3892
1260
Any ideas?
Are you using Vim 7.3?
Apparently they just recently added a colorcolumn option.
Try:
:set colorcolumn=31,32,33,34,35,36,37,38,39
Note that :help 'colorcolumn' says "Will make screen redrawing slower". I somewhat replicated your scenario, though, by using pure blocks of 1234567890 with the exact repetition count you specified.
The command you mentioned is very slow. colorcolumn isn't.
but this runs extremely slow and only matches the first line
By "first line" do you mean the first displayed line, when word wrapping is enabled? Unfortunately colorcolumn will exhibit the same behavior...
This is off the original topic, but Google leads people here. When trying to fix a horribly indented YAML or any other swiftwidth=2 file, I really struggle to visually recognize what is and isn't in a valid column. A comment by #ib to the accepted answer lead me to this gem.
:let &l:colorcolumn = join(range(3,15,2),',')
It basically says set colorcolumn to the comma delimited string value of 3 through 15 counted by 2. (In other words: :set colorcolumn=3,5,7,9,11,13,15) The result looks like this:
You can do a simple :set colorcolumn to see what value results.
To get rid of it do :set colorcolumn=
Related
I have added the set nu to my vimrc file, and I like it, but I would like to have vim start with line number 0 (it's to match the samples from a book I am using to learn C++).
I saw a suggestion to change set nu to set rnu, and at first it looked good, until I moved downward, and the 0 moved with my cursor. I understand what's going on here - it's displaying a 0 for my current position, and the lines above and below are renumbered relative to where 0 is. While cool, this is not what I want.
Thanks in advance!
Shane
This is not possible without patching the source.
Note that, in Vim, line numbers can be used in many more ways than in "regular" editors so changing how the line numbers are displayed will have a non-negligible impact in other areas. This doesn't seem like a very good idea.
I am using
set relativenumber
set number
which let's me move easily around. However, it is often hard to know the exact the line number of the object where I would like to jump to because I first need to look to the left. I feel it would be easier if I could see the line numbers also on the right hand side right because my eyes have less space to follow (maybe?). I think the ideal setting would be to show the relative/absolute line number where the $ appears when whitespace characters are shown and to the left/right of the buffer. I.e.
1 Random text.$1 1
159 This is the line where the cursor is.$159 159
1 Some random text.$1 1
2 More random text. Another sentence. Maybe a third one? And so on.$2 2
3 Another line which might be quite long and my eyes focus somewhere here.$3 3
4 More random text containing more text and more words and stuff.$4 4
(In this example, I would like to do 3k but I may type 2k or 4k because I did not follow the correct line to the left.)
Is it possible to achieve this somehow?
Any suggestion on how to change my workflow are welcome, too.
Note: Using cursorline does not help as I do not seek the number of the current line.
No, there is no built-in support to your requirement. also I don't think this is easy to be done by plugin.
Maybe you could consider to change your habit/workflow. E.g. enable the cursorline option, to highlight your "current" line, it may let you easier to identify which line are you on right now.
To move cursor, if you don't want to count lines, you may want to try the EasyMotion plugin. It is very handy plugin. However it won't replace the hjkl ... motions.
No, that's not possible, unless you modify Vim's source code in a non-trivial way, or work around with kludges like a vertically split small scratch buffer at the side that is updated via autocmds.
Do you have :set cursorline? That helps (me) a lot to follow the current line, even with large window widths. Reducing those might help, too, though you have to deal with wrapping / scrolling of long lines then.
I want to count lines in a range, not matter what range, but let it be, say, a visual block.
What is the shortest way to do it. All that comes to my mind is something like: '<,'>s/.//n
but I don't believe it is the shortest way.
So, can somebody give me a hint?
In visual mode, press gC-g
Typical output:
Selected 7 of 22 Lines; 8 of 32 Words; 201 of 491 Chars; 201 of 497 Bytes-- VISUAL LINE --
Source: :he count-items (discoverable as: :heTabTab...)
Set the option showcmd (:h 'sc'), and you will never ever need to type anything to know how many lines are selected -- at first, as I forget that I've set this option, I didn't understand the point of your question. ^^'
Otherwise, if you want to obtain that number programmatically, it's simply:
:echo line("'>") - line("'<") + 1
From within a range-function, it can also be obtained by a:lastline-a:firstline+1. (:h function-range-example)
'<,'>s///n is one character shorter. :-)
If I just want to know the number of lines in a visual selection I usually just yank it (hit y). It'll say "5 lines yanked" or "block of 5 lines yanked" depending on the type of selection.
When working with positional data files, it is often very useful to highlight a specific column. In such files it is quite common to have huge "areas" filled with spaces (or NULL values) and only very sparse data points. In such cases it becomes difficult to read the file.
Here's an example excerpt:
462
63082
01089
75518 735301
53473 017146
37217
07
940376
762 2842
88331
40680 8928
645718
0131
03522
47210 27431
93837
8825072 49479415
52084 8940
0591705 205635
525429
65339 300
0397
1983
0
2605768
121991 648
3892
1260
I found it helpful to simply highlight a specific column. At first I tried to use a regular :match, but this turned out to be way to slow on huge data files. I posted this as another question. The answer is simple. cursorcolumn (available since vim 7.3) can be set to a range and is a lot faster as it does not need to match the characters.
Implementing the proposed solution I saw it working. But it's cumbersome, and - knowing vim - there should be an easier way to specify this.
Question:
Is it possible to set the cursorcolumn range to the columns of the currently selected (visual) block?
It turns out it's very simple. The function getpos can retrieve the position of any marker. We'll use this to extend the solution to the earlier problem:
:let &l:cc = join(range(getpos("'<")[2], getpos("'>")[2]),',')
Now, we can map this easily:
:vnoremap <F5> <ESC>:let &l:cc = join(range(getpos("'<")[2], getpos("'>")[2]),',')<CR>
So, now when editing a positional data file, we'll simply have to enter visual mode, select the portion of the file we need highlighted and press F5
I noted that the 'showbreak' symbol is highlighted with the highlight "NonText" color-element. NonText is also used for the EOL Characters.
I would like to keep the highlight-color for the EOL characters but want to change it for the showbreak symbol is that possible?
Another problem is that my showbreak symbol is not displayed.
I would like to use this symbol "↳" and put it in the linenumbers column (using set cpoptions+=n). I can't find out how to display the symbol and how to put a space after the showbreak symbol (between the text and the symbol).
Can anyone help me?
I don't think you're going to get highlighting to be different than the EOL character, at least I am not aware of a way to do that.
For the second part I can help with. I was able to get "↳ " to show up in my line number column with the following settings:
let &showbreak = '↳ '
set wrap
set cpo=n
Note that there is a space after the ↳. This lines up nice until you have > 9 lines in the file. If you wanted it to line up with the last character of the number column regardless of the number of lines I'm not sure what you're going to have to do.
Edit: I've recently written a proof-of-concept function for someone on IRC that highlights the first character on a line that has been wrapped with a different highlight group. It hasn't been tested much but it seems to work. Not exactly what you're looking for but maybe it's worth a look.
:help hl-NonText makes it pretty clear that you cannot have different colors for the 'showbreak' string and other non-text strings, of which eol is a member (see :help 'listchars'):
NonText
'~' and '#' at the end of the window, characters from 'showbreak' and
other characters that do not really exist in the text (e.g., ">"
displayed when a double-wide character doesn't fit at the end of the
line).
If you're willing to accept this limitation (#elliottcable) hi! link NonText LineNr will match the 'showbreak' string to the line number colors.
If you really wanted to get clever, as a compromise you could create a mapping or command to toggle between ':set list' and ':set nolist' that would also adjust the NonText highlight setting simultaneously.
If you use :set relativenumber (added in vim 7.3), :set showbreak=↳\ \ \ will reliably keep your 'showbreak' neatly lined up since the number width will not change as you navigate through the file. (This in addition to the :set cpo+=n and :set wrap #Randy Morris mentioned in his answer.)
You'll definitely need UTF-8 for the ↳ character, since it does not appear in other encodings. I'd strongly recommend you carefully document your encoding problems, with details about how to reproduce them along with your OS, its version, and the :version output of vim, and post them as separate questions. UTF-8 should be helping you wrangle multiple languages rather than being an impediment.