vi

How do I join two lines in vi?

我的未来我决定 提交于 2019-11-26 23:50:53
问题 I have two lines in a text file like below: S<Switch_ID>_F<File type> _ID<ID number>_T<date+time>_O<Original File name>.DAT I want to append the two lines in vi like below: S<Switch_ID>_F<File type>_ID<ID number>_T<date+time>_O<Original File name>.DAT The second line got deleted and the contents of the second line was appended to the first line. How could I do it using command mode in vi? 回答1: Shift + J removes the line change character from the current line, so by pressing "J" at any place

开发中遇到的问题 ---【Linux vi编辑后无法保存出现E212:Can't open file for writing】

你离开我真会死。 提交于 2019-11-26 23:46:07
原因分析:一般都是因为一次创建了文件夹同时创建了文件导致,vi /etc/docker/demo.json 解决方案: 手动 先进入etc目录下:cd /etc/ 手动创建文件夹docker:mkdir docker/ 进入docker:cd docker/ 创建demo.json文件并进入编辑:vi demo.json 按i进入编辑模式 编辑完后,按ESC退出编辑模式,然后保存并退出: :wq 此时就可以了。 来源: https://www.cnblogs.com/hujunwei/p/11335565.html

Any way to delete in vim without overwriting your last yank? [duplicate]

浪子不回头ぞ 提交于 2019-11-26 23:45:25
问题 This question already has an answer here: In Vim is there a way to delete without putting text in the register? 22 answers I love vim, but one common gotcha is: yank a line go to where you would like to paste it delete what's there paste your yank, only to discover that it pastes what you just deleted Obviously the workflow is delete first, yank second. But it would be reeeeeaaaaaalllly nice if I didn't have to. Anyone have a trick for this? Does vim have a paste buffer that works well, or is

Find and replace strings in vim on multiple lines

萝らか妹 提交于 2019-11-26 23:45:06
问题 I can do :%s/<search_string>/<replace_string>/g for replacing a string across a file, or :s/<search_string>/<replace_string>/ to replace in current line. How can I select and replace words from selective lines in vim? Example: replace text from lines 6-10 , 14-18 but not from 11-13 . 回答1: The :&& command repeats the last substitution with the same flags. You can supply the additional range(s) to it (and concatenate as many as you like): :6,10s/<search_string>/<replace_string>/g | 14,18&& If

Replace tabs with spaces in vim

孤街浪徒 提交于 2019-11-26 23:44:30
问题 I would like to convert tab to spaces in gVim. I added the following line to my _vimrc : set tabstop=2 It works to stop at two spaces but it still looks like one tab key is inserted (I tried to use the h key to count spaces afterwards). I'm not sure what should I do to make gVim convert tabs to spaces? 回答1: IIRC, something like: set tabstop=2 shiftwidth=2 expandtab should do the trick. If you already have tabs, then follow it up with a nice global RE to replace them with double spaces. 回答2:

What are the dark corners of Vim your mom never told you about? [closed]

荒凉一梦 提交于 2019-11-26 22:19:00
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . There are a plethora of questions where people talk about common tricks, notably "Vim+ctags tips and tricks". However, I don't refer

Removing BOM characters using Java [duplicate]

你离开我真会死。 提交于 2019-11-26 22:00:19
问题 This question already has an answer here: Byte order mark screws up file reading in Java 8 answers What needs to happen to a string using Java to be an equivalent of vi s :set nobomb Assume that BOM comes from the file I am reading. 回答1: Java does not handle BOM properly. In fact Java handles a BOM like every other char. Found this: http://www.rgagnon.com/javadetails/java-handle-utf8-file-with-bom.html public static final String UTF8_BOM = "\uFEFF"; private static String removeUTF8BOM(String

How to paste over without overwriting register

折月煮酒 提交于 2019-11-26 21:33:59
Does anyone know of a way to paste over a visually selected area without having the selection placed in the default register? I know I can solve the problem by always pasting from an explicit register. But it's a pain in the neck to type " x p instead of just p Luc Hermitte "{register}p won't work as you describe. It will replace the selection with the content of the register. You will have instead to do something like: " I haven't found how to hide this function (yet) function! RestoreRegister() let @" = s:restore_reg return '' endfunction function! s:Repl() let s:restore_reg = @" return "p@

How do I use vim registers?

。_饼干妹妹 提交于 2019-11-26 21:11:57
I only know of one instance using registers is via Ctrl R * whereby I paste text from a clipboard. What are other uses of registers? How to use them? Everything you know about VI registers (let's focus on vi 7.2) -- share with us. FModa3 Registers in Vim let you run actions or commands on text stored within them. To access a register, you type "a before a command, where a is the name of a register. If you want to copy the current line into register k , you can type "kyy Or you can append to a register by using a capital letter "Kyy You can then move through the document and paste it elsewhere

Tab key == 4 spaces and auto-indent after curly braces in Vim

吃可爱长大的小学妹 提交于 2019-11-26 21:11:54
How do I make vi - Vim never use tabs (converting spaces to tabs, bad!), makes the tab key == 4 spaces, and automatically indent code after curly brace blocks like Emacs does? Also, how do I save these settings so I never have to input them again? I've seen other questions related to this, but it always seems to be a little off from what I want. Ken As has been pointed out in a couple of answers below, the preferred method now is NOT to use smartindent, but instead use the following (in your .vimrc ): filetype plugin indent on " show existing tab with 4 spaces width set tabstop=4 " when