Quantcast

replace represenation of certain characters with a string of characters?

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

replace represenation of certain characters with a string of characters?

neolus
I couldn't figure out a way to phrase my question but I'm not asking about replacing patterns or anything.
I'd like to know if it's possible in vim to ( visually ) show any certain character as something else. e.g. while editing a text file any occurrence of the character '?' would just look like '<>' but is still the character '?' and nothing is different except what you see. I'm asking because I figured this is impossible but maybe someone out there knows something I don't?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

John Little-4
On Tuesday, March 26, 2013 3:41:25 PM UTC+13, neolus wrote:
> I'd like to know if it's possible in vim to ( visually ) show any certain
> character as something else.

Get yourself a font editor, e.g. fontforge (see fontforge.org, or in the repos for your distro).  (I'm assuming you're running gvim, or vim in a terminal emulator where you can change the font.)

Regards, John Little

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

Christian Brabandt
In reply to this post by neolus
On Tue, March 26, 2013 03:41, neolus wrote:

> I couldn't figure out a way to phrase my question but I'm not asking about
> replacing patterns or anything.
> I'd like to know if it's possible in vim to ( visually ) show any certain
> character as something else. e.g. while editing a text file any occurrence
> of the character '?' would just /look/ like '<>' but is still the
> character
> '?' and nothing is different except what you see. I'm asking because I
> figured this is impossible but maybe someone out there knows something I
> don't?
>

:h new-conceal

This however allows to visually display a portion of a text by a single
other char (not 2 as you asked about).

In your case, you can do:

syn match MyConcealedChar /?/ conceal cchar=Ąę
:set conceallevel=2 concealcursor=nv

See also
:h 'conceallevel'
:h 'concealcursor'

regards,
Christian

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

neolus
In reply to this post by John Little-4
I considered using fontforge that way, only issue is I'm not sure if fonts have particular resrtictions to cell size for each character. For my purposes I'm doing more of a
( replace character with wide character e.g.  from: ? to: <<>> )
kinda thing..
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

neolus
In reply to this post by Christian Brabandt
whenever I tried with two characters vim complained it was an invalid argument.
conceallevel 2 is on but it still won't work with more than one character.
I tried
     hi Special gui=bold guibg=#000000 guifg=#022FEE
     set cole=2
     syn match Container "B" conceal cchar=AE
     syn match Container "B" conceal cchar=Ąę
and it complained. Were you just suggesting I try it? or did you try it and it worked?
I read the help file and it does technically say that 2 still takes one character.
"is completely hidden unless it has a
                        custom replacement character"
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

neolus
In reply to this post by neolus
Also even if fontforge could let me draw a wide glyph doesn't vim only allow monospace fonts anyway?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

John Little-4
On Wednesday, March 27, 2013 2:47:14 PM UTC+13, neolus wrote:
> Also even if fontforge could let me draw a wide glyph doesn't vim only allow
> monospace fonts anyway?

In principle, CJK fonts have double width characters in them.  See, f.ex., :help guifontwide.  However, I have just imparted the totality of my knowledge on the topic.

Regards, John Little

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

neolus
if that's all it's not worth looking into for me, as I in fact want more than just two character width .
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

neolus
I'm sorry to be misleading, from the start I wanted to be able to do this with more than 2 characters ( at least 4 in particular) it seems like I gave the impression that I only needed two.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

John Little-4

> I wanted to be able to do thiswith more than 2 characters ( at least 4 in particular)

Another thought, you could use autocommands on reading and writing the file to change what's seen, like the way vim handles gzipped files.

Regards, John Little

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

Christian Brabandt
In reply to this post by neolus
On Wed, March 27, 2013 02:45, neolus wrote:

> whenever I tried with two characters vim complained it was an invalid
> argument.
> conceallevel 2 is on but it still won't work with more than one character.
> I tried
>      hi Special gui=bold guibg=#000000 guifg=#022FEE
>      set cole=2
>      syn match Container "B" conceal cchar=AE
>      syn match Container "B" conceal cchar=Ąę
> and it complained. Were you just suggesting I try it? or did you try it
> and
> it worked?
> I read the help file and it does technically say that 2 still takes one
> character.
> "is completely hidden unless it has a
> custom replacement character"


If you read my message again, I already wrote, that only a single character
is possible.

regards,
Christian


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

Christian Brabandt
In reply to this post by neolus
On Wed, March 27, 2013 04:46, neolus wrote:
> I'm sorry to be misleading, from the start I wanted to be able to do this
> with more than 2 characters ( at least 4 in particular) it seems like I
> gave
> the impression that I only needed two.
>

How about a different approach and misusing folding:
set fdm=expr fde='>1' fdl=0 foldminlines=0
fdt=substitute(getline(v:foldstart),'vim','EMACS','g') fillchars-=fold

(You might want to adjust the Folded highlighting group. Syntax
highlighting won't be possible though).

regards,
Christian

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

neolus
hi I tried the first command and then the second gave me an error saying

      E492: Not an editor command: fdt=substitute(getline(v:foldstart),'vim','EMACS','g') fillchars-=fold
I also tried the command with
      set fdt=substitute(getline(v:foldstart),'vim','EMACS','g') fillchars-=fold
which didn't complain but nothing happened, ( I typed a g and it was the same? )

Anyway I'd like to keep syntax highlighting if possible so maybe we shouldn't get too much in to this. I have a feeling it won't lead to promising results...

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

neolus
In reply to this post by John Little-4
John Little-4 wrote
Another thought, you could use autocommands on reading and writing the file to change what's seen, like the way vim handles gzipped files.
you mean like running sed on the whole file when opening it and running it again after saving it?
that's basically my "give up plan"
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

Christian Brabandt
In reply to this post by neolus
On Wed, March 27, 2013 16:51, neolus wrote:
> hi I tried the first command and then the second gave me an error saying
>
>       E492: Not an editor command:
> fdt=substitute(getline(v:foldstart),'vim','EMACS','g') fillchars-=fold
> I also tried the command with
>       set fdt=substitute(getline(v:foldstart),'vim','EMACS','g')
> fillchars-=fold
> which didn't complain but nothing happened, ( I typed a g and it was the
> same? )

That was supposed to be typed in one single line (e.g. one single :set
line without linebreaks), probably my mail was wrapped when sending.
You also need to enable folding, e.g. :set foldenable

So in whole type this as 1 single :set statement:
set fdm=expr fde='>1' fdl=0 foldminlines=0
fdt=substitute(getline(v:foldstart),'vim','EMACS','g') fillchars-=fold fen

BTW: You know, that you need to replace vim by the chars you want to be
replaced and EMACS by the chars, that you like to see, right?

regards,
Christian

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

neolus
Christian Brabandt wrote
BTW: You know, that you need to replace vim by the chars you want to be
replaced and EMACS by the chars, that you like to see, right?
no I did not get that before :) thx for explaining.
impressive workaround!
now just to make it more seemless
I only need to figure out a way to get rid of the highlighting and appended '--------'s  
to get what I want now.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

Christian Brabandt
Hi neolus!

On Mi, 03 Apr 2013, neolus wrote:

> Christian Brabandt wrote
> > BTW: You know, that you need to replace vim by the chars you want to be
> > replaced and EMACS by the chars, that you like to see, right?
>
> no I did not get that before :) thx for explaining.
> impressive workaround!
> now just to make it more seemless
> I only need to figure out a way to get rid of the highlighting and appended

What highlighting?

> '--------'s   to get what I want now.

The :set fillchars-=fold should have taken care of that. In any case,
make sure your 'fillchars' setting doesn't include the fold item.

Mit freundlichen Grüßen
Christian
--
Glauben: Dinge für wahr halten, für die es keine Parallele und keinen
Beweis gibt und die jemand verkündet, der über kein Wissen verfügt.
                -- Ambrose Gwinnet Bierce (Des Teufels Wörterbuch)

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: replace represenation of certain characters with a string of characters?

neolus
It's probably just my color scheme I have to fix, thx for all the help Christian!
TSCHÜSS!
Loading...