DEV Community 👩‍💻👨‍💻

Cason Adams
Cason Adams

Posted on

Fun vi shortcut to open a terminal in vi

I prefer to use tmux for multiplexing terminals. However, I just learned / figured out how to kind of make this work like I do with tmux. Mind you not as flexible.

Add this snippet to vimrc or init.vim file

init.vim

nmap <Leader>t :call Terminal()<CR>

function! Terminal()
  :set splitbelow
  :set splitright
  :10split
  :set laststatus=0
  :set scl=no
  :set nonu
  :term
endfunction

autocmd TermOpen * startinsert

tnoremap <Esc> <C-\><C-n> <bar> :call ExitTerminal()<CR>
function! ExitTerminal()
  :set nosplitbelow
  :set nosplitright
  :set laststatus=2
  :set scl=yes
  :set number
  :q!
endfunction

Enter fullscreen mode Exit fullscreen mode

Now when you <Leader>t you will drop into a terminal in vi

Notes

To exit use <Esc>

Top comments (2)

Collapse
 
ayoubelmhamdi profile image
ayoubelmhamdi

cool ❤️ and very fast and useful for me in androd/termux

Collapse
 
sq5rix profile image
Tom

Cool stuff thanks!!

Stop sifting through your feed.

Find the content you want to see.

Change your feed algorithm by adjusting your experience level and give weights to the tags you follow.