DEV Community

Discussion on: What's your favorite Vim trick?

Collapse
 
jkreeftmeijer profile image
Jeff Kreeftmeijer

Don't worry, I’m a neovim user myself. ✊

I’m actually the other way around in regards to neovim’s :terminal, though. I am using tmux, and prefer splitting the tmux window instead of starting a terminal session in Vim.

I must say I’ve never taken the time to set :terminal up properly, as I’m still getting a couple of “command not found” errors when starting it.

Fun fact: I’ve actually tried using tmux splits instead of Vim’s built-in ones a while back, but that didn’t really work because I didn’t find a way to share sessions between Vim instances.

So, what does your workflow look like? Do you open up Vim and do everything from there, in one instance?

Collapse
 
jesus_abark profile image
Jesús Abarca • Edited

Yes, I do everything inside Nvim now. When I was using Vim+Tmux, I was using a plugin for moving between Vim and Tmux panes transparently. I also needed special config for getting access to the system's clipboard. That wasn't necessary when I got rid of Tmux. Are you using those plugins?

The only thing I had to do for getting my Nvim's terminal splits just the same as iTerm's was to source my .bashrc file inside .bash_profile. I also added some useful mappings like:

  " Maps ESC to exit terminal's insert mode
  if has('nvim')
    tnoremap <Esc> <C-\><C-n>
  endif

  " Maps ctrl-b + c to open a new tab window
  nnoremap <C-b>c :tabnew +terminal<CR>
  tnoremap <C-b>c <C-\><C-n>:tabnew +terminal<CR>

  " Maps ctrl-b + " to open a new horizontal split with a terminal
  nnoremap <C-b>" :new +terminal<CR>
  tnoremap <C-b>" <C-\><C-n>:new +terminal<CR>

  " Maps ctrl-b + % to open a new vertical split with a terminal
  nnoremap <C-b>% :vnew +terminal<CR>
  tnoremap <C-b>% <C-\><C-n>:vnew +terminal<cr>

also removed the number lines and got terminal buffers to automatically enter into insert mode with

  augroup neovim_terminal
    autocmd!

    " Enter Terminal-mode (insert) automatically
    autocmd TermOpen * startinsert

    " Disables number lines on terminal buffers
    autocmd TermOpen * :set nonumber norelativenumber
  augroup END

I'm attaching a screenshot of my current setup. Also here's my dot file repo if you want to take a look 🤓 github.com/jesusabarca/.dotfiles

Current setup:
alt text

Thread Thread
 
jkreeftmeijer profile image
Jeff Kreeftmeijer

I use vim-tmux-navigator to switch between Vim and tmux splits, configure Vim to use the unnamed paste buffer, and use reattach-to-user-namespace to do the same in tmux (although that doesn’t seem to be required anymore).

I’ll try the built-in terminal again sometime soon, though!