1

My question is if there is a possible way to hide everything except all text except the current line?


Some background: I have a really big JSON file which I just did a macro on and am doing a quick eyeball to see that everything looks alright.

What I'm currently doing is searching for a specific keyword and going next.

eg: /"Name": and holding n to go to the next result. (dw n is already mapped to nZZ)

This is really useful at the moment, but it's also very distracting to see other information on the top and bottom constantly changing.

Is there a possible way to hide everything except the current line (image for reference)?

Image for reference

  • Resize your window so it's height is that of a single row? ;) – B Layer Apr 5 '18 at 3:33
  • 3
    @BLayer, even better, split and change its height to 1! – Shahbaz Apr 5 '18 at 4:20
  • 2
    How about :g/"Name":/print ? – tivn Apr 5 '18 at 6:29
  • @Shahbaz Yep, you one-upped me. :) – B Layer Apr 5 '18 at 7:57
  • @tivn thanks for your answer it's really good. anyway to print in color? – Pyrons Apr 6 '18 at 0:10
2

I think you can use 'Conceal' feature. For example,

:match Conceal /^.*$/
:set conceallevel=3

All the lines except current one will be concealed. If you do not like the 'Conceal' color,

:highlight Conceal NONE

When you finish, just do

:match
  • Thanks, I believe this is the best answer. Any easy way to do this in a function? – Pyrons Apr 6 '18 at 0:03
  • @Pyrons Just write :function HideOtherLines() on the line before it and :endfunction on the line after it. – Rich Apr 9 '18 at 8:23
0

You could use "vimgrep" to get all the results in a quickfix window and jump to the results you want to.

Not exactly what you're looking for but a workaround.

Example:

vimgrep /"Name":/j | cw

Note: Switch between quickfix window and the buffer using CTRL-W CTRL-W

0

One way to achieve this would be to set all your highlighting groups to have the same foreground ctermfg/guifg and background ctermbg/guibg colours, and then use set cursorline and the CursorLine highlight group to change the colour of the current line.

However, an easier way to do it is to install the Limelight plugin.

You'll need to add the following configuration to your .vimrc in order to make Limelight focus on a single line:

let g:limelight_bop = '^'
let g:limelight_eop = '$'

You can then switch Limelight on and off with the commands:

:Limelight 1
:Limelight!

N.B. The 1 in the command above is an opacity/intensity parameter. If you do not include it, or use instead a value between 0 and 1, then Limelight will dim down the other lines, but not hide them completely.

  • 2
    Okay, that settles it. There is a plugin for everything! – B Layer Apr 5 '18 at 13:06
0

This solution looks simple enough :

:syntax match Ignore /^\(.*"Name":\)\@!.*$/ containedin=ALL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.