Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine a variable's type in a vim function?

Tags:

vim

Is there a way to check the type of a variable in vim? I need to check to make sure my functions argument is a number and am not sure how to go about it.

like image 432
Blaine Kasten Avatar asked Jul 15 '13 15:07

Blaine Kasten


People also ask

What is let G in Vim?

b: local to the current buffer. l: local to a function. g: global. :help internal-variables. Follow this answer to receive notifications.

How do I use echo in Vim?

Try out echo by running the following command: :echo "Hello, world!" You should see Hello, world! appear at the bottom of the window.

What is VimL?

Vim script (aka Vimscript, or VimL) is a full feature scripting language, meaning it can solve almost any text processing problem.

How do I comment in Vimscript?

Comments in Vimscript start with " (a double quote), not // . If you want to execute a normal mode command, like % or dd , you can use normal! % or normal! dd .


1 Answers

You're looking for type(varname).

Note that explicit type checks are somewhat of a code smell (especially because the exact implicit type conversions done by Vim are not widely known); though I have to admit that sometimes they do make for a nice and short function interface.

like image 98
Ingo Karkat Avatar answered Nov 03 '22 10:11

Ingo Karkat