1
1
# Neovim Sourcegraph Integration
2
2
3
- This repository contains a Lua script ( ` sourcegraph.lua ` ) that integrates
3
+ This repository contains a Lua plugin that integrates
4
4
[ Sourcegraph] ( https://sourcegraph.com/ ) search into Neovim. This tool helps
5
5
developers search for code snippets directly from their Neovim environment.
6
6
7
7
## Features
8
8
9
- - Fetch selected code within Neovim
10
- - URL encode the fetched code for search
11
- - Construct a Sourcegraph URL including the selected code
12
9
- Open the URL in the default browser to show search results on Sourcegraph
13
10
- Contextual search based on the file type of the current buffer
14
11
15
12
## Usage
16
13
17
14
After you've installed the script (see Installation section below), you can use
18
- it by simply selecting text in visual mode in Neovim and pressing ` <leader>S ` .
15
+ it by simply selecting text in visual mode in Neovim and pressing ` <leader>S `
16
+ (default - see below to change keybinding).
19
17
This will construct a Sourcegraph search URL with the selected text and open it
20
18
in your default web browser.
21
19
22
- ## Installation
23
-
24
- To install the script, follow these steps:
25
-
26
- 1 . Clone the repository or download the ` sourcegraph.lua ` file.
27
- 2 . Move the ` sourcegraph.lua ` file to your Neovim configuration directory (usually ` ~/.config/nvim/lua ` ).
28
- 3 . Add the following line to your Neovim configuration file (` init.vim ` or ` init.lua ` ): ` require'sourcegraph' ` .
29
- 4 . Change the mapping to the location of your path
30
-
31
- E.g.
20
+ ### Customizing the Key Binding
32
21
33
- ``` sh
34
- vnoremap < leader> S :lua require'philiplinell.sourcegraph'.search_sourcegraph ()< CR>
22
+ By default, the key binding to trigger a Sourcegraph search is ` <leader>S ` . If
23
+ you want to use a different key binding, you can set the ` g:sourcegraph_key `
24
+ variable in your ` .vimrc ` or ` init.vim ` file. For example, to use ` <leader>sg `
25
+ as the key binding, add this line:
35
26
27
+ ``` vim
28
+ let g:sourcegraph_key = '<leader>sg'
36
29
```
37
30
38
- My path is ` config/nvim/lua/philiplinell/sourcegraph.lua ` .
31
+ ## Installation
39
32
40
- ## Contributing
33
+ Using vim-plug, add the following to your ` init.vim ` or ` .vimrc ` :
41
34
42
- Contributions are welcome! Please submit a pull request or open an issue if you have any improvements or suggestions.
35
+ ` Plug 'philiplinell/sourcegraph.lua' `
43
36
44
- ## Disclaimer
37
+ Save the file and run the ` :PlugInstall ` command in Neovim.
45
38
46
- I am not used to the neovim API, lua or sourcegraph!
39
+ ## Disclaimer
47
40
48
- The majority of ` sourcegraph.lua ` was written with the help of ChatGPT, as well
49
- as the majority of this README.
41
+ This is my first Neovim plugin, and I'm still learning the Neovim API, Lua, and
42
+ Sourcegraph. I've had a lot of help from ChatGPT, OpenAI's language model, both
43
+ for writing the sourcegraph.lua script and for creating this README.
50
44
51
- These are some of the prompts that I used
45
+ I've listed some of the prompts I used with ChatGPT below, to give an idea of
46
+ how it helped create this plugin:
52
47
53
48
```
54
49
I would like to create a neovim plugin, in lua, that takes the text I have selected in visual mode and open that in a browser.
@@ -61,3 +56,7 @@ https://sourcegraph.com/search?q=context:global+QUERY&patternType=standard&sm=1
61
56
```
62
57
I'll create a repository that has the sourcegraph.lua file. Can you suggest a readme for the repository?
63
58
```
59
+
60
+ If you have any suggestions or improvements, or if you find any issues, please
61
+ don't hesitate to open an issue or a pull request. Any contributions are very
62
+ welcome!
0 commit comments