Skip to content
Advertisement

Tag: vi

How to make vi/vim execute “rewrite filter on write” for given file extension?

I would like to be able to write handy “short version” in configuration file. The obvious way to achieve it would be “on save filter” executed by vi/vim. The filter script would rewrite “short version” to “long version” expected by the app. Answer Assuming code is an ex command that does your filtering (which could be calling a vimscript function,

Why can’t I sudo echo a line in /etc/?

I am on centos and I did sudo echo ‘testline’>>/etc/test/test it said -bash: /etc/test/test: Permission denied However, when I do sudo vi /etc/test/test and insert testline and do :wq it writes out fine, why is this happening? Answer You need to wrap the whole statement (including the redirect) into a group so the sudo extends around it. Note: that, too,

How to add a string to line 13 in my text file

I have a very large text file that is difficult to open in text editors. Lines 12 – 15 are: I would like to add: 3 196 to line 14 and then have a blank line between 3 196 and Atoms like it is currently. I tried: But it did not seem to change anything. Anyone know of how I

vi command to copy certain lines to another file

I have a log file with thousands of lines. I want to copy certain logs ranging between two line numbers to another file so that I can share them within team. For example – I want to copy text from line number 1000 to line 1200 to another file say issueLog.log What is the shortest way to do this? Note:

find and replace a String in vi editor on linux?

i am trying to replace String with new String in Linux vi editor but getting following error. Answer I’d guess the reason you’re getting that error message is because you intend to replace the string on all lines, not just the current one. In order to search all lines, add a % to your command:

How to substitute text which has implicit meaning in vi

I have a C code in vi from which I want to replace the text “n” with something else. Use of %s:n:(anything else) isn’t working. Is there any way to bypass this? For example,a line in the code is: printf(“Hello worldn”); In vi, I need to replace “n” in the printf line with a full stop. Use of substitue command

Advertisement