DEV Community

Ajeeb.K.P
Ajeeb.K.P

Posted on

clipboard sync with sudo vim

Intro

This post explains, how to sync the system clipboard with vim while using sudo.

Install some gui for vim

Some GUI version of vim like vim-gtk3, vim-gtk, or vim-athena for making clipboard work. Because, the plain vim is not compiled with clipboard flags enabled (at least in Debian based Distros).

sudo apt install vim-gtk3

Configure clipboard

Switch to root user
sudo su

Now edit root user's vimrc (vim config file)
vim ~/.vimrc

Add this line,

set clipboard=unnamed,unnamedplus

Pro tip

Use a minimal vim config like this to make your life easier

set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set nu
set ic
set is
set smartindent
set clipboard=unnamed,unnamedplus
syntax on
Enter fullscreen mode Exit fullscreen mode

Result

After following this post, you will be able to work with sudo vim and the system clipboard will sync once you copy/cut/paste the content from vim.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more