Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,17 @@ via github issues or PRs).

## Installation

First, install using your favourite package manager, or use Vim's built-in package support.
vim-plug:

```vim
" ~/.vimrc

call plug#begin('~/.vim/plugged')
...
Plug 'danhab99/claude.vim'

call plug#end()
```

Vim:

Expand Down
51 changes: 51 additions & 0 deletions autoload/claude.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

function! s:load_api_key() abort
let l:api_key_file = expand('~/.claude_api_key')
if filereadable(l:api_key_file)
let l:api_key = readfile(l:api_key_file)[0]
if empty(l:api_key)
throw "Claude.vim: API key file is empty."
endif
return l:api_key
else
echom "API key file not found:" . l:api_key_file
throw "Claude.vim: API key file not found."
endif
endfunction

let g:claude_api_key = s:load_api_key()

" Setup keybindings for Claude functions
function! claude#setup_keybindings() abort
call s:SetupClaudeKeybindings()
endfunction

" Open the Claude chat interface
function! claude#chat() abort
" Delegate to plugin function
call s:ClaudeLoadPrompt('chat')
endfunction

" Implement a feature using Claude
function! claude#implement() abort
" Example: Select block and modify
echo "Not yet implemented. Forward this to s:ClaudeLoadPrompt('implement') in plugin."
endfunction

" Send a chat message in the chat window
function! claude#send_chat_message() abort
" Delegate to ClaudeQueryInternal in plugin
call s:ClaudeQueryInternal(messages, system_prompt, tools, stream_callback, final_callback)
endfunction

" Cancel a running Claude response
function! claude#cancel_response() abort
" TODO: Use the actual Claude API to cancel the request.
if exists('g:claude_active_job') && g:claude_active_job > 0
call job_stop(g:claude_active_job)
unlet g:claude_active_job
echo "Response cancelled."
else
echo "No active response to cancel."
endif
endfunction
10 changes: 9 additions & 1 deletion plugin/claude.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
" File: plugin/claude.vim
" vim: sw=2 ts=2 et

augroup claude
autocmd!
let s:plugin_dir = expand('<sfile>:p:h:h')
let cmd = printf('source %s/%s', s:plugin_dir, 'autoload/claude.vim')
autocmd BufEnter * exec cmd
augroup END

" Configuration variables
if !exists('g:claude_api_key')
let g:claude_api_key = ''
Expand Down Expand Up @@ -128,7 +135,8 @@ function! s:ClaudeQueryInternal(messages, system_prompt, tools, stream_callback,
endif
call extend(l:headers, ['-H', 'Content-Type: application/json'])
call extend(l:headers, ['-H', 'x-api-key: ' . g:claude_api_key])
call extend(l:headers, ['-H', 'anthropic-version: 2023-06-01'])
call extend(l:headers, ['-H', "Authorization: 'Bearer " . g:claude_api_key . '"'])
" call extend(l:headers, ['-H', 'anthropic-version: 2023-06-01'])

" Convert data to JSON
let l:json_data = json_encode(l:data)
Expand Down