How can I set my GHCi prompt to a lambda character on Windows? - windows

I want to have a lambda (λ) symbol as my prompt in GHCi (7.8) on Windows 7, so I set up my .ghci file as
:set +m
:set prompt "λ: "
:set prompt2 " | "
And I set my console font to Lucida Console since it's supposed to support Unicode, but when I load up GHCi, it looks like this instead
How can I get Windows to recognize the λ symbol properly?

Using > chcp.com 65001 worked with GHCi but opening other text files with Vim after setting that encoding returned garbled text.
Add the following to your %USERPROFILE%\.ghci. Instead of changing the encoding, you can use the Unicode escaped lambda \x03BB:
:set prompt "\x03BB: "
If %USERPROFILE%\.ghci does not exist, create it first before making the change.

This is actually quite a simple fix, just run the following command before starting GHCi:
> chcp.com 65001
This sets Window's encoding to the 65001 code page, which lets the λ get displayed properly:
This will also let a lot of other Unicode characters be displayed properly in cmd.exe and other Windows shells (such as Cygwin bash), but Windows' Unicode support is still not perfect, and some fonts don't support many of the characters. Luckily, λ happens to be a supported character so we can all have the classic GHCi prompt.

Using Răzvan Flavius Panda's answer, I decided to make a configuration file that had three flags for setting the prompt. The reason for this is prompt-cont is for GHCi versions >= 8.2.0, whereas prompt2 is for older GHCi versions.
I had a look at a short tutorial about configuring GHCi to try and find out where to put the configuration file. The site says that GHCi reads configuration files in the following order:
./.ghci (Local configuration file.)
Depending on your OS:
*nix: $HOME/.ghc/ghci.conf
Windows: C:\Users\<name>\AppData\Roaming\ghc\ghci.conf
$HOME/.ghci (Possibly *nix only; didn't work for me.)
I chose the second option.
C:\Users\Edwin\AppData\Roaming\ghc\ghci.conf:
:set prompt "\x03BB> "
:set prompt2 "\x03BB| "
:set prompt-cont "\x03BB| "
Explanation:
\x03BB stands for λ.
prompt is the main prompt. So it'll be "λ> ".
prompt2 is for a secondary prompt (I haven't seen it yet). So it'll be "λ| ".
prompt-cont is the same as prompt2, and is a replacement for prompt2 in GHCi 8.2.0.

Related

Why '$p' appears at the first line of vim in iterm?

I'm using Mac OS 10.13.4.
iTerm2 Version is Build 2.1.1
Vim Version is
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 29 2017 18:37:46)
Included patches: 1-503, 505-680, 682-1283
Compiled by root#apple.com
And I Installed the Vundle plugin
And when I open vim in iTerm2 with oh-my-zsh, the $p appears at the first line.
It doesn't appear with Terminal.app of Apple?
How to solve this problem?
vim is assuming that iTerm2 is xterm (not a good assumption), and attempting to determine the state of the cursorBlink resource by sending an escape sequence containing $p which iTerm2 does not handle properly (see source-code for vim for the escape sequence, and also where it uses the feature). While vim starts with the TERM setting (i.e., "xterm"), it does make a few checks to exclude things like gnome-terminal as noted in the source code comment. But iTerm2 happens to fool vim in this case. So the result goes to the screen.
In XTerm Control Sequences that is documented like this:
CSI ? Ps$ p
Request DEC private mode (DECRQM). For VT300 and up, reply is
CSI ? Ps; Pm$ y
where Ps is the mode number as in DECSET/DECSET, Pm is the
mode value as in the ANSI DECRQM.
Two private modes are read-only (i.e., 1 3 and 1 4 ), pro-
vided only for reporting their values using this control
sequence. They correspond to the resources cursorBlink and
cursorBlinkXOR.
Although vim is fooled here, the problem is due to iTerm2, for which you've probably set the TERM environment variable to xterm-256color, or something like that. It doesn't match iTerm2's behavior very well (the function keys don't match up, etc). ncurses provides a better one. But out-of-the-box MacOS has a terminal database that's about ten years old, and lacks that entry. To get a good terminal database (i.e., one where you could set TERM to iterm2), you could do that with MacPorts or home-brew.
Running infocmp to get a measure of the differences between the (correct) iterm2 entry and linux, xterm-256color shows that
it's actually closer to nsterm-256color (a correct entry for Terminal.app which Apple doesn't provide) with 38 lines of difference,
next closest linux with 76 lines and
still further away from xterm-256color with 94 lines.
The feature that's missing or mis-implemented in iTerm2 isn't in the terminal description: it's a special feature that vim has to guess about.
As mentioned above, this $p is due to vim sending a control sequence for a cursor blink request. In your .vimrc, you can turn off the cursor blink request by clearing the t_RC terminal option. I wrapped this in a conditional which turns it off only for 256 color terminals.
if &term =~ '256color'
set t_RC=
endif
Setting the terminal explicitly to linux solved it for me:
export TERM=linux
The p means print, which is the command the range is being given to, and yes.. it displays to you what is in that range.
In vim you can look at :help :range and :help :print to find out more about how this works. These types of ranges are also used by sed and other editors.
They probably used the 1,$ terminology in the tutorial to be explicit, but note that you can also use % as its equivalent. Thus, %p will also print all the lines in the file.

Ruby display unicode character

I'm trying to print out some Unicode characters:
# encoding: utf-8
puts "ử ậ ắ ặ ố ồ"
If I run it through Powershell, this is what I get:
If I run it through cmd, this is what I get:
If I run it in Eclipse (with Aptana Studio 3 plugin), this is what I get:
Is it a problem with my system/software or is it Ruby's problem? How can I get it to work?
It works on Ideone though: http://ideone.com/PdycKH
Ruby supports it no problem, and setting the formatting at the top of the file is the way to go.
The issue is the display via the command line window. You need to use both a font and character page that supports Unicode display.
See this question regarding doing this in the Windows command line.
About the chcp command
I figured it out:
For cmd and Powershell, I have to change the font (I changed to Consolas)
In Eclipse, I have to change the encoding: go to Run/Run configurations, select the Common tab, change the Encoding to Other: UTF-8

macvim shell (:sh) only displays character codes / escape sequences

Just compiled MacVim with homebrew. Here's what it looks like when I :sh and then type ls:
http://cloud.jtmkrueger.com/image/2N0S0T3k3l1J
As you can see, it's just character codes.
UPDATE
I run oh-my-zsh
Tried installing the plugin named here:
http://vim.1045645.n5.nabble.com/ANSI-colors-td1219411.html
Didn't seem to help
ANOTHER UPDATE
Upon removing my zsh syntax highlighting plugin It seems to work ok. Is there a way to turn off zsh plugins when using oh-my-zsh only when it's a vim 'dumb terminal'?
When you do :sh in GVim or MacVim, you don't get a real terminal emulator.
It's "dumb" and there's no way to make it understand those escape sequences. You better get used to it or ask (with convincing arguments and a ready-made patch) on the vim-dev mailing list.
You might want to try the ConqueTerm plugin which does its best to interpret ANSI sequences, even inside MacVim.
Just for the reference, :h guioptions now support the following flag:
'!' External commands are executed in a terminal window. Without
this flag the MS-Windows GUI will open a console window to
execute the command. The Unix GUI will simulate a dumb
terminal to list the command output.
The terminal window will be positioned at the bottom, and grow
upwards as needed.
Set :set go+=!, run :sh, and be surprised :).
What you see is actually not just character codes, but your usual shell prompt which contains color codes. You can probably disable it by redefining PS1 or remove your modified definition in ~/.bashrc.
If you would like to use a color prompt on the command line, but not in MacVim you can fix this in ~/.bashrc by setting PS1 differently when inside vim (from here)
if [ $VIM ]; then
export PS1='\h:\w\$ '
fi
You could try the following, instead of ls, type command ls; it shouldn't show the escapes codes.
If it works you can simple create a new file in a folder in your path, say vls, with the following contents:
#!/bin/sh
command ls $#
after that chmod +x vls and again, if it is in your path, you should be able to use that from vim.

set gvim font in .vimrc file

I am using gVim 7.2 on Windows 7. I can set the gui font as Consolas 10 (font size) from the menu. I am trying to set this in .vimrc file like below:
set guifont=Consolas\ 10
But it doesn't work. Does anyone know how to set this?
I use the following (Uses Consolas size 11 on Windows, Menlo Regular size 14 on Mac OS X and Inconsolata size 12 everywhere else):
if has("gui_running")
if has("gui_gtk2")
set guifont=Inconsolata\ 12
elseif has("gui_macvim")
set guifont=Menlo\ Regular:h14
elseif has("gui_win32")
set guifont=Consolas:h11:cANSI
endif
endif
Edit: And while you're at it, you could take a look at Coding Horror's Programming Fonts blog post.
Edit²: Added MacVim.
Try setting your font from the menu and then typing
:set guifont?
This should display to you the string that Vim has set this option to. You'll need to escape any spaces.
I am trying to set this in .vimrc file like below
For GUI specific settings use the .gvimrc instead of .vimrc, which on Windows is either $HOME\_gvimrc or $VIM\_gvimrc.
Check the :help .gvimrc for details. In essence, on start-up VIM reads the .vimrc. After that, if GUI is activated, it also reads the .gvimrc. IOW, all VIM general settings should be kept in .vimrc, all GUI specific things in .gvimrc. (But if you do no use console VIM then you can simply forget about the .vimrc.)
set guifont=Consolas\ 10
The syntax is wrong. After :set guifont=* you can always check the proper syntax for the font using :set guifont?. VIM Windows syntax is :set guifont=Consolas:h10. I do not see precise specification for that, though it is mentioned in the :help win32-faq.
Start a graphical vim session.
Do :e $MYGVIMRC Enter
Use the graphical font selection dialog to select a font.
Type :set guifont= Tab Enter.
Type G o to start a new line at the end of the file.
Type Ctrl+R followed by :.
The command in step 6 will insert the contents of the : special register
which contains the last ex-mode command used. Here that will be the command
from step 4, which has the properly formatted font name thanks to the tab
completion of the value previously set using the GUI dialog.
For Windows do the following:
Note down the font name and font size from the "Edit-Select Font..." menu of "gvim.exec".
Then do :e $MYGVIMRC
Search for "guifont" string and change it to
set guifont=<font name as noted>:h<font size>
Save the file and quit.
Next time when you execute gvim.exec, you will see the effect.
Although this is an old thread I thought that I would add a comment as I have come across it whilst trying to solve a similar issue; this might help anyone else who may find themselves here:
The backslash character is used to ignore the next character; once added to the font name in my gvimrc it worked; I am on a GNU/Linux machine which does not like spaces. I suspect that the initial post was an error due to the back slash being used on a windows machine.
In example:
:set guifont? ## From gvim command, would give the following:
set guifont=DejaVu Sans Mono for Powerline 11
Where as I needed to add this line to the gvimrc file for it to be read:
set guifont=DejaVu\ Sans\ Mono\ for\ Powerline\ 11
When I try:
set guifont=Consolas:h16
I get: Warning: Font "Consolas" reports bad fixed pitch metrics
and the following is work, and don't show the waring.
autocmd vimenter * GuiFont! Consolas:h16
by the way, if you want to use the mouse wheel to control the font-size, then you can add:
function! AdjustFontSize(amount)
let s:font_size = s:font_size + a:amount
:execute "GuiFont! Consolas:h" . s:font_size
endfunction
noremap <C-ScrollWheelUp> :call AdjustFontSize(1)<CR>
noremap <C-ScrollWheelDown> :call AdjustFontSize(-1)<CR>
and if you want to pick the font, you can set
set guifont=*
will bring up a font requester, where you can pick the font you want.
I had to end up doing
:set guifont=Courier:h10:cANSI
Ubuntu 14.04 LTS
:/$ cd etc/vim/
:/etc/vim$ sudo gvim gvimrc
After if - endif block, type
set guifont=Neep\ 10
save the file (:wq!). Here "Neep" (your choice) is the font style and "10" is respect size of the font. Then build the font - cache again.
:/etc/vim$ fc-cache -f -v
Your desired font will set to gvim.

How can I invoke VIM with C-X e for long, complex, tricky commands?

I found an awesome tip here. You can "[r]apidly invoke an editor to write a long, complex, or tricky command". However, when I press the key combination above, I get Emacs open. I would like to switch it to Vim. How can I invoke Vim with C-X e?
[1. Problem SOLVED by Brian Cambell]
export EDITOR=vim
Add to your .bashrc or appropriate shell rc file
[2. Problem SOLVED thanks to Pax]
I was unable to get the tricky command back to Bash. The errors were:
> Error detected while processing BufRead Auto commands for "*":
> E117: Unknown function: JumpToLastPosition
Quotes in .vimrc solved the second problem. I am still unsure about the part in my .vimrc:
" augroup misc
" autocmd!
" autocmd BufReadPost * call JumpToLastPosition()
" autocmd FileChangedShell * call WarningMsg("File changed outside of vim")
" augroup end
[3. Problem]
What do the above part in .vimrc do?
On most Linux installs (all the ones I tested), bash recognizes both the Emacs and Vi command history keys (or you can use "set -o vi" to force it).
So, you can just use the vi-mode "<ESC>v" to to enter visual mode, this will start editing in a Vim session.
To run the command, you just save and exit from Vim ("ZZ" or ":wq"). To cancel the command, you need to delete the contents, save and exit ("1GdGZZ").
In addition to running it by exiting, you can also save it while in the editor to another location (":w /tmp/myscript").
Keep in mind that visual mode will work with the currently selected line so you don't have to start with a blank command ("<ESC>v"). You can use the normal vi-mode tools to select a line from the history first and then enter visual mode ("<ESC>kv" for last command, "<ESC>/grep<ENTER>nnv" for third-last grep command and so on).
Using this method has the advantage of not changing the "EDITOR" variable which may be used for other things (unless you want Vim for everything, which is a very sensible position to take IMNSHO).
Update:
Regarding your error, posted after the question:
JumpToLastPosition() is the function called by Vim for all files to put the cursor where it was when you last edited the file. I'm going to assume you're actually getting this error when the editing starts, not when you exit, since this is the auto function following a buffer read.
Can you start a "normal" vim session ("vim xx.txt" and then "vim xx") without this error occurring? You may find you get the same problem (and possibly only on the last one).
If you do have the same problem, you need to look at your startup files. It's possible the autocmd for BufRead is broken somehow. Have a look inside your vimrc and you filetype.vim files to see where that function is called and/or defined (I suspect it's called but not defined and that may be a mismatch between the two files or one of them has been damaged).
export EDITOR=vim
Add to your .bashrc or appropriate shell rc file
The link that you provided contains the answer:
Next time you are using your shell, try typing ctrl-x e (that is holding control key press x and then e). The shell will take what you've written on the command line thus far and paste it into the editor specified by $EDITOR.
You need to set the EDITOR environment variable (like #Brian Campbell)

Resources