vim

vim字符串替换命令

我与影子孤独终老i 提交于 2020-01-21 11:12:45
:%s/str1/str2/g 替换每一行中所有str1为str2 常用! :s/str1/str2/g 替换当前行所有str1为str2 基本替换 :s/str1/str2/ 替换当前行第一个str1为str2 :s/str1/str2/g 替换当前行所有str1为str2 :n,$s/str1/str2/ 替换第 n 行开始到最后一行中每一行的第一个str1为str2 :n,$s/str1/str2/g 替换第 n 行开始到最后一行中每一行所有str1为str2 (n 为数字,若 n 为 .,表示从当前行开始到最后一行) :%s/str1/str2/(等同于 :g/str1/s//str2/) 替换每一行的第一个str1为str2 :%s/str1/str2/g(等同于 :g/str1/s//str2/g) 替换每一行中所有str1为str2 可以使用 # 作为分隔符,此时中间出现的 / 不会作为分隔符 :s#str1/#str2/# 替换当前行第一个str1/ 为str2/ :%s+/str11/str12/+/str21/str22+ (使用+ 来 替换 / ): /str11/str12/替换成/str21/str22/ 文件中删除^M 问题描述:对于换行,Windows下用回车换行(0A0D)来表示,Linux下是回车(0A)来表示。这样

Limiting a match in vim to certain filetypes?

若如初见. 提交于 2020-01-21 10:57:08
问题 I have the following in my .vimrc to highlight lines longer than 80 chars: highlight OverLength ctermbg=red ctermfg=white guibg=#592929 match OverLength /\%81v.*/ This works quite well. However, the problem is that I would prefer it if it only worked on certain file types. Basically, any programming language should be highlighted and things like html, xml, and txt files should not be. I'm pretty sure I could do this easily with an autocmd, but I'm not sure if that is the best way to

nignx优化

本秂侑毒 提交于 2020-01-21 09:37:29
http错误代码 200:一切正常 401:用户名或密码错误 403:禁止访问 404:文件不存在 500:服务器内部错误 自定义报错页面(404) vim /usr/local/nginx/conf/nginx.conf .. .. charset utf-8 ; #仅在需要中文时修改该选项 error_page 404 /404.html ; #自定义错误页面 .. .. yum list | grep google | grep chinese #中文包 查看服务器状态信息 编译安装时使用–with-http_stub_status_module开启状态页面模块 1)语法格式: … … location /status { stub_status on ; #allow IP地址; #deny IP地址; } … … 2)使用方法 访问服务器下的/status页面: Active connections: 1 server accepts handled requests 10 10 30 Reading: 0 Writing: 1 Waiting: 0 //Active connections:当前活动的连接数量。 Accepts:已经接受客户端的连接总数量。 Handled:已经处理客户端的连接总数量。(一般与accepts一致,除非服务器限制了连接数量)。

CSV search and replace

纵饮孤独 提交于 2020-01-21 09:17:05
问题 I want to replace a series of pipeline characters with different values, how would I do this with regular expressions? Example: This | is | a | sentence And | this | is | the | second | one Final result: This new is new2 a new3 sentence And new this new2 is new3 the new4 second new5 one 回答1: If substitution values differ only in the numbers at the ends, use the command :let n=[0] | %s/|/\='new'.map(n,'v:val+1')[0]/g (See my answer to the question "gVim find/replace with counter" for detailed

vim <C-S-Key> mapping

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-21 09:08:23
问题 I am working with Cygwin/Mintty/Vim. With <C-v> I see that <C-S-c> is encoded <83> . This mean vim can read it and I can map it using the map command. Unfortunately if I try: :inoremap <C-S-c> foobar it doesn't work... How can I make it work and why vim refuses to map Unicode keystokes? Same question for <C-S-F1> . If I execute this command: :inoremap <C-S-F1> foobar I will get something like this: [20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5

vim default syntax for files with no extension

こ雲淡風輕ζ 提交于 2020-01-21 06:22:26
问题 How do I set up a default syntax for files that have no extension in vim? 回答1: One way would be to add an autocommand to your .vimrc for files that don't have the syntax set: au BufNewFile,BufRead * if &syntax == '' | set syntax=html | endif Or, you could set the filetype for any file that it's not defined for: filetype plugin on au BufNewFile,BufRead * if &ft == '' | set ft=html | endif Setting filetype plugin on along with the au command gives the added benefit of loading HTML plugins if

用VIM打造属于自己的IDE

删除回忆录丶 提交于 2020-01-21 05:45:24
Vim是一个强大的文本编辑器,我参考网上教程定制了一个简单的IDE,具有文件视图、自动补全、批量注释等常用功能。先上图: 要完成整个配置,需要安装ctags、cscope软件,以及taglist.vim、winmanage、omnicppcomplete.vim、NERDcommenter.vim、a.vim、DoxygenToolKit插件。 ctags软件可以帮助我们跳转到函数或者变量的定义位置; cscope软件比ctags更强大,可以找到哪些位置调用了某个函数; taglist.vim和winmanage插件用于显示源代码的结构,比如函数列表; omnicppcomplete.vim插件可以实现C/CPP代码的补全; NERD_commenter.vim可以实现批量注释; a.vim实现.cpp和.h的快速切换,比如敲代码时想立刻查看头文件; DoxygenToolKit插件用于自动产生注释。 有了这些基本功能,Vim俨然成了一个简化版的SourceInsight。 1. 配置.vimrc .vimrc是Vim的配置文件,就在$HOME目录下面,如果没有就自己创建一个。在这个文件里可以深度定制Vim。不要太复杂,先配上最基本的,代码如下: set nocompatible "不要兼容vi syntax on "高亮 set tabstop=4 "tab等于4空格 set

[r]Seven habits of effective text editing

梦想的初衷 提交于 2020-01-21 03:39:50
Seven habits of effective text editing( via ) Bram Moolenaar November 2000 If you spend a lot of time typing plain text, writing programs or HTML, you can save much of that time by using a good editor and using it effectively. This paper will present guidelines and hints for doing your work more quickly and with fewer mistakes. The open source text editor Vim (Vi IMproved) will be used here to present the ideas about effective editing, but they apply to other editors just as well. Choosing the right editor is actually the first step towards effective editing. The discussion about which editor

Changing default position of quickfix window in Vim

雨燕双飞 提交于 2020-01-20 18:27:32
问题 Setup - MacVim with MiniBufExplorer plugin window spanning the entire top and Taglist plugin window on the right Due to the fact that I keep my Taglist on the right, whenever I open the quickfix window, its position is on the far right, below the Taglist window (with the same width as the Taglist window) Is it possible to change the default opening position logic so that the quickfix window will open below my main code window (down and left) or maybe span the entire bottom? 回答1: While it is

Why is pasting a long one-liner very slow in Vim's insert mode?

蹲街弑〆低调 提交于 2020-01-20 13:46:07
问题 My Macbook was stuck yesterday, when I tried to paste 1200 lines of 80 characters to Vim. It was much faster to download the file, and not to paste the text. I have thought that this problem might be the reason, why internet operators allow slower uploading than downloading. 回答1: If you paste it into a terminal window, Vim thinks you're typing it out by hand, and it will try and update the display as you go. You can access your clipboard (on OS X) using the pbpaste and pbcopy commands, so you