DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Terminal in Neovim


To build a pure keyboard working environment, a problem is how to select texts in terminal (then copy them). I've tried to solve this with select plugin of urxvt, but it can't work as expected from time to time.

The following solution use the terminal mode of neovim instead. Thus which terminal emulator (gnome-terminal, urxvt or xfce-terminal) to use is irrelevant. Most of the time we work in terminal mode, and swtich to normal mode to select, copy and paste texts.

To make the workflow smooth, I created the following script for this scenario, in which defined some runtime attributes, some convenient keyboard shortcuts, start terminal mode, turned on insert for receive user input:

cat << EOF > ~/.config/nvim-term.vim
set clipboard+=unnamedplus
set nobackup
set noswapfile
set incsearch
set nowrap
set nonumber
set laststatus=0

tnoremap <C-o> <C-\><C-n>
tnoremap <C-q> <C-\><C-n>:q<CR>

terminal
startinsert
EOF

Then modify the shortcut of starting terminal in i3 configuration:

bindsym $mod+Return exec gnome-terminal -- $HOME/.linuxbrew/bin/nvim -u $HOME/.config/nvim-term.vim

Notes:

Here is used to quit the terminal, to enter the normal mode for text manipulation. & is not chosen intentionally to avoid conflicting with applications in terminal.

If you need for the application inside terminal instead of terminal itself, remove mapping for neovim with:

  1. go back to normal mode with
  2. run command :tunmap <C-q>

Now you can use freely. To quit the terminal, and :q.

For the i3 shortcut:

  • The -- following gnome-terminal is mandatory;
  • Absolute paths of executable and script must be used to avoid "file not found" error.


Published

Oct 20, 2020

Last Updated

Nov 1, 2020

Category

Tech

Tags

  • neovim 3
  • select text 1
  • terminal 8

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor