# Configure tmux to copy to system clipboard

[Tmux](https://github.com/tmux/tmux/wiki) is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.

I love Tmux because using [Tmux](https://github.com/tmux/tmux/wiki) + [Neovim](https://neovim.io) makes a great IDE.

Depending on which Terminal app you are using, some things in Linux if you copy content from within the [Tmux](https://github.com/tmux/tmux/wiki) session, you can't paste them outside of [Tmux](https://github.com/tmux/tmux/wiki), which can be a big pain most of the time.

To solve that problem we are going to install [Xclip](https://github.com/astrand/xclip), it is a command line utility that is designed to run on any system with an X11 implementation and it allows you to use clipboard from your command line.

### Install Xclip

```bash
sudo apt install xclip
```

### Configure Tmux to use Xclip

Put following script in your tmux configuration file `vim ~/.tmux.conf`

```bash
#for copying to sys clipboard
bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"
bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"
bind -T copy-mode-vi C-j send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"
```

Reload your tmux session usually `prefix + r` . And your clipboard from tmux session should work again.
