GithubHelp home page GithubHelp logo

neoterm's Introduction

neoterm

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.
    • Running, Success, Failed: status on statusline supported (matching the test result #25): test-status-line
  • Wraps some REPL to receive current line or selection.
  • Many terminals support many-terms

test libs

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.

test libs supported

  • rspec
    • You can override the default command (bundle exec rspec) using the g:neoterm_rspec_lib_cmd
    • Status in statusline supported
  • cucumber
    • You can override the default command (bundle exec cucumber) using the g:neoterm_cucumber_lib_cmd
  • minitest
    • Status in statusline supported
  • go-lang test (partially implemented)
  • nose (partially implemented)
  • Cargo (partially implemented)
  • npm
    • You can override the default command (npm test) using the g:neoterm_npm_lib_cmd

REPL

  • 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.

REPL supported

  • irb
  • bundle exec rails console

other useful commands:

  • :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.

Contributing

Open a pull request, I'll be glad in review/add new test libs, repls and other features to this plugin. 😃

how add a new test lib

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 command = 'rspec'

  if a:scope == 'file'
    let command .= ' ' . expand('%:p')
  elseif a:scope == 'current'
    let command .= ' ' . expand('%:p') . ':' . 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

example config file:

let g:neoterm_position = 'horizontal'
let g:neoterm_automap_keys = ',tt'

nnoremap <silent> <f10> :TREPLSendFile<cr>
nnoremap <silent> <f9> :TREPLSend<cr>
vnoremap <silent> <f9> :TREPLSend<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>

neoterm's People

Contributors

bitboxer avatar christian-schulze avatar dangalipo avatar gravndal avatar ianks avatar icholy avatar jodosha avatar kassio avatar leonardt avatar npbee avatar pcaneill avatar rtwo avatar ukuloskit avatar vhakulinen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.