LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to highlight text in vi editor (https://www.linuxquestions.org/questions/linux-general-1/how-to-highlight-text-in-vi-editor-466533/)

Gins 07-22-2006 09:28 AM

How to highlight text in vi editor
 
I need some help from our experts about the vi editor. I used it everyday.

If you write letter using the wordprocessor, you can make certain sentences or passages in different colors.

I want to do the same thing in the vi editor. I would like to make some sentences with bigger font size.

The reason is I want to highlight certain facts in my letters.

These things are so easy in your wordprocessor. I use the Open Office wordprocessor.

Please tell me how to make changes to certain sentences in vi editor.
This may be an impossible task.
Your comments are welcome.

phil.d.g 07-22-2006 09:56 AM

Vi isn't a word processor, it is a text editor. Think of vi as notepad on steriods. vi is the wrong tool for your specific purpose, you should stick with a word processor. You can of course learn a markup language such as latex and write your letters in vi and use latex commands to specify formatting.

Reference: http://www.latex-project.org/

Gins 07-22-2006 10:57 AM

Thanks phil for taking time to reply me. This is for the first time I heard a bout LaTeX.

It may be already installed on my Linux system. I am using Mandriva Linux 2006 version. It is a 64 bit program.

Do you know how to find out whether it is installed by default?

jlliagre 07-22-2006 11:25 AM

That depends too on the format of the file you are editing.

If this is html, you can use the font tag, eg:
Code:

normal text <font color="red">some red text</font> normal text again
If it is plain text to be displayed in a terminal, you can use ansi escape sequences, eg:
Code:

normal text  ^[[31msome red text^[[31m normal text again
Unfortunately, vi (or vim) won't assist you entering these tags or sequences.

phil.d.g 07-22-2006 11:32 AM

Just to make it clear vi won't then render the html or interpret the shell escape commands, they will always appear as jlliagre wrote them. However a browser will render the html and you'll get your formatted text.

In the same way once you have written your latex source file it needs compiling into some format of your choosing.

I'm unfamiliar with Mandrake, use your package manager tools to find out if it is installed.

Gins 07-22-2006 12:00 PM

I thank both of you for taking time to reply me.

I always write a small note using the vi editor. For example, this linuxquestions.org website's username and the password is stored in a vi file.

Some files are just 4 or 5 lines. Some are 2 or 3 page long letters. So I want to highlight some sentences in those files.

I find the vi is very convenient. I have been using it for more than 5 years.

I know the files of html nature works fine to write big or colored letters. I have been writing webpages or rather html pages using the vi editor.

As phil mentioned, the vi is not a wordprocessor. It is a note-pad.

The alternative may be that I wrote everything using html format. That is rather cumbersome. I need something quick. It takes time to write those html tags and related stuff.

I never learnt to work with the vim program. Is it better than the vi editor?
Has it better function than the vi editor?

On the other hand, I can't use the simple 'cat' command to see all the highlights in the vi editor.

As phil mentioned, I must use the webbrowser to see the html pages. That is cumbersome.

phil.d.g 07-22-2006 12:48 PM

Maybe this will help you understand:

Write a letter in openoffice, or some other word processor and add colours, different fonts and sizes to it. Save it as an rtf "Rich Text Format" file . Go and open that file in vi. Other document formats will not work because they are saved in a binary format.

vi just works with plain text documents, it knows nothing of formatting, colours and what have you. When you write your document in a wordprocessor all the formatting must be saved along with the actual text as demostrated by the above test. vim does the same job as vi, it just has more features, but none that make it act like a wordprocessor.

You either need to learn a markup language and in vi use the markup tags to specify the structure of your document, or use a word processor and WYSIWYG techniques.

Edit: Again cat just deals with plain text, it reads a character from a file and prints it on stdout (normally your console). OK its a little more complex than that but thats beyond the scope of this thread, but it does not parse the file for formatting instructions.

jlliagre 07-22-2006 01:23 PM

I'm using elvis instead of vim as my preferred vi clone, it has the ability to properly render some text formats like html, tex and nroff manual pages.
You still need to enter the formatting commands manually though.

Gins 07-22-2006 01:36 PM

Thanks Phil for the reply.

I wrote a letter using the Open Office and saved as a .rtf file.

I named it ' Rubbish2001.rtf '

Then I opened it on the vi editor. Please see the following.

\hr20\min24}{\revtim\yr2006\mo7\dy22\hr20\min26}{\printim\yr1601\mo1\dy1\hr0\min0}{\comment StarWriter}{\vern6450}}\deftab709
{\*\pgdsctbl
{\pgdsc0\pgdscuse195\pgwsxn12240\pghsxn15840\marglsxn1800\margrsxn1800\margtsxn1440\margbsxn1440\pgd scnxt0 Default;}}
\paperh15840\paperw12240\margl1800\margr1800\margt1440\margb1440\sectd\sbknone\pgwsxn12240\pghsxn158 40\marglsxn1800\margrsxn1800\margtsxn1440\margbsxn1440\ftnbj\ftnstart1\ftnrstcont\ftnnar\aenddoc\aft nrstcont\aftnstart1\aftnnrlc
\pard\plain \ltrpar\s1\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af4\afs24\lang255\ltrch\dbch\af3\afs2 4\langfe255\loch\f0\fs24\lang1033
\par
\par \pard\plain \ltrpar\s1\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af4\afs40\lang255\ltrch\dbch\af3\afs4 0\langfe255\loch\f0\fs40\lang1033 {\loch\f0\fs40\lang1033\i0\b0 Ffjf\'f6lfj\'f6lsfk\'f6ldsf\'f6k\'f6k\'f6}
\par
\par \pard\plain \ltrpar\s1\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af4\afs24\lang255\ltrch\dbch\af3\afs2 4\langfe255\loch\f0\fs24\lang1033 {\loch\f0\fs24\lang1033\i0\b0 jfsjflsfdfls}
\par
\par \pard\plain \ltrpar\s1\cf2{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af4\afs24\lang255\ltrch\dbch\af3\afs2 4\langfe255\loch\f0\fs24\lang1033 {\loch\f0\fs24\lang1033\i0\b0 fms\'f6fdm\'f6dlsaf\'f6ds}
\par \pard\plain \ltrpar\s1\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af4\afs24\lang255\ltrch\dbch\af3\afs2 4\langfe255\loch\f0\fs24\lang1033
\par \pard\plain \ltrpar\s1\cf3{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af4\afs32\lang255\ab\ltrch\dbch\af3\a fs32\langfe255\ab\loch\f2\fs32\lang1033\b {\loch\f2\fs32\lang1033\i0\b f\'f6\'e4f\'e4\'f6dsfl\'e4sdf\'e4'sdf'ds'\'e4s}
\par
\par
\par
\par }
~
"Rubbish20001.rtf" 26L, 2975C

-----------------------------------------

It saved as a binary file though I saved as a .rtf file.

phil.d.g 07-22-2006 01:54 PM

Nope, thats right. If you scroll down you'll start to see the text you entered in OpenOffice. Those tags and keywords are instructions to specify the structure and formatting of your document. As you can see vi hasn't interpreted them and formatted your text appropriately it just shows the keywords as text.

Hold on, did you write nonsense in your document. Are these strings from it:
Quote:

Ffjf
Quote:

jfsjflsfdfls
OK, this definately is a string from it
Quote:

föäfäödsfläsdfä'sdf'ds'äs
Using non-ascii characters and random strings makes spotting your text even harder.

phil.d.g 07-22-2006 02:21 PM

Quote:

Originally Posted by jlliagre
I'm using elvis instead of vim as my preferred vi clone, it has the ability to properly render some text formats like html, tex and nroff manual pages.

I did not know that. I don't know the roadmap for elvis but I suppose being able to render some formats is half way to having a WYSIWYG editing capacity.

Gins 07-22-2006 04:28 PM

Phil

I wrote nonsense; you are 100% correct. This is a trial. However, now it is too late here. I must sleep. I would attend this again tomorrow.

Are you based in the USA?

phil.d.g 07-23-2006 02:16 AM

No, England.

Gins 07-23-2006 11:24 AM

Phil

Out of context, I wonder whether it is common to use Open Source operaing systems in England. I mean the home users. Here it is very rare. If I ask 100 people, I wouldn't find a single individual who uses any Open Source at their home computers.

However, I know 2 people who uses Open Source operating systems. One uses Free BSD and the other uses Linux.

I have Windows XP. I look at it once a week.

phil.d.g 07-23-2006 01:56 PM

Well, seeing as your taking your own thread off topic I suppose it doesn't matter :cool:

---

I don't really know. Certainly with people I know who do Computer Science degrees it is reasonably popular, but I don't know anyone who uses a computer as a means to an end that uses Linux. However in other parts of England the case may be different, its a funny country like that. When I was at sixth form college (16 to 18 years old) I knew only one person that used Linux.

The rest of my family won't touch my machines, they'll only use Windows.


All times are GMT -5. The time now is 05:04 AM.