5

I'm using Vim on a machine through SSH with PuTTY.

In my shell (bash), I can copy/paste unicode characters, like ‘ ¿ ’ using Shift + Insert and it works as expected. In Vim, within the same shell session, however, I get this instead.

▒~@~X¿▒~@~Y

Pulling up :digraphs shows that this is happening with all unicode characters.

I have this in my vimrc:

set encoding=utf-8
set fileencoding=utf-8

And here is the output from the locale command:

LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_ALL=en_US.UTF-8

Why can I not use special characters within Vim when they work fine on the command line?

Edit: The remote character set in PuTTY is set to UTF-8.

Edit 2: Output from vim --version

VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Feb 22 2009 06:30:54)
Compiled by steve@v480
Normal version with GTK GUI.  Features included (+) or not (-):
-arabic +autocmd +balloon_eval +browse +builtin_terms +byte_offset +cindent
+clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
+cryptv +cscope +cursorshape +dialog_con_gui +diff +digraphs +dnd -ebcdic
-emacs_tags +eval +ex_extra +extra_search -farsi +file_in_path +find_in_path
+float +folding -footer +fork() -gettext -hangul_input -iconv +insert_expand
+jumplist -keymap -langmap +libcall +linebreak +lispindent +listcmds +localmap
+menu +mksession +modify_fname +mouse +mouseshape -mouse_dec -mouse_gpm
-mouse_jsbterm -mouse_netterm -mouse_sysmouse +mouse_xterm -multi_byte
+multi_lang -mzscheme +netbeans_intg -osfiletype +path_extra -perl +postscript
+printer -profile -python +quickfix +reltime -rightleft -ruby +scrollbind
+signs +smartindent -sniff +statusline -sun_workshop +syntax +tag_binary
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
 +toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo
+vreplace +wildignore +wildmenu +windows +writebackup +X11 -xfontset +xim
+xsmp_interact +xterm_clipboard -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -I/usr/local/include/gtk-1.2 -I/usr/local/include/glib-1.2 -I/usr/local/lib/glib/include -I/usr/X11R6/include -I/usr/openwin/include -I/usr/local/include -I/usr/local/ssl/include -I/usr/local/pgsql/include -I/usr/local/include/ncurses -I/usr/local/BerkeleyDB.4.2/include -I/usr/openwin/include -I/usr/local/rrdtool-1.2.19/include  -O2 -L/usr/local/pgsql/lib -R/usr/local/pgsql/lib -L/usr/local/lib -R/usr/local/lib -L/usr/local/ssl/lib -R/usr/local/ssl/lib -L/usr/openwin/lib -R/usr/openwin/lib -I/usr/local/rrdtool-1.2.19/include  -I/usr/X11R6/include -I/usr/openwin/include
Linking: gcc  -L/usr/X11R6/lib -R/usr/X11R6/lib -L/usr/openwin/lib -R/usr/openwin/lib   -L/usr/local/lib -R/usr/local/lib -R/usr/lib -L/usr/local/pgsql/lib -R/usr/local/pgsql/lib -L/usr/lib -R/usr/openwin/lib -L/usr/openwin/lib -L/usr/local/ssl/lib -R/usr/local/ssl/lib -L/usr/local/BerkeleyDB.4.2/lib -R/usr/local/BerkeleyDB.4.2/lib -L/usr/X11R6/lib -R/usr/X11R6/lib -o vim   -L/usr/local/lib -L/usr/X11R6/lib -R/usr/X11R6/lib -L/usr/openwin/lib -R/usr/openwin/lib -lgtk -lgdk -lgmodule -lglib -lintl -lXext -lXt -lX11 -lSM -lICE -lm -lncurses -lnsl -lsocket
  • Try this on the command line - set guifont=Lucida_Sans_Typewriter:h10:cANSI. I was having the same problem until I changed the font. ¿ displays in this font – Steve Apr 11 '16 at 13:19
  • That has no effect (I wouldn't expect it to have an effect, since vim is being through through SSH without a gui. The font being used with PUTtY can display special characters, as I am able to see these in bash) – Scribblemacher Apr 11 '16 at 14:29
  • 2
    Does this happen even if you start with vim -Nu NONE? What is the output of vim --version? – muru Apr 12 '16 at 13:41
  • 1
    That's a bit of an ancient version of vim - I also noticed -multi-byte in that compile flag list; mine's +multi-byte, so my best guess is that your problem is there. You said below you're on Sun OS, which I'm not all that familiar with; perhaps it has a package manager you can go through to update/alter vim, or perhaps you can recompile it yourself on that machine. – ZeroG Apr 12 '16 at 14:23
  • I've added the output from vim --version to the question. Yes, the issue does persist with vim -Nu NONE – Scribblemacher Apr 12 '16 at 14:23
2

I tried this on my linux box via putty and via cygwin, both seemed to work as expected for me. I'm wondering if perhaps your putty is actually not configured for UTF-8; I know for example ncurses apps with line drawing characters are affected by the putty translation setting. Try right-clicking on your putty title bar, go to "Change Settings...", then under Category navigate to "Window->Translation", then change the Remote character set to UTF-8. When I change this to Win 1252, I get behavior a little bit like what you're seeing.

For completeness, here are all my translation settings:

Remote character set: UTF-8
Treat CJK ambiguous characters as wide: unchecked
Caps Lock acts as Cyrillic switch: unchecked
Handling of line drawing characters: Use Unicode line drawing code points
Copy and paste line drawing characters as lqqqk: unchecked

With those settings, I'm able to paste the character you mentioned in vim successfully. If that works for you, obviously you can save those settings with your putty session.


It appears that the problem is lack of multi-byte support. If you need to recompile without root access, it's possible but tricky. I did it on my Linux Mint system to test:

  1. Get the old vim from git:

    wget https://github.com/vim/vim/archive/v7.2.000.tar.gz
    tar xvzf v7.2.000.tar.gz
    
  2. Edit the Makefile (vim vim-7.2.000/src/Makefile)

  3. Find prefix=$(HOME) and uncomment it so that the installer installs to your home directory
  4. Find and uncomment CONF_OPT_MULTIBYTE = --enable-multibyte
  5. To install it to ~/bin/vim, run:

    make
    make install
    
  6. Run from your home bin directory

This almost certainly will not work the first time; if you go this route, you'll have to get all the build dependencies built yourself ahead of time by getting each dep's source code. I recommend you try with the version of vim that's already on the system so that at least your runtime dependencies are already there.

  • Unfortunately this is not the problem. The character set in PuTTY is already set to utf-8. Since I'm able to paste utf-8 characters into bash, I suspect that the issue is a vim setting, not PuTTY, otherwise the former wouldn't work. – Scribblemacher Apr 12 '16 at 11:46
  • Very strange; a few things that might narrow down the problem a bit: try "echo ¿ >> temp.txt" from bash then vim temp.txt and see if your character shows up; that will tell us if it can't display it at all or if it's just an input thing. Are you using something like screen or tmux? That might impact vim's interaction with the terminal. Are you using a binary build of vim? I'm wondering how it was built; maybe a compile flag is off. If you installed it from your distro package manager such as apt or it came with your distro, let us know what distro, – ZeroG Apr 12 '16 at 13:35
  • That echo test does work for an inverted question mark, but not for others. For example, ‘ ¿ ’ becomes ▒~@~X¿▒~@~Y. Even so, I still can't insert a ¿ using Ctrl+K, ?, I – Scribblemacher Apr 12 '16 at 14:19
  • OS is SunOS 5.10. I added the output of vim --version to the question. – Scribblemacher Apr 12 '16 at 14:20
  • Since the issue seems to be the lack of multi-byte support, if you want to add that to this answer, I'll mark it as accepted. – Scribblemacher Apr 12 '16 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.