This Neovim plugin enhances code sharing by allowing the easy copying of lines along with their file paths, line numbers, and repository URLs. By including essential metadata, it supports clearer communication, especially when collaborating with AI tools and improving coding efficiency.
copy_with_context.nvim
The copy_with_context.nvim plugin enables developers to copy code snippets with contextual metadata, including file paths, line numbers, and direct repository URLs. This functionality enhances the clarity and utility of shared code snippets, making it easier to understand the specific context where the code resides within a project.
Key Benefits
- Enhanced Context: When sharing code, including the file path and line number provides essential context that facilitates comprehension. Instead of manually appending these details, this plugin automates the process, saving time and reducing errors.
- AI-Assisted Development: When interacting with AI tools like ChatGPT and others, including file paths and line numbers significantly improves the quality of responses. AI can better understand the precise location within the code, leading to more relevant suggestions and solutions.
Practical Examples
Using this plugin transforms code sharing as illustrated below:
Without Context:
Here's my login function:
def authenticate(user)
validate_credentials(user)
end
How do I add OAuth?
With Context (using this plugin):
Here's my login function:
def authenticate(user)
validate_credentials(user)
end
# app/controllers/auth_controller.rb:45-47
# https://github.com/user/repo/blob/abc123/app/controllers/auth_controller.rb#L45-L47
How do I add OAuth?
The inclusion of line numbers and file paths allows for precise communication and aids AI tools in providing tailored guidance based on the specific codebase structure.
Usage
The plugin allows users to copy lines in different contexts, utilizing customizable key mappings for various purposes:
- Copy the current line with a relative path.
- Copy the current line with an absolute path.
- Copy a visual selection of lines with relative or absolute paths.
- Copy the current line or selection with a link to the remote repository.
Configuration Options
Customization is straightforward with options to define mappings and formats:
require('copy_with_context').setup({
mappings = {
relative = '<leader>cy',
absolute = '<leader>cY',
remote = '<leader>cr',
},
formats = {
default = '# {filepath}:{line}',
remote = '# {remote_url}',
},
trim_lines = false,
})
Repository URL Support
The plugin automatically generates links to your code snippets hosted on platforms like GitHub, GitLab, and Bitbucket, ensuring that your shared code always has the correct permalink for reference.
With copy_with_context.nvim, enhancing the quality of shared code snippets becomes efficient and effective, allowing developers to focus on coding rather than context gathering.
No comments yet.
Sign in to be the first to comment.