在写简书的时候需要复制vim中的文件,如果直接复制粘贴,效果如下:
8 from django.db import models
7 from django.utils import timezone
6 from django.contrib.auth.models import User
5
4 # Create your models here.
3
2 class Post(models.Model):
1 STATUS_CHOICES = (
9 ('draft','Draft'),
1 ('published','Published'),
2 )
3 title = models.CharField(max_length=250)
4 slug = models.SlugField(max_length=250,unique_for_date='publish')
5 author = models.ForeignKey(User,on_delete=models.CASCADE,related_name='blog_posts')
6 body = models.TextField()
7 publish = models.DateTimeField(default=timezone.now)
8 created = models.DateTimeField(auto_now_add=True)
9 updated = models.DateTimeField(auto_now=True)
10 status = models.CharField(max_length=10,choices=STATUS_CHOICES,default='draft')
11
12 class Meta:
13 ordering = ('-publish',)
14
15 def __str__(self):
16 return self.title
直接把行号也粘上了,效果很差。经查阅相关资料,解决方案如下:
1. 首先,查看vim版本是否支持clipboard
zzx@zzx:~$ vim --version | grep clipboard
+clipboard +jumplist +persistent_undo +vartabs
+eval +mouse_gpm +syntax +xterm_clipboard
2. 如果有 +clipboard 则跳过这一步; 如果显示的是 -clipboard 说明不支持, 需要
- ubuntu
sudo apt-get install vim-gtk
3. vim的寄存器
打开vim输入:reg查看vim的寄存器,当支持clipboard之后,会多出"+寄存器,表示系统剪切板。
4. "+yG
vim的normal模式下输入:"+yG
,vim提示:
25 lines yanked into "+
之后粘贴到简书中,效果如下:
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
# Create your models here.
class Post(models.Model):
STATUS_CHOICES = (
('draft','Draft'),
('published','Published'),
)
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250,unique_for_date='publish')
author = models.ForeignKey(User,on_delete=models.CASCADE,related_name='blog_posts')
body = models.TextField()
publish = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=10,choices=STATUS_CHOICES,default='draft')
class Meta:
ordering = ('-publish',)
def __str__(self):
return self.title
完美!