Skip to content

andrewwoods/vim-copy-path-reference

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Copy Path Reference for Vim

Copy your file location to your system clipboard

There's a useful feature in PhpStorm (and other JetBrains editors) that's is missing in Vim. That's the Copy Reference command that copies the path to the file and the line number to your system clipboard. Well, it's not missing, technically speaking. It is kind of buried though, and not really intuitive. This plugin makes it easy to share your exact position in the project with another developer.

Vim and Neovim by default doesn't have an established project root. In Vim, your project "root", is determined by where you start Neovim or Vim. Relative paths use this directory. The functions of this plugin are descriptively named to wrap the builtin Vim functionality.

CopyBaseFilename
CopyBaseFilenameAndLineNumber
CopyFullPath
CopyFullPathAndLineNumber
CopyFullDirectory
CopyRelativeDirectory
CopyRelativePath
CopyRelativePathAndLineNumber

Suggested Leader Mappings

Neovim

vim.keymap.set("n", "<leader>cb", "<cmd>CopyBaseFilenameAndLineNumber<CR>", { desc = "[C]opy [B]ase Filename" })
vim.keymap.set("n", "<leader>cd", "<cmd>CopyFullDirectory<CR>", { desc = "[C]opy Full [D]irectory" })
vim.keymap.set("n", "<leader>cf", "<cmd>CopyFullPathAndLineNumber<CR>", { desc = "[C]opy [F]ull Path" })
vim.keymap.set("n", "<leader>cp", "<cmd>CopyRelativePathAndLineNumber<CR>", { desc = "[C]opy Relative [P]ath" })
vim.keymap.set("n", "<leader>cr", "<cmd>CopyRelativeDirectory<CR>", { desc = "[C]opy [R]elative Directory" })

Vim

nnoremap <leader>cb :CopyBaseFilenameAndLineNumber<CR>
nnoremap <leader>cd :CopyFullDirectory<CR>
nnoremap <leader>cf :CopyFullPathAndLineNumber<CR>
nnoremap <leader>cp :CopyRelativePathAndLineNumber<CR>
nnoremap <leader>cr :CopyRelativeDirectory<CR>

Version

The current version is 0.9.1. This project uses semantic versioning.

Examples

Base Filename

The CopyBaseFilename - copies the last segment of the file path in the clipboard.

README.md

CopyBaseFilenameAndLineNumber - copies the last segment of the file path in the clipboard.

README.md:29

Full Paths

CopyFullDirectory - copies the absolute path of the directory containing the file into the clipboard.

/Users/awoods/src/public/vim-file-reference

CopyFullPath - copies the absolute path of the file into the clipboard.

/Users/awoods/src/public/vim-file-reference/README.md

CopyFullPathAndLineNumber - copies the absolute path of the file and current line number into the clipboard.

/Users/awoods/src/public/vim-file-reference/README.md:47

Relative Paths

CopyRelativeDirectory - copies the relative directory of the file into the clipboard. If the current file is in the "project root", this will return a period. Otherwise, the path will begin with the directory below the project root.

.

A file like docs/CONTRIBUTING.md would return the following value.

docs

CopyRelativePath - copies the relative path of the file into the clipboard.

README.md

CopyRelativePathAndLineNumber - copies the relative path of the file and current line number into the clipboard.

README.md:66

Ideas for sections/pages

  • Language Translations
  • Frequently Asked Questions (FAQ)
  • Screenshots

Resources

Credits and Acknowledgments

About

PhpStorms Copy Path/Reference for Vim

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published