LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-05-2017, 05:40 AM   #1
negora
LQ Newbie
 
Registered: Feb 2017
Posts: 2

Rep: Reputation: Disabled
In "less", How to show a marker when a line is wrapped?


Hello:

This is my first message here, although I've been reading these forums from time to time for the last years, when I was looking for solutions to some of my problems. So salutes to you all and thanks for your help .

I'm using the command "less" with line wrapping enabled. In the past, I didn't like to use this feature when reading code that used lines longer than 80 characters, because it was hard to follow the flow of the wrapped lines. I only used it when reading prose. So I used the arrows keys to move through the text (a nightmare) or re-formatted the code by hand to fit in the screen. But I've not enough time to re-format all the legacy code that I've to read, so I'm trying to accustom my eyes and brain to line wrapping.

One problem of line wrapping is that it's hard to see where each line starts. In "vim", if I enable the line numbering, this gives me a hint of that. But with "less", enabling the line numbering repeats the line number in each "piece" of the same line. So there's no visual hint (and it performs bad in big files). But is there a way to show a marker in each line start?

I've though of using "view" (a.k.a. "vim -R"; "vim" in read-only mode), but people say that "less" is best for reading big files (logs, for example).

Thank you!

Last edited by negora; 02-05-2017 at 05:44 AM.
 
Old 02-05-2017, 06:18 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 17,982
Blog Entries: 12

Rep: Reputation: 5442Reputation: 5442Reputation: 5442Reputation: 5442Reputation: 5442Reputation: 5442Reputation: 5442Reputation: 5442Reputation: 5442Reputation: 5442Reputation: 5442
read "man less" - if the feature is there, it is there, if it isn't, it isn't.

it is possible to use a different pager, though:
https://duckduckgo.com/?q=linux+alte...ore+less+pager
 
Old 02-05-2017, 06:29 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,989

Rep: Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739
you can also try to use most
 
Old 02-05-2017, 10:47 AM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921
How about cat -n file | less ?
 
Old 02-12-2017, 05:07 AM   #5
negora
LQ Newbie
 
Registered: Feb 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
Apologizes for answering so late, but I've been quite busy.

Thank you all for showing me some alternatives to "less" . I had already discarded using "more" because is very limited for my use. But these days I've been doing some experiments with "most".

I've liked it. It has some features that "less" lacks, such as splitting the window, which may be really useful. This program effectively marks the lines that have been wrapped. What's the problem? That it marks them in the right-most column instead of the left-most column. If you're reading a language that flows from left to right, it's little useful. Because it costs to skip lines quickly. It's a shame, because "most" has some features that are very useful. If I could change the location of that column...

With regard to your solution, Hydrurga, I like it. But I would prefer something that highlighted the line starts. Because, when you're printing the results of a database query, for example, the line numbers mixes with the real numbers of the output and it's complicated to read it.

Just this morning, I've thought about a solution that allows me to highlight each line start. And it seems to work well with the 3 mentioned pagers. It consists in using Perl to inject a coloured marker at the start of each line:

Code:
perl -pe 's/^/\e[01;31m> \e[00m/' <my_file> | less -R
This adds a red bigger-than symbol and a white space, at the start of each line.

Then, with "less", I could even set the LESSOPEN variable to this value, so that it marked the line starts by default:

Code:
export LESSOPEN='|perl -pe "s/^/\\e[01;31m> \\e[00m/" %s'
Thank you.
 
Old 02-12-2017, 05:33 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,989

Rep: Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739Reputation: 5739
nice find. I like it!
If you think your problem is solved please mark the thread solved.
 
Old 02-12-2017, 10:54 AM   #7
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
On my system the -N seems to add 8 characters (line number plus padding) which doesn't seem to get compensated for.

$ COLUMNS=72 less -N .bash_history

You can toggle --chop-long-lines aka -S with [-] [S] [Enter] while less is running. Otherwise [Right Arrow] and [Left Arrow] let you shift over to see extras. The -S options seems to be ON by default. When the line wraps (-S is OFF), and the line number is repeated on the wrapped lines.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
teamviewer "show black screen" and "disable remote input" in x11vnc ? alirezaimi Linux - Networking 1 02-07-2017 02:00 AM
"Line 7 : syntax error near unexpected token ')' and Line 7: "option 1-?")" tiffney2018 Linux - Newbie 5 05-07-2016 03:35 PM
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
[SOLVED] sql: put "beginning of line" and "end of line" within a charset... masavini Programming 7 09-19-2012 08:03 AM
X: video drivers "ati" and "fglrx" show same fonts differently simopal6 Linux - Software 7 07-30-2008 02:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration