I created this plugin to make it easy to do two things:
If you are in the pwd
of an open source github/gitlab project...
- yank and paste a formatted and syntax highlighted code block in a markdown document (eg vimwiki)
- paste the formatted code block in an email / slack channel etc. (with links to the source code)
In addition to the yanked text adds:
- a link to the source code web repository
- a relative file location / line number to the source code (to work with
gF
)
-
Install using your favorite vim package manager
-
Create a vmap eg.
vnoremap \my :call MarkdownCodeYank()<cr>
- Go to an open source project directory
Eg. if you have neovim checked out...
michael@pop-os:~/github/neovim$ git remote -v
origin https://github.com/neovim/neovim (fetch)
origin https://github.com/neovim/neovim (push)
michael@pop-os:~/github/neovim$
-
Select a Code Segment in visual mode and use your vmap (eg,
\my
for the above mapping) -
Navigate to your markdown notes file and paste.
It should paste (p
) something like this...
`src/nvim/main.c:202 - 209` [web](https://github.com/neovim/neovim/blob/master/src/nvim/main.c#L202-L209)
\`\`\`c
#ifdef MAKE_LIB
int nvim_main(int argc, char **argv); // silence -Wmissing-prototypes
int nvim_main(int argc, char **argv)
#elif defined(WIN32)
int wmain(int argc, wchar_t **argv_w) // multibyte args on Windows. #7060
#else
int main(int argc, char **argv)
#endif
\`\`\`
or as formatted ...
src/nvim/main.c:202 - 209
web
#ifdef MAKE_LIB
int nvim_main(int argc, char **argv); // silence -Wmissing-prototypes
int nvim_main(int argc, char **argv)
#elif defined(WIN32)
int wmain(int argc, wchar_t **argv_w) // multibyte args on Windows. #7060
#else
int main(int argc, char **argv)
#endif
- Unicode Names and weird characters. Please test and complain or pr.
- Note in this early version it currently clobbers the
"
and+
registers with slightly different hadling of the#
character. This is to make it easier to paste withp
in vimwiki format and<ctrl-v>
in a slack channel. but if you set up the default register to "+" then it will paste incorrectly. - weird filetypes might need to be changed manually in source.
- Add bitbucket support
- private repo / custom namespace support for (github/gitlab/bitbucket)
This is a quick rewrite of this gist I wrote to navigate through a large gitlab namespaced project directory. If you are having trouble with this plugin perhaps look at that.
Note the trick is to have your ~/Code/namespaced/project/structure/
arranged locally
in the same pattern as the gitlab project structure (ie not flat to ~/Code/).
https://gist.github.com/mjbrownie/d537aa133a446ecc187064923aa3e1ff