Vim RestMan is a REST API client plugin for Vim that allows developers to make HTTP requests directly from within their Vim editor. It provides functionality similar to Postman but integrated into the Vim environment.
- VimScript (Vim's native scripting language)
- curl (for HTTP requests)
- jq (optional, for JSON formatting)
- Make HTTP requests directly from Vim
- Parse .rest files containing API request definitions
- Variable capture and substitution
- Response display with syntax highlighting
- Split window interface
- JSON response formatting
- Request history tracking
The plugin follows a modular architecture with clear separation of concerns:
vim-restman
├── plugin/
│ └── vim-restman.vim # Plugin initialization
└── autoload/
├── vim_restman.vim # Core orchestrator
├── vim_restman_utils.vim # Utility functions
├── vim_restman_file_parser.vim # Request file parsing
├── vim_restman_curl_builder.vim # Request building
├── vim_restman_buffer_manager.vim # Display management
├── vim_restman_window_manager.vim # Window management
└── vim_restman_capture_manager.vim # Variable capture
-
Core Orchestrator (
vim_restman.vim
)- Coordinates between components
- Manages plugin lifecycle
- Handles main workflow
-
File Parser (
vim_restman_file_parser.vim
)- Parses .rest files
- Extracts request definitions
- Processes global configurations
-
Curl Builder (
vim_restman_curl_builder.vim
)- Constructs curl commands
- Handles request formatting
- Manages variable substitution
-
Display Management (
vim_restman_buffer_manager.vim
)- Manages output display
- Handles syntax highlighting
- Formats responses
- User opens/edits .rest file
- File parser processes request definitions
- Curl builder creates HTTP request
- Request is executed
- Response is captured and processed
- Results displayed in split window
- Variables captured for future use
- Vim 8.0 or newer
- curl installed on system
- jq (optional) for JSON formatting
Plug 'sojohnnysaid/vim-restman'
git clone https://github.com/sojohnnysaid/vim-restman.git
cp -r vim-restman/plugin/* ~/.vim/plugin/
cp -r vim-restman/autoload/* ~/.vim/autoload/
Add to your .vimrc:
" Optional: Custom key mapping
nmap <your-preferred-key> <Plug>RestManMain
" Optional: Window settings
let g:restman_window_size = 40
vim-restman/
├── plugin/ # Plugin initialization
├── autoload/ # Core functionality
├── doc/ # Documentation
├── LICENSE # MIT License
└── README.md # User documentation
plugin/vim-restman.vim
: Plugin entry pointautoload/vim_restman.vim
: Core orchestrationautoload/vim_restman_file_parser.vim
: Request parsingautoload/vim_restman_curl_builder.vim
: Request building
#Globals Start
@variables
base_url=https://api.example.com
token=12345
@capture
response.id=captured_id
#Requests Start
GET /users
Authorization: Bearer {{token}}
--
POST /users
Content-Type: application/json
{"name": "John"}
--
#Requests End
{
'method': 'GET|POST|PUT|DELETE',
'endpoint': '/path',
'headers': ['Header: Value'],
'body': 'request body'
}
{
'variable_name': {
'value': 'variable value',
'set': 1
}
}
- Create feature branch
- Add functionality in appropriate autoload file
- Update main orchestrator if needed
- Add documentation
- Test manually
- Submit PR
" Run basic functionality test
:RestManMain
" Test variable capture
:echo vim_restman_capture_manager#GetAllCapturedValues()
vim_restman#Main()
" Main entry point for plugin execution
vim_restman#CleanUp()
" Cleanup plugin resources
vim_restman_file_parser#ParseCurrentFile()
" Parse current .rest file
vim_restman_curl_builder#BuildCurlCommand(parsed_data, request_index, variables)
" Build curl command from request data
#Requests Start
GET /api/users
Authorization: Bearer {{token}}
--
#Requests End
@capture
response.id=user_id
response.token=auth_token
GET /api/users/{{user_id}}
Authorization: Bearer {{auth_token}}
- Use meaningful variable names
- Group related requests together
- Include appropriate headers
- Document request purpose in comments
- Use proper indentation in request bodies
- Clean up captured variables when done
Note: This plugin requires 'nocompatible' mode in Vim and curl installed on your system.
Warning: Be careful with sensitive data in .rest files. Consider using environment variables for tokens and credentials.