linux 强制刷新文件,vim 如何刷新或重载reload 已打开的文件

Ref:vim 如何刷新或重载reload 已打开的文件

Just use

:e

to reload the file.  I believe, if you've made changes to the

file, it requires you to do

:e!

to force-discard your local changes and reload from the disk.

If I'm not sure, I'll often yank my current copy into a scratch

buffer/window, force-reload the file from disk, and then use

:diffthis

on each of the two buffers/windows to verify that there are no

surprises.

You may also be interested in the 'autoread' setting.

More information at

:help FileChangedShell

:help 'autoread'

:help :e

:help :diffthis

-tim

I have found, that the most comfortable way to do this is

DiffOrig command, described in the VIM help (you should define it

self though). One this command does the something very similar to

all those copy/paste/force reload/diffthis stuff.

:help DiffOrig

To reload unconditionally, from wherever it is, the file you're

curretly editing:

:e    " read-write if the file has read-write permissions

or

:view    " always readonly

- To check whether any of the file(s) you're currently editing has been

changed by someone else:

:checkt[ime]

If a file or its datestamp have changed, then if 'autoread' is set and

the file is not 'modified' in your instance of Vim, Vim will reload it

without prompting. Otherwise, Vim will ask you what you want to do about

the change.

See

:help :edit

:help :checktime

:help 'autoread'

Random;

but I liked this command; so wrote a little wrapper to toggle it...

(broken if you change buffers I know, but my scripting is horrible at

best for vim)

function! DiffOrig()

if &diff

wincmd p | bdel | diffoff

else

vert new | set bt=nofile | r # | 0d_ | diffthis | wincmd p | diffthis

endif

endfunction

map do :call DiffOrig()

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要在Linux中使用vim打开文件,可以按照以下步骤操作: 1. 打开终端窗口。 2. 输入命令“vim 文件名”,其中“文件名”是你要打开文件名。 3. 按下回车键,vim将会打开文件。 4. 在vim中编辑文件内容,可以使用各种命令和快捷键进行编辑。 5. 编辑完成后,按下Esc键退出编辑模式,然后输入命令“:wq”保存文件并退出vim。 6. 如果只是想退出vim而不保存文件,可以输入命令“:q!”强制退出vim。 ### 回答2: 在Linux系统下,我们经常会使用到vim来编辑文件,接下来我将介绍如何使用vim打开文件。 第一步,打开终端。在Linux中,您可以使用Ctrl+Alt+T快捷键来打开一个终端。 第二步,用vim命令打开文件打开文件的命令格式为: vim 文件名 例如,我们要打开一个名为test.txt的文本文件,在终端输入: vim test.txt 第三步,开始编辑文件。当文件打开后,您将看到屏幕中的文本内容。可以使用方向键在文件中移动光标,也可以直接使用鼠标单击定位光标到要编辑的位置。接着您可以开始编辑文件了。 第四步,保存修改并退出。当您编辑完文件后,需要保存并退出vim。保存文件的命令是:按下Esc键,然后进入命令行模式(输入:)并输入wq命令,即: :wq 该命令表示:保存修改并退出。 如果您只想保存而不退出vim,则可以使用w命令,即: :w 如果您对文件修改后不满意,可以使用q!命令把修改撤销掉并强制退出vim: :q! 总之,使用vim打开文件非常简单。注意在编辑文件时要注意使光标处于正确的位置,以免误操作。编辑完成后,及时保存。祝您使用愉快! ### 回答3: Linux是一种适用于服务器和个人电脑的操作系统,它的强大之处在于其可编程性和自由度。而Vim则是一款在Linux系统上广为流传的文本编辑器,它能够利用命令行的方式完成文本编辑任务。 在Linux系统中,使用Vim打开文件非常简单。只需要按下键盘上的“Ctrl”+“Alt”+“T”等快捷键打开终端,然后使用“cd”命令进入要打开文件所在的目录。如:cd Desktop,即可进入桌面目录。 进入目录后,使用命令“vim 文件名”打开需要编辑或查看的文件,即可进入Vim编辑模式。在这个模式下,你可以使用各种快捷键完成对文本的操作。如,“i”键进入插入模式,在该模式下,你可以随心所欲地编辑。当你完成编辑后,再按下“Esc”键即可回到命令模式,此时你可以使用各种命令完成对文本的保存、关闭等操作。如,使用命令“:w”保存更改,使用“:wq”保存并退出Vim编辑器。 需要注意的是,Vim编辑器的操作可能会相对繁琐,需要根据不同的需求选择不同的快捷键和命令。初次接触Vim的使用者,建议多参考官方文档和其他的技术博客,逐步熟悉各种功能和操作。同时,也可以尝试其他的Linux文本编辑器,如Nano和Emacs等,以更好地适应不同的编辑需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值