# Manipulate chars with their ascii code

Let say I have

``````let l:letter = 'A'
``````

is there a function that takes `l:letter` ascii code and transforms it to `'B'`? I mean something like

``````let l:next_letter = l:letter + 1
``````

I know there's `<Ctrl-A>` with `set nf=alpha`, but that requires to have the cursor over the character in the document and I was wondering if it's possible to do it with a variable without modifying the document.

Here's what I try so far, but as I said, it modifies the document and the cursor position:

``````fu! s:get_next_char(letter)
set nf=octal,hex,alpha
call setline(line('\$') + 1, a:letter)
exe ':normal! G^'."\<C-A>"
set nf=octal,hex

let l:next_letter = getline('\$')
normal! Gdd
return l:next_letter
endfu
``````
• `:help string-functions`. Apr 20, 2015 at 7:03
• @romainl thanks for the tip but next time take into account that maybe I've been programming in vimscript for a couple of days and for what I know, `string-functions` is not a global standard man page for every language, seriously. Apr 20, 2015 at 7:25
• I agree with @Jcao02, prior knowledge of the entirety of Vim help pages are not a requirement of this site. And I would classify `:help string-functions` as slightly obscure. Also, some scripting languages like python and perl use `chr()` and `ord()` functions to convert to ascii/character. So searching with these terms still wouldn't show up the `nr2char` and `char2nr` functions either. I think @romainl's comment should be posted as an answer instead. Apr 20, 2015 at 7:38
• I have to agree with romainl: it's very important to know how to navigate vim help pages. My first shell classes taught me `man man`. `:help :help` is equally important. But vim documentation is quite massive and hard to figure the first years. Thus tricks like `:h function^D` give us entries points. Here it would be `:h functions` (/`:h string-functions`). Then, it's easy to understand what's doing what. Even if we are used to other languages. We can always give the information (it's what we're doing most of the time), but teaching how to fish it is more important -- you know the proverb... Apr 20, 2015 at 10:24
• @LucHermitte I would argue that just posting `:help string-functions` is not showing how to fish. It's more like giving someone the bait and not teaching them to fish at all. Posting how they can search for functions, is teaching them to fish. Apr 21, 2015 at 2:33

It's easy to do with `:help nr2char()` and `:help char2nr()`.

Example usage:

`:let b_char = nr2char(char2nr('A') + 1)`

Then, `:echo b_char` will return 'B'

The question is (emphasis mine):

is there a function that takes `l:letter` ascii code and transforms it to 'B'?

Since you want a function, the first thing to try is `:help function<C-d>` which lists every documentation tag containing `function`:

``````:function                    list-functions               folding-functions
function()                   time-functions               history-functions
functions                    mark-functions               mapping-functions
function-key                 text-functions               various-functions
function_key                 compl-function               numbered-function
:function-verbose            spell-functions              quickfix-functions
function-argument            float-functions              complete-functions
nb-functions                 style-functions              anonymous-function
gui-functions                string-functions             completion-functions
arg-functions                server-functions             window-size-functions
var-functions                cursor-functions             interactive-functions
function-range-example       window-functions             command-line-functions
expr-function                buffer-functions             highlighting-functions
new-functions-5.2            system-functions             curly-braces-function-names
date-functions               syntax-functions             python-Function
dict-functions               xterm-function-keys          :endfunction
file-functions               vt100-function-keys          :delfunction
user-functions               bitwise-function
``````

The most obvious candidate is `function-list`, let's try it:

``````There are many functions.  We will mention them here, grouped by what they are
used for.  You can find an alphabetical list here: |functions|.  Use CTRL-] on
You may have noticed a pattern, here: functions are grouped by theme. This means that, if you need a function to filter a list you can go directly to `:help list-functions`.
The Vim help pages are very useful; often times `:help <keyword><C-d>` will get you a long way ;-)
{"ft_lang_label":"__label__en","ft_lang_prob":0.8080933,"math_prob":0.63492167,"size":2978,"snap":"2023-14-2023-23","text_gpt3_token_len":616,"char_repetition_ratio":0.23806322,"word_repetition_ratio":0.0,"special_character_ratio":0.1930826,"punctuation_ratio":0.122370936,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95192546,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-01T11:19:32Z\",\"WARC-Record-ID\":\"<urn:uuid:d0669356-7e70-45fe-a65b-614f88c9e7e7>\",\"Content-Length\":\"175461\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:435323cf-2fc1-4744-b193-3bbd7a59e54b>\",\"WARC-Concurrent-To\":\"<urn:uuid:169db89b-7965-4352-8077-5cbb43318202>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://vi.stackexchange.com/questions/3013/manipulate-chars-with-their-ascii-code\",\"WARC-Payload-Digest\":\"sha1:QEOJDYCIBGDAOL662SZGNDK64EOHB5WC\",\"WARC-Block-Digest\":\"sha1:AMK3PUOQV4JA5RKZULXTOXCTRD73CQRU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224647810.28_warc_CC-MAIN-20230601110845-20230601140845-00786.warc.gz\"}"}