https://github.com/zhisme/copy_with_context.nvim
Copy lines in nvim with file path and line number metadata. Perfect for sharing code snippets with context.
https://github.com/zhisme/copy_with_context.nvim
Last synced: 28 days ago
JSON representation
Copy lines in nvim with file path and line number metadata. Perfect for sharing code snippets with context.
- Host: GitHub
- URL: https://github.com/zhisme/copy_with_context.nvim
- Owner: zhisme
- License: mit
- Created: 2025-03-18T10:55:21.000Z (about 1 month ago)
- Default Branch: master
- Last Pushed: 2025-03-20T20:03:45.000Z (about 1 month ago)
- Last Synced: 2025-03-20T21:39:14.778Z (about 1 month ago)
- Language: Lua
- Homepage:
- Size: 11.7 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-neovim-sorted - zhisme/copy_with_context.nvim
- awesome-neovim-sorted - zhisme/copy_with_context.nvim
README
# copy_with_context.nvim

[](https://hitsofcode.com/github/zhisme/copy_with_context.nvim/view)

Copy lines with file path and line number metadata. Perfect for sharing code snippets with context.
## Why?
When sharing code snippets, it's often useful to include the file path and line number for context. This plugin makes it easy to copy lines with this metadata. It is easier to understand the context of the code snippet when the file path and line number are included. Otherwise you have to do it manually. Copying snippet, then adding the line number (what if it is long config file? it is boring). We can automate it and do not waste our time.
## Installation
- Using [packer.nvim](https://github.com/wbthomason/packer.nvim):
```lua
use({
'zhisme/copy_with_context.nvim'
})
```- Using [vim-plug](https://github.com/junegunn/vim-plug):
```vim
call plug#begin()" Other plugins...
Plug 'zhisme/copy_with_context.nvim'call plug#end()
```## Usage
1. Copy current line with relative path:
- Press `cy` in normal mode.
- Plugin copies line under cursor with relative path into your unnamed register.
- Paste somewhereOutput example:
```
<% posts.each do |post| %>
# app/views/widgets/show.html.erb:4
```2. Copy current line with absolute path:
- Press `cY` in normal mode.
- Plugin copies line under cursor with absolute path into your unnamed register.
- Paste somewhereOutput example:
```
<% posts.each do |post| %>
# /Users/zh/dev/project_name/app/views/widgets/show.html.erb:4
```3. Copy visual selection with relative path:
- Select lines in visual mode.
- Press `cY`.
- Plugin copies the selected lines with relative path into your unnamed register.
- Paste somewhereOutput example:
```
<% posts.each do |post| %>
<%= post.title %>
<% end %>
# app/views/widgets/show.html.erb:4-6
```4. Copy visual selection with absolute path:
- Select lines in visual mode.
- Press `cY`.
- Plugin copies the selected lines with absolute path into your unnamed register.
- Paste somewhereOutput example:
```
<% posts.each do |post| %>
<%= post.title %>
<% end %>
# /Users/zh/dev/project_name/app/views/widgets/show.html.erb:4-6
```## Configuration
There is no need to call setup if you are ok with the defaults.
```lua
-- default options
require('copy_with_context').setup({
-- Customize mappings
mappings = {
relative = 'cy',
absolute = 'cY'
},
-- whether to trim lines or not
trim_lines = true,
context_format = '# %s:%s', -- Default format for context: "# Source file: filepath:line"
-- context_format = '# Source file: %s:%s',
-- Other format for context: "# Source file: /path/to/file:123"
})
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/zhisme/copy_with_context.nvim. Ensure to test your solution and provide a clear description of the problem you are solving.## License
The plugin is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).