VimChatBot : A simple self-teaching chat bot game for Vim
| script karma
Downloaded by 1018
Comments, bugs, improvements
script versions (upload new version)
|Agetian's Vim ChatBot (C) 2012 by Michael Kamensky, all rights reserved.
This script is distributed under Vim license.
Vim ChatBot is a simple self-teaching chat bot game for Vim. It will try to
communicate with the human and will accumulate the human's questions and answers
over time, utilizing them later and trying to mimic human behavior. This chat
bot is not meant to be smart, at best it resembles a talking parrot and it's far
from being a real human-like chat robot companion. It's meant to be fun and it
was originally intended as a little project to teach myself how to script Vim.
IMPORTANT -- READ BEFORE USING OR DON'T TELL ME YOU WERE NOT WARNED:
Vim ChatBot will use the currently open file in the buffer as a source and as a
target for its database of known questions and replies! It will automatically
append new lines to the end of the current file as it learns the phrases from
the human! Therefore, if you were working on some important document prior to
starting the chat bot, make sure you switch to a new document or open your chat
database before initiating a conversation.
Vim ChatBot will never automatically save the file for you though, and it's
always up to you to decide if you want to save the updated database or not. You
should do it explicitly using the :write (or another command) to save the file.
Vim ChatBot utilizes the concept of a here-document (similar to here-documents
in bash) to be able to store its database of known questions and replies in the
script file itself. When VimChatBot.vim is opened in Vim, the chat bot will
automatically append new entries to the end of the script file as it learns new
phrases from you, and it will not corrupt the script file. If you'd like to keep
the updated database, you need to make sure you save the script file (:w or :x)
after you're done chatting.
Starting the Vim ChatBot
By default, Vim ChatBot maps itself to the <Leader>Cb command in normal mode
(<Leader> is the backslash symbol by default, so unless you've changed your
leader, the default command to start Vim Chatbot is \Cb ).
If the <Leader>Cb command is already taken by something among your scripts, feel
free to change the mapping (just search for nnoremap in the script file and
change the mapping to another combination of keys).
You can use the following macros when typing answers, the bot will also utilize
them when learning to use the phrase from you:
$TIME$ - refers to the current time.
$TIME12$ - (experimental) refers to the current time in 12-hour format.
$DAY$ - refers to the current day.
$WEEKDAY$ - refers to the current day of the week.
$MONTH$ - refers to the current month.
$YEAR$ - refers to the current year.
Finishing the conversation
To finish the conversation, type /Q into the "You Say:" prompt. Unless you are
asked something (or told something) by the bot and it's waiting for you to teach
it how to reply to that, /Q will end the conversation immediately. If, however,
the bot is waiting for your reply to learn something from you, /Q will merely
inform the bot that you don't have the intention to answer the question. If you
want to quit the conversation altogether, you will need to type /Q again.
Ctrl+C can be used as the universal quit command if you want to quit chatting
when in the middle of a bot-asked question and when you don't feel like typing
By default, Vim ChatBot treats the first two responses as special, that is, the
bot will store a separate set of responses for the phrases you type as your
first and as your second lines, and will respond accordingly. This is to prevent
absolute stupidity, such as saying "Hi!" in the middle of a conversation. The
number of "magical contexts" (responses which should be treated specially) can
be modified and is stored in the s:MagicalContexts variable.
You can modify the database manually by adding or removing phrases in case you
are not satisfied with something that the bot has learned or would like to teach
it something without having to go through the process of teaching-by-chatting.
The database for Vim ChatBot is stored in the following way:
The database structure described above has an important consequence: when
speaking to Vim ChatBot, never use a triple colon (:::) symbol in your phrases,
they will confuse the bot and may make it behave more stupidly than normal.
In the beginning of the conversation, the bot might seem not to recognize some
of the phrases you taught it before - this is due to the magical contexts
kicking in, the bot hasn't yet been taught to recognize that specific phrase in
that particular position. This is normal behavior, just patiently repeat the
If you have a Python-enabled version of Vim, ChatBot will utilize the Python
random number generation algorithm from the "random" library. If your Vim is not
Python-enabled, a simpler algorithm will be utilized instead, based on the idea
suggested by Bee-9 at:
This algorithm is less efficient and will produce less random numbers, which may
or may not be apparent in the actual conversation with the bot (your mileage may
vary). At any rate, a Python-enabled Vim is recommended for more randomness, but
not strictly required.
Remember: Don't take Vim ChatBot seriously and just have fun! :)
|Either put the file VimChatBot.vim to your "plugin" folder so it's auto-loaded, or unpack to any folder you like and then :source the script file when necessary.
Before initiating the chat bot conversation, make sure you either:
1) have the script file itself open in the current buffer (in this case, the here-document database in the end of VimChatBot.vim will be used);
2) have your own chat database file open in the current buffer (should initially be an empty file, will then be auto-filled with known questions and replies by the chat bot);
3) have a new empty file open in the current buffer (in case you don't yet have a chat bot database and you don't want to use VimChatBot.vim as a source/target for the database).
Once ready, use the <Leader>Cb command in normal mode (by default) to initiate a conversation.
Make sure you've read and understood all the information in the detailed description before starting!
Click on the package to download.
ip used for rating: 220.127.116.11
||- Updated the stupid line endings to use Unix format so that the chat bot works equally well on both Windows and *nix systems without having one to do :setlocal ff=unix and :w on the script before using it.
||- **NOTE:** this is a special update build for Vim/GVim v7.4 only! If you are using Vim 7.3 or an earlier build, please keep using VimChatBot v1.7 which is actually the preferred build for older Vims! This version requires Vim 7.4, the script interface on vim.org doesn't let me specify 7.4 as the target version, so I had to specify 7.3 instead, sorry.
- updated the human input routines to account for some of the changes in Vim 7.4 that broke the echo output.
||- Made one of the chat bot's inquiries less confusing to the user.
||- Auto set the regular expression search to ignore case mode prior to initiating the chat (to make it case-insensitive no matter what settings the user has), then restore the case-sensitivity setting after the chat is over.
||- Added a possibility of the chat bot initiating the conversation first (has a random 50% chance of happening).
- Some minor refactoring
||- Added support for macros $HOUR$, $MINUTE$, and $SECOND$ referring to the individual components (hours, minutes, seconds) of current time.
||- Fixed a bug with the chat initiation always mapping to \Cb instead of <Leader>Cb
- Less global namespace pollution due to the use of local functions
- Added a Vim version check, currently set to v7.0 (not sure if this script would run on Vim below v7.0, don't have an older build to test on).
- Added a load-only-once check.
- Added some basic documentation to the script file itself.
- Changed the name of the function MainChatLoop to VCB_MainChatLoop, following the naming scheme of other functions.
||- Some more code cleanup, added the proper header to the script, added the vi compatibility mode check/workaround. Functionally the same as v1.2a.
||Code Cleanup: Gave the functions more unique names, hopefully this will ensure much better compatibility with other scripts.
||- Code cleanup: removed the unnecessary "s:" flags for most variables that just need to be local to their functions. No other functional difference from the previous version.
||- Added some basic macro functionality, you can now use $TIME$, $DAY$, $WEEKDAY$, $MONTH$, and $YEAR$ to refer to the current time/date while speaking. Check the README for details.
- Fixed a potential crash-prone spot in one of the functions.
||- Updated the README file with some additional information on the possible quirks in behavior, please read the "Quirks" section of the updated file.