vim-so
wraps the so executable to provide a plain-language search interface
for code snippets on Stack Overflow.
Assume that you're building a Go application, and have forgotten how to reverse an array. You may run the following ex command:
:So reverse an array
The following will occur:
vim-so
will detect the currentfiletype
vim
will execute the following shell command:so -t go "reverse an array"
- The first applicable code snippet will be pasted into the current buffer
- You may cycle among snippets via
so#next()
andso#prev()
vim-so
can be installed as described in :help packages
, or by using a
package manager like Pathogen, Vundle, or Plug.
Search the Stack Overflow API for code snippets matching a phrase. It's recommended that you map this function to a convenient command:
command -nargs=1 So call so#search(<q-args>)
Cycle to the next code snippet. It's recommended that you map this function to a convenient hotkey:
nnoremap <C-N> :call so#next()<CR>
Cycle to the previous code snippet. It's recommended that you map this function to a convenient hotkey:
nnoremap <C-P> :call so#prev()<CR>
Open the Stack Overflow thread associated with the current code snippet in your web browser:
command SoView :call so#view()
The browser executable that should be used in conjunction with the so#view
function.
Here's a practical configuration example. Add these lines to your .vimrc
:
let g:so_browser = "firefox"
command -nargs=1 So call so#search(<q-args>)
command SoView call so#view()
nnoremap <C-N> :call so#next()<CR>
nnoremap <C-P> :call so#prev()<CR>