Cursor AI Integration for Vim and Neovim
Bring the power of Cursor's AI capabilities directly into your Vim or Neovim workflow
Warning
This project is in alpha stage and is actively being developed. You may encounter bugs, breaking changes, and incomplete features. Use at your own risk and please report any issues you find!
- 🤔 Ask - Get instant answers to coding questions with full context awareness
- 💬 Chat - Interactive conversational AI assistance with history management
- ✨ Apply - Seamlessly apply AI-generated code suggestions to your buffers
- 🎨 Modern UI - Beautiful floating windows and split layouts
- ⚡ Async - Non-blocking operations that keep your editor responsive
- 🔧 Configurable - Extensive configuration options and key mappings
- 🔀 Dual Support - Works with both Vim 9.0+ and Neovim 0.8+
Note: cursor.vim focuses on interactive AI assistance, not inline code completion. Use it alongside GitHub Copilot for the best development experience!
cursor.vim is designed to complement inline completion tools like GitHub Copilot, not replace them.
- Use GitHub Copilot for: Real-time code suggestions as you type
- Use cursor.vim for: Interactive Q&A, learning, debugging, and applying complex changes
Think of it as having both:
- A co-pilot (GitHub Copilot) - suggests code while you fly
✈️ - An instructor (cursor.vim) - answers questions and helps you learn 🎓
| Feature | GitHub Copilot | cursor.vim |
|---|---|---|
| Inline code completion | ✅ | ❌ |
| Tab suggestions while typing | ✅ | ❌ |
| Interactive Q&A | ❌ | ✅ |
| Multi-turn conversations | ❌ | ✅ |
| Code explanation | Limited | ✅ |
| Apply code with preview | ❌ | ✅ |
| Chat history | ❌ | ✅ |
| Ask about selections | ❌ | ✅ |
| Works with Vim & Neovim | ✅ | ✅ |
Recommendation: Install both! They work great together and serve different purposes.
Choose one:
- Neovim 0.8+ - Modern Neovim with Lua support
- Vim 9.0+ - Modern Vim with job control and popup windows
Both require:
- Cursor Agent CLI - Cursor Agent CLI installed and authenticated (
cursor-agentcommand) - Node.js - Required by Cursor Agent CLI
Using vim-plug
Plug 'johnbrandborg/cursor.vim'Using lazy.nvim
{
'johnbrandborg/cursor.vim',
config = function()
require('cursor').setup({
-- your config here (optional)
})
end
}Using packer.nvim
use {
'johnbrandborg/cursor.vim',
config = function()
require('cursor').setup()
end
}# For Neovim
git clone --depth=1 https://github.com/johnbrandborg/cursor.vim.git \
~/.config/nvim/pack/cursor/start/cursor.vim
# For Vim
git clone --depth=1 https://github.com/johnbrandborg/cursor.vim.git \
~/.vim/pack/cursor/start/cursor.vim- Install the plugin using your preferred method
- Install and authenticate with Cursor Agent CLI - the command is
cursor-agent - Open Vim or Neovim and run
:CursorSetupto verify installation - Start using cursor.vim!
Note: cursor.vim automatically detects your editor (Vim or Neovim) and loads the appropriate implementation.
" Ask a question
:CursorAsk How do I implement a binary search in Python?
" Open chat interface
:CursorChat
" Apply last AI response to buffer
:CursorApplycursor.vim comes with sensible defaults, but you can customize it to your liking.
require('cursor').setup({
-- Path to cursor CLI executable
cli_path = 'cursor-agent',
-- Default AI model
model = 'claude-sonnet-4',
-- Timeout for CLI operations (milliseconds, 0 to disable)
timeout = 60000,
-- UI preferences
ui = {
-- Window type: 'float', 'split', 'vsplit'
window_type = 'float',
-- Floating window dimensions (percentage)
float_width = 0.8,
float_height = 0.8,
-- Split size (lines/columns)
split_size = 15,
-- Border style: 'none', 'single', 'double', 'rounded', 'solid', 'shadow'
border = 'rounded',
},
-- Chat preferences
chat = {
-- Save chat history
save_history = true,
-- Maximum context messages
max_context = 20,
-- History directory
history_dir = vim.fn.stdpath('data') .. '/cursor_chat_history',
},
-- Key mappings (set to false to disable)
mappings = {
ask = '<leader>ca',
chat = '<leader>cc',
apply = '<leader>cy',
status = '<leader>cs',
},
-- Debug mode
debug = false,
})" Set configuration before plugin loads
let g:cursor_config = {
\ 'cli_path': 'cursor-agent',
\ 'model': 'claude-sonnet-4',
\ 'timeout': 60000,
\ 'ui': {
\ 'window_type': 'float',
\ 'float_width': 0.8,
\ 'float_height': 0.8,
\ 'split_size': 15,
\ 'border': 'rounded',
\ },
\ 'chat': {
\ 'save_history': v:true,
\ 'max_context': 20,
\ },
\ 'debug': v:false,
\ }To disable default key mappings entirely (works for both Vim and Neovim):
let g:cursor_no_default_mappings = 1Ask questions and get AI-powered answers with full context.
" Simple question
:CursorAsk How do I reverse a list in Python?
" Interactive mode (prompts for input)
:CursorAskInteractive
" Or use keymap: <leader>ca
" Ask about visual selection
" 1. Select code in visual mode
" 2. Press <leader>ca or run :CursorAskVisual
" Ask about current buffer
:CursorAskBuffer Explain this codeInteractive conversational interface with context memory.
" Open chat window
:CursorChat
" Or use keymap: <leader>cc
" In chat window:
" - Type your message and press <Enter> to send
" - Press 'q' to close
" - Use <leader>cc to clear history
" Save chat history
:CursorChatSave my_session.json
" Load chat history
:CursorChatLoad ~/.local/share/nvim/cursor_chat_history/my_session.json
" Clear chat history
:CursorChatClear
" Close chat window
:CursorChatCloseApply AI-generated code directly to your buffers.
" Preview code blocks from last response
:CursorPreview
" Apply code from last response
:CursorApply
" Or use keymap: <leader>cy
" You'll be prompted to choose:
" - Replace entire buffer
" - Append to end
" - Insert at cursor
" Apply to new buffer
:CursorApplyNewCheck plugin status and configuration.
:CursorStatus
" Or use keymap: <leader>cs| Command | Description |
|---|---|
:CursorSetup |
Initialize plugin (called automatically) |
:CursorStatus |
Show plugin status |
:CursorAsk <question> |
Ask a question |
:CursorAskInteractive |
Ask with input prompt |
:CursorAskVisual |
Ask about visual selection |
:CursorAskBuffer |
Ask about current buffer |
:CursorChat |
Open chat interface |
:CursorChatClear |
Clear chat history |
:CursorChatSave [file] |
Save chat session |
:CursorChatLoad <file> |
Load chat session |
:CursorChatClose |
Close chat window |
:CursorApply |
Apply last AI response |
:CursorApplyNew |
Apply to new buffer |
:CursorPreview |
Preview code blocks |
| Mode | Key | Action |
|---|---|---|
| Normal | <leader>ca |
Ask (interactive) |
| Visual | <leader>ca |
Ask about selection |
| Normal | <leader>cc |
Open chat |
| Normal | <leader>cy |
Apply code |
| Normal | <leader>cs |
Show status |
" 1. Select code you want to refactor
" 2. Press <leader>ca (or :CursorAskVisual)
" 3. Type: "Refactor this to use list comprehension"
" 4. Review the response
" 5. Press <leader>cy to apply changes" 1. Select buggy code
" 2. :CursorAskVisual Why isn't this working?
" 3. Get detailed explanation
" 4. Ask follow-up questions in :CursorChat:CursorAsk Explain Python decorators with examples
" Review detailed explanation in floating window:CursorStatus
" Check if CLI is detected
" If not, set custom path in config:
require('cursor').setup({
cli_path = '/path/to/cursor-agent'
})Ensure Cursor Agent CLI is authenticated:
cursor-agent auth loginThe cursor-agent CLI can take 30-60 seconds to respond. If you get timeout errors (exit code 143), increase the timeout:
require('cursor').setup({
timeout = 120000 -- 2 minutes for complex queries
})Or disable timeout entirely (not recommended):
require('cursor').setup({
timeout = 0 -- No timeout
})Enable debug logging:
require('cursor').setup({
debug = true
})cursor.vim is built with a dual modular architecture supporting both Vim and Neovim:
cursor.vim/
├── plugin/cursor.vim # Auto-detects Vim/Neovim and loads appropriate implementation
├── lua/cursor/ # Neovim implementation (Lua)
│ ├── init.lua # Main module
│ ├── config.lua # Configuration
│ ├── cli.lua # Cursor CLI interface (libuv)
│ ├── ask.lua # Ask feature
│ ├── chat.lua # Chat feature
│ ├── apply.lua # Code application
│ └── ui.lua # UI components
└── autoload/cursor/ # Vim implementation (Vimscript)
├── init.vim # Main module
├── config.vim # Configuration
├── cli.vim # Cursor CLI interface (job_start)
├── ask.vim # Ask feature
├── chat.vim # Chat feature
├── apply.vim # Code application
└── ui.vim # UI components
Both implementations provide feature parity - all commands and features work identically in Vim and Neovim.
Contributions are welcome! Please feel free to submit issues and pull requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
cursor.vim and copilot.vim serve different but complementary purposes:
GitHub Copilot excels at:
- Inline code suggestions as you type
- Autocomplete for repetitive patterns
- Fast, context-aware completions
cursor.vim excels at:
- Interactive Q&A and explanations
- Multi-turn conversations with context
- Debugging and learning
- Applying complex code changes with preview
- Explicit code generation on demand
Together, they provide:
- 🚀 Faster coding - Copilot for quick completions
- 🧠 Better understanding - cursor.vim for learning and debugging
- 🎯 More control - cursor.vim for explicit, reviewed changes
- 💪 Complete workflow - Cover all aspects of AI-assisted development
Many developers use both: Copilot for day-to-day completions, and cursor.vim when they need to think through problems or learn new concepts.
cursor.vim provides two complete implementations:
| Feature | Neovim (Lua) | Vim (Vimscript) |
|---|---|---|
| Async Operations | vim.loop (libuv) |
job_start() |
| Floating Windows | nvim_open_win() |
popup_create() |
| JSON Handling | vim.json.* |
json_encode/decode() |
| Configuration | Lua tables | Dictionary variables |
Both implementations are maintained in parallel and provide identical functionality.
- Planning feature integration
- Inline code completion
- Multi-model selection
- Custom system prompts
- LSP integration for context-aware suggestions
- Telescope integration
- Diff view for code changes
MIT License - see LICENSE file for details
- Inspired by copilot.vim
- Built for Cursor AI integration
- Powered by Neovim
Made with ❤️ for the Vim community