Hot answers tagged

44

You can use %b or %B in statusline or rulerformat. From :help statusline: b N Value of character under cursor. B N As above, in hexadecimal. For example: set statusline=%b\ %B Gives you: 8984 2318 Another way is to use ga or the :ascii command. From :help ga: :as[cii] or ga :as :ascii ga ...


42

You can use digraphs: Ctrl+k-N (with a capital N) In Insert mode, digraphs are entered by Ctrl+k followed by a two-character sequence. For en-dash, the sequence is -N. As Quincy pointed out, U+2014 is em-dash. If you want to enter that using digraphs, the sequence is -M.


24

Others have already provided work-arounds, but as for the reason why it happens, I bet you're accidentally pressing Alt+Space. I'm using Xubuntu with the 105-key Finnish keyboard layout myself, so for me, typing { means pressing AltGr+7. I just did a quick test in xfce4-terminal (on the bash command line), and pressing AltGr+Space indeed produces a no-...


22

Preface: This has nothing to do with Vim as such, but I will show you what I consider to be the "best" way to insert these characters by far; Vim's digraph system is more or less the same, but it only works with Vim. This will work in all applications. This will only work for X11 systems (Linux, BSD, etc.). For Windows, there's AllChars. It hasn't been ...


19

To insert Unicode characters such as the euro or copyright symbols, or diacritical marks such as the German umlaut or accent grave, digraphs can be used. For example, in insert mode press Ctrl+k and type the following: Spanish: a' for á, E' for É, n? for ñ, German: a: for ä, ss for ß, other accented letters: a! for à, a> for â for ê, a? for ã, Greek: a* ...


19

You can add an autocommand that replaces non-breaking spaces with regular ones upon saving particular file types, eg. by putting something like this in your vimrc: augroup RemoveSpaces autocmd! autocmd BufWritePre *.css silent! :%s/\%u00A0/ /g augroup end You can tweak it by adding more file types or setting a mark and returning to it after the replace ...


16

Type in normal mode /<ctr-v>u0303 / - start search <Ctr-v>u - init utf-8 code input 0303 - hex code combine character. :he unicode Also :he mbyte-combining and :he utf-8-char-arg the last one covered case with commands like f, F and so on.


13

The 'listchars' option provides a means to make 'list' display non-breaking spaces. It's not set by default, so you probably want to add it. set listchars+=nbsp:‗


10

If there isn't a predefined digraph or you want a more memorable key sequence, then you can define digraphs in your vimrc. For example, the below will define two digraphs for en dash (8211) and em dash (8212) which mirror their XCompose sequences. digraph -. 8211 -- 8212 The :digraph command expects the value to be specified in decimal rather than hex, ...


10

If I understand you correctly, you have a file where certain characters are represented by their decimal value in the format \uXXXX, with X being any hexadecimal character but always 4, correct? If so, you can transform those sequences into the actual values they represent by doing a clever search and replace. In this particular case, I would do: :%s/\\u\(\...


9

It allows you to enter a digraph — it's a method of entering a more extensive range of Unicode characters using pairs of keystrokes. (See :h digraphs) For future reference, you can find out what insert mode keystrokes do with commands such as: :h i_CTRL-K.


8

The standard way of inserting an en dash in Vim is to use a digraph, as tommcdo explained. However, I find digraphs in general, and particularly this one (Ctrl+k, -, Shift+N) pretty awkward to type. For faster input of dashes, you could add the following pair of insert-mode mappings to a filetype file, such as .vim/after/ftplugin/markdown.vim. For en/em ...


6

If you have a recent Vim, you may try to enable DirectX rendering. It should improve "wide" font rendering, among other things. Here's an example vimrc snip: if has("gui_running") set guioptions=icpM if has('win32') || has('win64') if (v:version == 704 && has("patch393")) || v:version > 704 set renderoptions=type:...


6

My unicode plugin allows for easy input of unicode characters. Specifically it allows :Digraph <name> - Search digraphs for character :UnicodeTable - Displays a characterset table :UnicodeName - Identify character under cursor Completing of characters using their names or values from the unicode table (:h i_CTRL-X_CTRL-Z) or the digarphs (:h i_CTRL-...


6

There you go: :%s/[\uff01-\uff5e]/\=nr2char(char2nr(submatch(0))-65248)/g This matches the range of full-width characters, and via :help sub-replace-expr and char2nr() converts this to a number, subtracts to get this into the ASCII range for ! - ~, and converts it back to characters. Addendum If you need to support other (non-contiguous) characters, you ...


6

We discussed it less then 10 days ago on reddit. One solution is matchstr(getline('.'), '\%'.col('.').'c.') which doesn't mess with any register. I've put the resulting functions (we can ask for the characters before, or after the cursor) in my vimscript library along with other functions on the subject.


5

You can define your own digraph like this. :digraph .. 8226 Or you could use the pre-existing digraph Sb which gives you Unicode 8729. Not the exact code point you were looking for but it is probably pretty similar visually, if not the same, in most fonts.


5

Something like this should work: function! Strpartw(src, start, ...) return a:0 ? \ join(split(a:src, '.\zs')[a:start : (a:start + a:1 - 1)], '') : \ join(split(a:src, '.\zs')[a:start :], '') endfunction


5

The @ character in iskeyword includes all characters for which isalpha() (C function) is TRUE; in modern (last 20 years) libc implementations this also looks for unicode characters. Your second iskeyword uses 97-122 (a-z) and 64-90 (A-Z), which doesn't include all the variants with the various diacritics (such as the umlaut/diaeresis/trema). So the ...


5

To go to the Nth byte in the file: use :go N, :Ngo, or Ngo (normal mode). To move N bytes ahead, you could use something like this :exe 'go' line2byte(line("."))+col(".")-1+N Unless you have changed virtualedit, you can move forward with <space>. To go to the Nth character in the file, use 1goN<space> in normal mode. To move ahead N ...


5

List & Listchars 'list' is a boolean option that, when set, instructs vim to display whitespace characters. And it is completely customizable using 'listchars'. For example, to show non-breaking spaces as ! (you can use whatever character you like, especially with digraphs and unicode support): set list listchars=nbsp:! I use 'listchars' extensively, ...


4

Pressing <C-v>ude90 in insert mode should work. The problem is probably: let g:indentLine_char = <de90> which is missing quotes; it should be: let g:indentLine_char = "<de90>" (where <de90> is entered with <C-v>, and not 6 separate characters). See :help i_CTRL-V and :help i_CTRL-V_digit.


4

You are close. You need to use this form: :let foobar="\u1234" Using "\u" allows to use up to 4 hex digits. Until recently, it was not possible to use more, but with newer Vims you can now use "\U" plus up to 8 hex numbers. The details are explained at :h expr-quote


4

The default encoding seems to be latin1: :set encoding? encoding=latin1 When entering characters, Vim tries to convert them from the incoming character set (probably unicode) to latin-1. This fails since latin-1 doesn't have these characters. Hence the question marks. Opening an existing file (Saved with notepad or some other program) should result in ...


4

Vim is using Unicode (probably UTF-8), but Excel and/or Access are using Windows-1252 (or possibly a related Windows code page such as 1251 or 1253). Decimal 8216 is hexadecimal 2018, thus ‘ is Unicode character U+2018 LEFT SINGLE QUOTATION MARK. Asc and Chr are old, pre-Unicode functions, which is why they are reporting the Windows-1252 character codes. If ...


3

There's nothing built-in, but the following mapping seems to do the trick. " g9 Print the hex values of the bytes used in the " character under the cursor / selected text, using the " actual 'fileencoding' of the buffer. function! s:ShowHexFileEncodingCharacter( isSelection ) let l:text = (a:isSelection ...


3

In lh-vim-lib, I'm doing it this way: if exists('*strcharpart') function! lh#encoding#strpart(mb_string, p, l) " If we want a narrow contract " call lh#assert#value(lh#encoding#strlen(a:mb_string)).is_ge(a:p+a:l) return strcharpart(a:mb_string, a:p, a:l) endfunction else function! lh#encoding#strpart(mb_string, p, l) " If we want a ...


3

For commonly used characters, :digraph or external means such as the mentioned Compose key are great. For rarely used ones, I define abbreviations, like this: norea <unique> unicode_smiley 😃 norea <unique> unicode_skull ☠ And then use my SnippetComplete plugin to get a popup menu that list all such abbreviations, e.g. : unicode_<C-x>]


3

In adition to using the predefined digraphs (Run :dig to get a list), you can also define your own digraphs in vim: :digr e: 235 a: 228 See also: http://vimdoc.sourceforge.net/htmldoc/digraph.html


3

On my French AZERTY Mac keyboard, I can insert an en dash with Alt+-. Your mileage may obviously vary.


Only top voted, non community-wiki answers of a minimum length are eligible