vi

Customising word separators in vi

柔情痞子 提交于 2019-11-26 19:33:17
问题 vi treats dash - and space as word separators for commands such as dw and cw . Is there a way to add underscore _ as well? I quite often want to change part of a variable name containing underscores, such as changing src_branch to dest_branch . I end up counting characters and using s (like 3sdest ), but it would be much easier to use cw (like cwdest ). 回答1: In case you're using vim, you can change that by setting the iskeyword option ( :he iskeyword ). If that is not an option, you can

Easiest way to swap occurrences of two strings in Vim?

情到浓时终转凉″ 提交于 2019-11-26 19:18:26
问题 What is the easiest way to replace all occurrences of string_a with string_b while at the same time changing anything that was already string_b into string_a ? My current method is as follows: :s/string_a/string_c/g :s/string_b/string_a/g :s/string_c/string_b/g Although this works, it requires extra typing and seems inefficient. Does anybody know of a better way to do this? 回答1: I'd do it like this: :%s/\v(foo|bar)/\={'foo':'bar','bar':'foo'}[submatch(0)]/g But that's too much typing, so I'd

How do I use vi keys in ipython under *nix?

微笑、不失礼 提交于 2019-11-26 18:52:30
问题 Currently in Bash I use set -o vi to enable vi mode in my bash prompt. How do I get this going in ipython? Note: If an answer applies to all *nix, I'll remove the OS X from the title :) 回答1: In case someone's wandering in here recently, IPython 5.0 switched from readline to prompt_toolkit, so an updated answer to this question is to pass an option: $ ipython --TerminalInteractiveShell.editing_mode=vi ... or to set it globally in the profile configuration ( ~/.ipython/profile_default/ipython

Yank entire file

▼魔方 西西 提交于 2019-11-26 18:46:11
问题 I often write something in gVim, then need to copy-paste it into another application. Is there an easy way to yank the entire file? I usually do something like this g g V G " + y (Go to top, visual-line mode, go to bottom, yank) But is there a better way that I'm missing out on? 回答1: I use the following instruction: :%y+ 回答2: ggyG (go to the first line, yank to the last line) Edit: Ah, system clipboard. Doesn't exactly roll off the fingers, but: gg"+yG 回答3: A working solution in old vi is :r

Copy and paste content from one file to another file in vi

假装没事ソ 提交于 2019-11-26 18:45:22
问题 I am working with two files, I need to copy a few lines from one file and paste into another file. I know how to copy (yy) and paste(p) in the same file. But that doesn't work for different files, how is this done?? Also, is there a way to cut-paste? I have tried googling, but most of the resources only talk about copy-paste. 回答1: Since you already know how to cut/yank text, here are a few ideas for pasting it back into another file: Edit the first file, yanking the text you want. Then open

How do I fix the indentation of an entire file in Vi?

六眼飞鱼酱① 提交于 2019-11-26 17:52:51
问题 In Vim, what is the command to correct the indentation of all the lines? Often times I'll copy and paste code into a remote terminal and have the whole thing messed up. I want to fix this in one fell swoop. 回答1: = , the indent command can take motions. So, gg to get the start of the file, = to indent, G to the end of the file, gg=G . 回答2: Before pasting into the terminal, try :set paste and then :set nopaste after you're done. This will turn off the auto-indent, line-wrap and other features

Copy all the lines to clipboard

一笑奈何 提交于 2019-11-26 17:29:18
问题 Is there any way to copy all lines from open file to clipboard in VI editor. I tried y G but it's not using clipboard to store those lines. So is it possible? 回答1: You should yank the text to the * or + registers: g g " * y G Explanation: gg to get the cursor to the first character of the file "*y to start a yank command to the register * from the first line, until... G to go the end of the file 回答2: Use: : % y + to yank all lines. Explanation: % to refer the next command to work on all the

Editing/Replacing content in multiple files in Unix AIX without opening it

耗尽温柔 提交于 2019-11-26 17:21:43
问题 I have multiple files in Unix directory. files names are as below. EnvName.Fullbkp.schema_121212_1212_Part1.expd EnvName.Fullbkp.schema_121212_1212_Part2.expd EnvName.Fullbkp.schema_121212_1212_Part3.expd In each of the above file there is a common line like below. eg EnvName.Fullbkp.schema_121212_1212_Part1.expd is having below data Log=EnvName.Fullbkp.schema_10022012_0630_Part1.log file=EnvName.Fullbkp.schema_10022012_0630_Part1.lst EnvName.Fullbkp.schema_121212_1212_Part2.expd is having

cat中文正常vi中文乱码

夙愿已清 提交于 2019-11-26 17:07:55
Linux cat中文正常vi中文乱码 问题示例 /*--> */ /*--> */ 出现此问题,有可能是vim 编辑器的配置编码方面的问题。 出现此情况,在vim 编辑器中输入 :e ++enc=utf8 :e ++enc=zh_CN 如果上面两次处理的结果中,有一个可以让乱码变为中文,那么说明打开文件时所使用的编码是不兼容中文的。 需要修改vim的配置。 vim的用户配置文件是$HOME/.vimrc , 我们在这个配置文件中加入以下内容: set fileencodings=utf-8,gbk,gb2312,gb18030 set fileencoding=utf8 set encoding=utf8 执行source ~/.vimrc 使配置生效 再次打开文件: 可以看到vi 编辑文件时已经可以正常显示中文。 Author: halberd.lee Created: 2019-08-09 Fri 16:53 Validate 来源: https://www.cnblogs.com/halberd-lee/p/11328284.html

Make Vim show ALL white spaces as a character

僤鯓⒐⒋嵵緔 提交于 2019-11-26 16:50:27
I can't find a way to make Vim show all white spaces as a character. All I found was about tabs, trailing spaces etc. Rook As others have said, you could use :set list which will, in combination with :set listchars=... display invisible characters. Now, there isn't an explicit option which you can use to show whitespace, but in listchars, you could set a character to show for everything BUT whitespace. For example, mine looks like this :set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:< so, now, after you use :set list everything that isn't explicitly shown as something else, is then,