Use the same terminal for everything. The main reason for this plugin is reuse the terminal easily. All commands opens a terminal if it's not open or reuse the open terminal. REPL commands, opens a terminal and the proper REPL, if it's not opened.
- NeoVim terminal helper functions/commands.
- Wraps some test libs to run easilly within NeoVim terminal.
- Wraps some REPL to receive current line or selection.
- Many terminals support:
Run test libs with 3 different scopes:
- all (
neoterm#test#run('all')
):
Run all tests from the current project. For a Rails project with rspec, it's the
command: rspec
.
- file (
neoterm#test#run('file')
):
Run the current test file. For a Rails project with rspec, it's the command:
rspec spec/path/to/file_spec.rb
.
- current (
neoterm#test#run('current')
):
Run the nearst test in the current test file. For a Rails project with rspec,
it's the command: rspec spec/path/to/file_spec.rb:123
.
- rspec
- You can override the default command (
bundle exec rspec
) using theg:neoterm_rspec_lib_cmd
- Status in statusline supported
- You can override the default command (
- cucumber
- You can override the default command (
bundle exec cucumber
) using theg:neoterm_cucumber_lib_cmd
- You can override the default command (
- minitest
- Status in statusline supported
- rake
- it's like minitest but it doesn't support minitest status and uses rake
commands like the following:
- all:
rake test
- file:
rake test TEST=file
- current: `rake test TEST=file TESTOPTS="--name="/test name/""
- all:
- it's like minitest but it doesn't support minitest status and uses rake
commands like the following:
- go-lang test (partially implemented)
- nose (partially implemented)
- Cargo (partially implemented)
- npm
- You can override the default command (
npm test
) using theg:neoterm_npm_lib_cmd
- You can override the default command (
- elixir
TREPLSend
: sends the current line or the selection to a REPL in a terminal.TREPLSendFile
: sends the current file to a REPL in a terminal.
- Ruby:
pry
andirb
- Rails:
bundle exec rails console
- Python:
ipython
andpython
- JavaScript:
node
- Elixir:
iex
- Julia:
julia
- R / R Markdown:
R
- Haskell:
ghci
- Idris:
idris
- GNU Octave:
octave
- For Octave 4.0.0 and later, you can enable Qt widgets (dialogs, plots, etc.) using
g:neoterm_repl_octave_qt = 1
- For Octave 4.0.0 and later, you can enable Qt widgets (dialogs, plots, etc.) using
- MATLAB:
matlab -nodesktop -nosplash
- PARI/GP:
gp
The REPL is set using the filetype plugin so make sure to set
filetype plugin on
Most standard file extensions for the above REPLs are picked up by Neovim's default filetype plugins. However, there are two exceptions:
- Julia
.jl
files, which are detected asfiletipe=lisp
- Idris
.idr
,.lidr
files which are not recognised as any filetype To fix this, either install a suitable plugin for the language or add something like the following to yourinit.vim
:
au VimEnter,BufRead,BufNewFile *.jl set filetype=julia
au VimEnter,BufRead,BufNewFile *.idr set filetype=idris
au VimEnter,BufRead,BufNewFile *.lidr set filetype=lidris
:T <command>
: Opens a terminal, or use an opened terminal, and runs the given command within a terminal.:Tmap <command>
: maps a the given command to,tt
.
Open a pull request, I'll be glad in review/add new test libs, repls and other features to this plugin. 😃
A test lib is defined by a function and an autocommand group.
.nvim/plugged/neoterm/
▾ autoload/
▾ neoterm/
▾ test/
rspec.vim
▾ ftdetect/
rspec.vim
The function (neoterm#test#<lib_name>#run
) will return the command, by the
given scope, that will be runned in a terminal window. This function should be
defined in its own file: /autoload/neoterm/test/<lib_name>.vim
.
- autoload/neoterm/test/rspec.vim
function! neoterm#test#rspec#run(scope)
let path = g:neoterm_use_relative_path ? expand('%') : expand('%:p')
let command = 'rspec'
if a:scope == 'file'
let command .= ' ' . path
elseif a:scope == 'current'
let command .= ' ' . path . ':' . line('.')
endif
return command
endfunction
The autocommand group will detect when the lib should be available. For example,
the rspec is available when exists a file spec/spec_helper.rb
on the current
folder, or when a file that matches with *_spec.rb
or *_feature.rb
is
opened.
- ftdetect/rspec.vim
aug neoterm_test_rspec
au VimEnter,BufRead,BufNewFile *_spec.rb,*_feature.rb call neoterm#test#libs#add('rspec')
au VimEnter *
\ if filereadable('spec/spec_helper.rb') |
\ call neoterm#test#libs#add('rspec') |
\ endif
aug END
let g:neoterm_position = 'horizontal'
let g:neoterm_automap_keys = ',tt'
nnoremap <silent> <f10> :TREPLSendFile<cr>
nnoremap <silent> <f9> :TREPLSendLine<cr>
vnoremap <silent> <f9> :TREPLSendSelection<cr>
" run set test lib
nnoremap <silent> ,rt :call neoterm#test#run('all')<cr>
nnoremap <silent> ,rf :call neoterm#test#run('file')<cr>
nnoremap <silent> ,rn :call neoterm#test#run('current')<cr>
nnoremap <silent> ,rr :call neoterm#test#rerun()<cr>
" Useful maps
" hide/close terminal
nnoremap <silent> ,th :call neoterm#close()<cr>
" clear terminal
nnoremap <silent> ,tl :call neoterm#clear()<cr>
" kills the current job (send a <c-c>)
nnoremap <silent> ,tc :call neoterm#kill()<cr>
" Rails commands
command! Troutes :T rake routes
command! -nargs=+ Troute :T rake routes | grep <args>
command! Tmigrate :T rake db:migrate
" Git commands
command! -nargs=+ Tg :T git <args>