DEV Community

Cover image for Vim to the rescue: Attached Terminal
Angad Sharma
Angad Sharma

Posted on

6 2

Vim to the rescue: Attached Terminal

Introduction

I was recently working on some C++ code using vim and had to switch to a terminal to compile the code everytime I wanted to test it. Granted that this problem can be solved by installing a plugin which compiles on save, but I wanted an intuitive attached terminal instead.

The problem with terminals inside vim is that they open either in a new tab or in a new split pane. By default, a terminal in vim looks like this:

:term
Enter fullscreen mode Exit fullscreen mode

Alt Text


What can be better

In the screenshot above, there are a few problems:

  • The split pane is too big, and occupies half of the screen
  • You have to enter a command everytime you want a terminal, it is slow
  • The split pane opens up in the top part of the screen by default

What we want to achieve

Alt Text

The benefits we get here are:

  • The terminal opens at the bottom (like it should)
  • The size of the attached terminal is ideal
  • The whole action is bound to a key, so it is fast

To configure your attached terminal this way, you can add the following lines in your .vimrc:

" SpawnTern function
" To add a terminal at the bottom
function SpawnTern()
    " spawn terminal below
    bel term

    " Decrease split size by 15 words
    15winc -
endfunction

" We bind the control+x keys to spawn the terminal
noremap <c-x> :call SpawnTern()<CR>
Enter fullscreen mode Exit fullscreen mode

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay