18

Is it possible to get vim syntax highlighting in ConEmu?

Kariem Ali
  • 203
  • 1
  • 3
  • 7
  • It looks like [ConEmu supports 256 colors](http://code.google.com/p/conemu-maximus5/wiki/Xterm256Colors) so… maybe. What did you try? – romainl Jan 14 '13 at 10:10
  • @romainl I have vim set to use 256 colors t_Co=256 and syntax highlighting turned on. I am using a 256 color scheme, tried several ones. And I followed the instructions in that page. However, code always appears in one color. – Kariem Ali Jan 14 '13 at 10:31
  • This topic seems to be helpfull http://stackoverflow.com/questions/12913392/cant-enable-256-colors-in-conemu – Xavier Jan 14 '13 at 11:51
  • @x4vier Thanks, but that doesn't help. Hopefully we can get an answer from Maximus (the developer of ConEmu) as this seems to be an issue for many and there is no obvious solution for it. – Kariem Ali Jan 14 '13 at 21:46
  • 1
    @romainl It even supports 24-bit palette using xterm sequences I mentioned (had contacted author on habrahabr about the issue) since build 130104 [author comment](http://habrahabr.ru/post/164687/#comment_5671571) [subversion revision](http://code.google.com/p/conemu-maximus5/source/detail?r=1199). – ZyX Jan 15 '13 at 04:39
  • 1
    As far as I can remember, Vim has some troubles with escape sequences in ConEmu. Not finished/polished yet. You may read this topic: https://groups.google.com/d/topic/vim_dev/0H0qM1LJfuk/discussion – Maximus Jan 15 '13 at 08:16
  • Thanks @Maximus for your answer and for ConEmu. Please keep us posted if there is any news on this matter by answering this question or through the ConEmu wiki. – Kariem Ali Jan 15 '13 at 13:41

2 Answers2

31

Note. Some updated information may exists on the project site.

Well, builds since 130120 supports 256 colors in vim. You need to

  • Check options "Inject ConEmuHk" and "ANSI X3.64 / xterm 256 colors" on "Features" page
  • Check option "TrueMod (24bit color) support" on "Colors" page
  • Edit your vimrc file, sample lines are here. Of course, you need some 256-color vim scheme, it is zenburn in the last line of this example.

    set term=xterm
    set t_Co=256
    let &t_AB="\e[48;5;%dm"
    let &t_AF="\e[38;5;%dm"
    colorscheme zenburn
    
  • And "vim" must be vim.exe ATM.

Note. 'Original' Vim (Win32 console executable from gvim##.exe and vim##w32.zip) passed tests. MinGW's Vim fails to switch to using Ansi sequences.

enter image description here

Maximus
  • 10,751
  • 8
  • 47
  • 65
  • 4
    Use `let &t_AB="\e[48;5;%dm"` `let &t_AF="\e[38;5;%dm"`. Why Vim users so like suggesting raw escape codes here or there? – ZyX Jan 22 '13 at 04:21
  • I'm not a "Vim user". Suggesting first found solution that works ;) – Maximus Jan 22 '13 at 06:22
  • Btw, what is the difference between "let &t_AB=..." and "set t_AB=..."? – Maximus Jan 22 '13 at 06:25
  • 1
    First accepts expressions, requires vim compiled with +eval feature, not very ancient version (at least vim-6.0; I have never seen <=vim-5* or without +eval anyway and both are not very usable: except for a few syntax files (but not any syntax file, even some in the vim distribution won’t work) none of the plugins will work without +eval). Second accepts option strings and thus is very inconvenient for any relatively nontrivial option: due to escapes or requirement to use raw control characters. – ZyX Jan 22 '13 at 15:01
  • Thnx for explanations. ATM I ca't switch MinGW's Vim to using ansi sequences. Same config works with "official" and GIT's Vim versions. Can you tell what need to be checked? – Maximus Jan 23 '13 at 14:52
  • Don’t know. And can’t reproduce: ConEmu is not working under wine (launches, but fails to embed anything; apps that are to be embedded are all opened after I close ConEmu) (I have cross-compiled vim and gvim versions using i686-pc-mingw32-gcc for testing purposes). It is much better to ask on vim-dev: the only things I know about vim+windows is how to cross-compile it on linux and how to launch under wine. – ZyX Jan 23 '13 at 17:11
  • 2
    I got colors working. However it seems setting term to xterm breaks arrow keys – Gregory Pakosz Feb 11 '13 at 16:12
  • 1
    Same problem as Gregory. My colors work, but the arrows and number pad no longer work. – Jimbo Jun 05 '13 at 20:23
  • I have wasted, literally, three days with no sleep on this issue, the vimrc lines actually solved the colors issue, thank you so much. – guychouk Oct 21 '16 at 19:21
  • After I did this, I fixed arrow keys with @rxantos answer by writing `set term=pcansi` in my `_vimrc`. After that I also had to fix the symbols with this hack: Go to ConEmu `Settings / Environment` and append `chcp 65001` to arguments. This hack still has a [problem](https://dev.to/mattn/please-stop-hack-chcp-65001-27db) – Armin Bu Jun 02 '19 at 18:50
8

I know is an old question. But what worked for me was similar to the selected answer except that instead of setting term to xterm, set it to pcansi that way the keyboard keys will still work. For ConEmu in the %HOMEPATH%_vimrc

if !empty($CONEMUBUILD)
    set term=pcansi
    set t_Co=256
    let &t_AB="\e[48;5;%dm"
    let &t_AF="\e[38;5;%dm"
    set bs=indent,eol,start
    colorscheme wombat256
endif                      

Manu343726
  • 13,969
  • 4
  • 40
  • 75
rxantos
  • 1,724
  • 1
  • 13
  • 14
  • By %HOMEPATH%, do you mean %USERPROFILE%? – cchamberlain Jul 04 '15 at 21:52
  • In my machine both %HOMEPATH% and %USERPROFILE% leads to the same directory. So I guess yes. – rxantos Jul 04 '15 at 23:32
  • Why does this part matter? Doesn't vimrc simply need to be in $VIM (which may or may not be %USERPROFILE%?). Anyway more to the point are you still using pcansi? I have found that no arrows if use xterm; and colors are weird / specifically background colors where there is not text is the wrong color, if I use pcansi. Oh what to do what to do. Vim is good but it does sponge time! – lgjmac Sep 03 '18 at 09:55