vim备忘

以指定编码打开文件原文

<!-- lang: shell -->
vim file.txt -c "e ++enc=GB18030" 
e ++enc=GB18030

保存root权限的文件

  1. vi /etc/httpd.conf 保存时,用命令:w !sudo tee % :w - Write a file. !sudo - Call shell sudo command. tee - The output of write (vim :w) command is redirected using tee. The % is nothing but current file name i.e. /etc/httpd.conf. In other words tee command is run as root and it takes standard input and write it to a file represented by %. However, this will prompt to reload file again (hit L to load changes in vim itself). 强烈推荐这一种用法。不过,首先得保证运行vim的用户有sudo的权限。

转自:这里 在《vim实用技巧》中也提到了这种方法。不过当时对*nix的命令理解不深,觉得tee是一个用户名……汗~html


从新载入文件原文

1 从新载入当前文件: :e :e! #放弃当前修改,强制从新载入 2 从新载入全部打开的文件: :bufdo e 或者 :bufdo :e! :bufdo命令表示把后面的命令应用到全部buffer中的文件。shell


#查找(不区分大小写) 查找字符+\c。其中\c能够出如今任意位置。如须要不区分大小写查找“abc”或“AbC”:vim

<!-- lang: shell -->
/abc\c
/\cabc
/a\cbc

编辑远程文件

示例为:scp://[user@]host/path 不管用scp 仍是ftp、sftp, 若是打开有问题,能够试着在帮助中所谓的host和path之间再加一个“/”试试。 如:vim scp://root@172.24.181.70//enosoft/pushserv/a.txt 而在shell中直接使用scp要在host和path之间加一个“:”呵呵~this

相关文章
相关标签/搜索