Code Monkey home page Code Monkey logo

vimassist's Introduction

VimAssist

VimAssist is a plugin for Vim that provides a set of commands to assist in the writing of articles in natual language. It is designed to be used in conjunction with the Vim text editor.

Main Features

Ask command

The :Ask command is used to ask a question and insert the answer into the document. The answer is generated by OpenAI's GPT-4 model by using information from user's own documents. With proper mapping configuration, the user can use the shortct \a to launch the :Ask command.

Updatedocs command

The :Updatedocs command is used to update the documents in the knowledge base used by AI. When user executes this command, the plugin will confirm with the user to using the documents in the folder where VIM is launched. User has the option to choose another folder. With proper mapping configuration, the user can use the shortct \u to launch the :Updatedocs command.

Showdocs command

The :Showdocs command is used to display all the file names in the knowledge base, which are currently used by AI. With proper mapping configuration, the user can use the shortct \s to launch the :Showdocs command.

Installation

NOTE: I use Mac, and all the installation steps are verified on Mac. If you are using Windows or Linux, you may need to modify the installation steps.

Step 1: Install Python3

You can use brew to install Python3 of specific version. During my installation, I found the MacOS installed Python3.9 by default, but it did not work with VIM. Instead, I need to install Python3.12 to make the whole thing work. Again, this may only be the case for Mac.

brew install [email protected]

Step 2: Install VIM

On Mac, you can install VIM using Homebrew:

brew install vim

Step 3 (IMPORTANT): Check the if vim supports python3

You can check if your vim supports python3 by running the following command in vim:

:echo has('python3')

If the result is 1, then your vim supports python3. If the result is 0, then you need to install a new vim that supports python3.

Step 4: check the linked python3 version, make sure you system installed the version that linked to vim

You can check the linked python3 version by running the following command in OS terminal:

vim --version | grep python3

Step 5: Install the plugin manager for VIM

Follow the instruction on its github page: https://github.com/junegunn/vim-plug

Step 6: Install the VimAssist plugin

Excute following commands in your terminal:

mkdir -p ~/.vim/pack/vimassist/start/VimAssist git clone https://github.com/sluosapher/VimAssist.git ~/.vim/pack/vimassist/start/VimAssist

This will install the plugin source code into the folder ~/.vim/pack/vimassist/start/VimAssist, which will be recognized by the plugin manager.

Step 7: Install python dependencies

You need to install the needed python packages. IMPORTANT: You must use the correct version pip to install the packages. For exmaple, if you are using Python3.12, you need to use pip3.12 to install the packages.

pip3.12 install -r ~/.vim/pack/vimassist/start/VimAssist/scripts/python_requirements.txt

Step 8: Update the ~/.vimrc file

First, make sure you update the ~/.vimrc as instructed in step 5. Then, add the following lines to the ~/.vimrc file, after the call plug#begin() line, and before the call plug#end() line:

Plug 'vimassist/VimAssist'

Step 9: Mapping the shortcuts

Add the following lines to the ~/.vimrc file, after the call plug#end() line:

" map shortcut <leader>a in both normal mode and visual mode to the Ask command of chatdocu plugin  
nnoremap <leader>a :call vimassist#Ask()<CR>  
vnoremap <leader>a :call vimassist#Ask()<CR>  

" map shortcut <leader>u in both normal mode and visual mode to the UpdateDocs function  
nnoremap <leader>u :call vimassist#UpdateDocs()<CR>  
vnoremap <leader>u :call vimassist#UpdateDocs()<CR>  

" map shortcut <leader>s in both normal mode and visual mode to the ShowDocs function  
nnoremap <leader>s :call vimassist#ShowDocs()<CR>  
vnoremap <leader>s :call vimassist#ShowDocs()<CR>  

I have provided a example of the configuration in the file scripts/vimrc.example, which you can use as a reference.

Step 10: Save the ~/.vimrc file and restart VIM

After you save the ~/.vimrc file, you need to restart VIM to make the changes effective.

Usage

Prepare the OPenAI API key

You need to prepare the OpenAI API key to use the plugin. You can get the API key from the OpenAI website. After you get the API key, you need to save it as an environment variable OPENAI_API_KEY. You can do this by adding the following line to your ~/.bash_profile file:

export OPENAI_API_KEY="your_api_key"

Don't forget to source the ~/.bash_profile file after you make the change:

source ~/.bash_profile

Prepare the knowledge base

VimAssist provides three commands: :Ask, :Updatedocs, and :Showdocs. You can use the shortcuts \a, \u, and \s to launch the commands, respectively.

The plugin is supposed to work on a knowledge base, which is a folder containing all the documents that you want to use to generate the answer.

The first thing you need to do is to collect all the document files you will need for you writing, and save them into a specific folder. This is folder and its content is the knowledge base.

Use the :Updatedocs command

After you prepared the knowledge base, you can launch the :Updatedocs command (shortcut \u) in vim to tell the plugin to use the documents in the knowledge base. It will basically create an OpenAI assistant, and attach the files in the folder to the assistant.

Use the :Ask and :Showdocs commands

After you use the :Updatedocs command, you can use the :Ask command (shortcut \a) to ask a question and insert the answer into the document. You can also use the :Showdocs command (shortcut \s) to display all the file names in the knowledge base, which are currently used by AI.

Use the :Revise command

This command allows you to select a part of text (in visual mode) and ask the AI to revise it based on your specific request. You can use the shortcut \r to launch the :Revise command.

License

Apache License 2.0

vimassist's People

Contributors

sluosapher avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

vimassist's Issues

Issue using :Updatedocs

Note that I bolded what appears to me to be sigificant.
I'm getting the following error:
:Updatedocs
Do you want to use the directory /home/canderso to update the documentation?

Please provide the directory to use: /home/canderso/Documents/aiPDFsdoc_dir: /ho
me/canderso/Documents/aiPDFs
Expected a non-empty value for assistant_id but received None
Failed to retrieve the assistant with ID None. Creating a new assistant.
Error code: 400 - {'error': {'message': "Invalid value: 'retrieval'. Supported v
alues are: 'code_interpreter', 'function', and 'file_search'."
, 'type': 'invalid
_request_error', 'param': 'tools[1].type', 'code': 'invalid_value'}}
Documentation update failed
Press ENTER or type command to continue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.