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
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)