DEV Community

Me1onRind
Me1onRind

Posted on

Vim plugin: Sync your file(such as .vimrc) to gist

How save your .vimrc to remote storage like other IDEs, it's a problem for me. I didn't find any vim plugin meet my needs, so be inspired by terminus-sync-config, I write a plugin to do that. Currently only support gist, but it's extensible.

Feature

After configurate your gist id and local filepath and remote filename mapping, you can open your .vimrc, then use :PushConfig and :PullConfig to upload/donwload .vimrc.

Of course, It's support all text file.

Plugin

https://github.com/Me1onRind/EscSync
There is more detail in plugin's README.MD.

Top comments (2)

Collapse
 
pbnj profile image
Peter Benjamin (they/them)

Alternative (simpler?) methods:

Method 1: Git Repository

If you have a dotfiles git repo, you can check in your .vimrc to your repo:

git add .vimrc
git commit
git push
Enter fullscreen mode Exit fullscreen mode

Then you can pull it down from other machines:

git clone https://github.com/<user>/<repo>
Enter fullscreen mode Exit fullscreen mode

Method 2: GitHub Gist CLI

If you use the official GitHub CLI gh cli, you can create a GitHub Gist with your .vimrc:

gh gist create /path/to/your/vimrc
Enter fullscreen mode Exit fullscreen mode

Future syncs will require that you know the Gist ID. You can get it with gh gist list and then update it with gh gist edit or you can do it in one-line:

gh gist edit $(gh gist list | fzf --reverse --height 20 | awk '{print $1}') --filename=.vimrc .vimrc`
Enter fullscreen mode Exit fullscreen mode

This will allow you to fuzzy search through you GitHub gists, select the correct gist, and update the .vimrc file in the gist with .vimrc file from your machine.

Method 3: Vim Plugin

If you would like to sync vimrc from within Vim, you can create a vim command:

command! PushConfig !gh gist edit $GIST_ID -f vimrc $MYVIMRC
command! PullConfig   %!gh gist view $GIST_ID
Enter fullscreen mode Exit fullscreen mode
Collapse
 
me1onrind profile image
Me1onRind

I think method1 or method2 is not concise, I will try method3, thank you.