vi is a screen-oriented text editor originally created for the Unix operating system.

learn more… | top users | synonyms

1
vote
4answers
8k views

What is a vi equivalent of vim's 'set ruler' command?

Is there a way to show the current row and column position in vi? In vim, I know there is the set ruler command, but what are my options when using vi?
6
votes
3answers
4k views

Globally replace Vi with Vim on Fedora

On Debian-based systems the alternatives system handles both the vi and vim executable. So if vim is installed and you execute vi, you also get vim, which I find very nice, because I absolutely hate ...
11
votes
2answers
462 views

Vi editor: What's the fastest way to delete multiple rows in a file?

I'd like to use the Vi editor to delete multiple rows in a file. Please give me idea or suggestion. My goal is like this: Before: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 . . 29 30 . . ...
108
votes
9answers
126k views

How can I delete all lines in a file using vi?

How can I delete all lines in a file using vi? At moment I do that using something like this to remove all lines in a file: echo > test.txt How can I delete all lines using vi? Note: Using dd ...
2
votes
4answers
344 views

Move in crontab -e editor

I'm trying to manipulate the editor of crontab but it's really really confusing. So I launch the creation of a new crontab with crontab -e Then the default editor opens. Now from there, it's seems to ...
1
vote
2answers
42 views

Which user does vi run commands as?

This maybe a weird question but please listen carefully Let's say I have a file as -rwxr-w--- user3 user2 4095 somefile Right now I'm in a user2's shell(? is this right to say) and if I execute ...
-1
votes
2answers
55 views

Vim: set “cursor keys” hjkl to wasd [closed]

I admit that I'm not an expert vim user so forgive me not providing previous attempts! I wish to overwrite/remap the basic vi/vim (and gvim) "cursor keys" hjkl to the ordinary "gamer layout" wasd (w-...
7
votes
2answers
2k views

How to edit a .gpg file with vi?

So I created a gpg encrypted file with password: gpg -c passwords.txt.gpg how can I open it with vi, edit it, then close it? (So that no passwords.txt file will be created, the decrypted passwords....
0
votes
1answer
30 views

On OSX, vi seems to return 1 unexpectedly despite no error

So, on stock Mac OSX Yosemite, if I run vi /tmp/foo and then type in some text, and finally do :Wq (a common typo I make) and then :wq. Everything will appear to be fine, but for some reason the exit ...
0
votes
4answers
70 views

How to add hostname as first line of a file

I have a file which has a few lines. one two three four five I need to add hostname of the server I'm working on as the first line of the file. For example if abcd555.india.com is the server, the ...
17
votes
6answers
54k views

Delete 100 lines from vi editor using single command

I am using Ubuntu and trying to delete all 100 lines from vi editor but I got interview question of doing this in one command.
0
votes
1answer
35 views

How do I delete the repeating word in vi editor?

I want to delete certain word in multiple locations ( say I want to delete the word " involve" form Vi editor and it appear 10000 times) from a vi editor?
131
votes
4answers
118k views

Delete from cursor to end of line on VI

I know I've probably looked over this a million times in all the VI documents I've read, but I can't seem to find the delete from cursor to end of line command.
53
votes
8answers
70k views

Vi vs vim, or, is there any reason why I would ever want to use vi?

I know a bit about *NIX text editors (currently migrating from nano to vim), and, after looking around a bit on the Unix & Linux SE, have noticed that vi is used instead of 'vim' in a fair number ...
0
votes
1answer
48 views

Vi help problem with / in command mode

Hope someone can guide me in the right direction. I have an issue with the vi text editor, when in command mode after I enter ":" and want to use "/", the forward slash does not come up. What I get is ...
0
votes
2answers
54 views

How to fetch all the even lines and odd lines from a file and save them into two different files such as Evenfile & Oddfile? [duplicate]

The question is very simple. Suppose I've a file named "a.txt" and it has 100 lines. Now I want to extract odd lines i.e lines 1,3,5...etc and save them to a different file such as Odd.txt and the ...
53
votes
10answers
4k views

Use of touch and vi?

Is there a benefit of creating a file with touch prior to edit.. like: touch foo vi foo versus getting it to editor straight-away? Like: vi foo I see quite a few tutorials using the former (...
1
vote
1answer
142 views

Why does ci" (change inside quotes) not work in bash with vi mode enabled?

My favourite way to use bash is with readline's vi mode, enabled with set -o vi. It works perfectly for me, except that ci" does nothing. The change inside X feature does not work. What can I do to ...
42
votes
3answers
43k views

How can I set “vi” as my default editor in UNIX?

I believe I can do something like export EDITOR=vi, but I'm not sure what exactly to enter, and where. How can I set "vi" as my default editor?
1
vote
2answers
2k views

Where is the rc file for vi editor.

I would like to set up system-wide vi settings. I know i can setup preferences for vim editor in /etc/vimrc and ~/.vimrc but i don't think my vi on CentOS7 is reading anything from the vimrc files ...
1
vote
3answers
43 views

how to make a large command line broke in two lines be executed as a single line inside of a script

I am very begginer with Unix. I am using IBM z/OS390 and I am using the OMVS shell. I don't have "vi" installed at all so I use "oedit". If I try to initialize the app.jar straigh from OMVS shell it ...
4
votes
3answers
941 views

While in vi how can I pull in / insert / paste the contents of another file

I am editing file 'A' in vi. I have another file 'B' whose contents I want to 'paste' into my current location. Other than actual mouse copy and pasting, is there a command that I can use that will ...
0
votes
1answer
28 views

How to delete part of a file and save it in another - using vi

Say you have a file call stuff.txt and you're editing it in vi. cat stuff.txt 11233 blah doesn't matter what <---------------------pretend your cursor is here xxcvbbb dfdfdd How can you ...
10
votes
3answers
525 views

How do I modify the ci command in vim

Just like "ci(" changes everything between parentheses, I want "ci$" to change everything between dollar signs (for editing LaTeX.) Is this possible?
13
votes
2answers
474 views

What is “<Esc>Kv” in bash

When I am in bash and press Esc, Shift+K, V, bash fires up $EDITOR with a filename similar to /tmp/bash-fc-186566385. Why is that and what is its purpose? I probably need to mention that I am ...
0
votes
1answer
72 views

Faster way to enter in command mode with vi mode in the shell

I want to use the vi mode in bash but I find the ESC key a little bit too far, as for vim. The ideal can be to keep a key pressed, like ALT or the caps lock, to stay in command mode and be in insert ...
-2
votes
1answer
37 views

How to replace all dots in vi

How to replace in vi? There are numerous explanations in Internet, but most of them doesn't contain information about which buttons to press. If I enter :s/[.]/[.] <ENTER> then only one ...
3
votes
2answers
30 views

How to replace a line with a certain pattern in vi?

I am trying to replace lines that contain the pattern "s#_decoded_block[" with "s#_decoded_block_". The command I am using to do that is %s/s\d\+_decoded_block\[/s\d\+_decoded_block_/g I expect to ...
0
votes
1answer
24 views

Less quit behavior

I'm not sure how to describe this but I'll try by comparing it to vi. When I open vi, do something, and then exit vi it brings me back to the terminal where I can see all of the commands I had ...
3
votes
2answers
712 views

In vi/vim, how do I append to a file instead of overwriting it?

I know I can write to a file by simply doing :w <file>. I would like to know though how can I write to a file by appending to it instead of overwriting it. Example use case: I want to take some ...
1
vote
1answer
54 views

Two different versions of VIM

When I install just about any distribution of linux it's accompanied with an unorthodox version of vi. I most recently dealt with this on Ubuntu 14.04. I can vi a file but a number of the "hot" keys ...
13
votes
1answer
18k views

Replace using VIM, reuse part of the search pattern

I am working with VIm and trying to set up a search and replace command to do some replacements where I can re-use the regular expression that is part of my search string. A simple example would be a ...
0
votes
1answer
102 views

How can I get rid of the byte-order mark 

I have created an html webpage when I run it at the bottom of the page there's some unwanted characters uncoding . I tried to get rid of it through vi using set nobomb but it still appears in the ...
1
vote
4answers
64 views

Command line in vi mode: replace all

How do I replace globally from the command line in vi mode. It seems like I can't use ex commands by prefixing with :, so what do I do instead. for instance if I want to replace all \ with / in a ...
0
votes
1answer
36 views

vi is frozen after search on arch linux

I'm on Arch Linux live USB. I'm using vi to open an 18kb text file containing a single line of json. I did a search with / and hit a block partway through the file represented by an @ symbol. Then, ...
0
votes
2answers
175 views

Linux server terminal - rows of tildes, can't write commands?

I'm pretty new - came across this problem. My webserver terminal is looking weird, there are some code echoes and then rows and rows of tilde. Where I type would be at the green square, but nothing I ...
18
votes
3answers
9k views

How to automatically strip trailing spaces on save in Vi and Vim?

Is there a .vimrc setting to automatically remove trailing whitespace when saving a file? Ideally (to be safe) I would like to only have this functionality for certain files, e.g. *.rb
11
votes
3answers
3k views

Pasting from clipboard to vi-enabled zsh or bash shell

I'd like to be able to paste from the system clipboard (or text selection) into my "vi-like" shell prompt using the keyboard. I normally use zsh and sometimes bash. In both cases, I have the shell set ...
27
votes
4answers
2k views

Does vi silently add a newline (LF) at the end of file?

I have trouble understanding a weird behavior: vi seems to add a newline (ASCII: LF, as it is a Unix (AIX) system) at the end of the file, when I did NOT specifically type it. I edit the file as such ...
3
votes
2answers
1k views

How to cancel :X encryption in vi

This has annoyed me for years but I've never found a solution. Instead of pressing Esc then :x to save an exit from vi, I accidentally type a capital X and press Enter. The only way to continue is to ...
2
votes
1answer
1k views

Use of ! in VIM

I have seen that sometimes :q works but sometimes we have to use :q!. This is the case for many commands. I was wondering what is the general use of ! in vim and when to use it. I tried to google this,...
2
votes
4answers
129 views

How to move to the “Nth” offset in a file

I'm in need of a command that would help me to the the N th offset in a file. Say this is my file's contents: [root@localhost ~]# cat /file1.txt this is the the first line of many lines and is just a ...
0
votes
4answers
267 views

grep all the lines in a file and write line to a file from the pattern matching point

For example, a temp.txt file contains information like below: adsf on line jhkjhvjdbvjvbvbdjkvn qerwtt on line fdgdgdgdd qwqertg on line safffasffaf wrt on line adaddsd I want to grep for ...
3
votes
2answers
207 views

How to write contents of a file to new file removing repeated lines [duplicate]

For example, a file file1.txt contains Hi how are you hello today is monday hello I am fine Hi how are you After the processing of file1.txt it should write to file2.txt and contents ...
3
votes
1answer
112 views

EX editor: go to previous file

Using ex I open 3 files ex file1 file2 file3 I know the command :n goes to file 2 and file3 the command :rew go to file1 from file3 or file2 But what command can I use to go to previous file? I ...
0
votes
3answers
97 views

strange vi behavior on OSX Debian ssh terminal

While creating a swapfile I issue vi /etc/fstab as root. fstab file comes up, great. Issue G $ to jump to end of line and i to enter INSERT mode. Press the right arrow to move the cursor over by one ...
16
votes
1answer
2k views

How to put current line at top/center/bottom of screen in vim?

Any quicker navigation trick to place the line at which the cursor is at the moment to the top of the screen? center of the screen? bottom of the screen?
3
votes
1answer
60 views

Vim - Is there a way to get immediate visual feedback during Insert in Visual Block Mode?

I often press: <Ctrl> V to go into visual block mode and highlight a column hit <shift>-i (to insert at the beginning of the line), type a few things (at this point, I see my changes on ...
1
vote
3answers
207 views

How to match two lines at once in vim

I have a file that contains records with tab separated format but in two lines, I want to arrange records in one line with tab separated values using vim editor pattern match. Ex. Abc PQR ...
3
votes
2answers
28 views

vi — replace chars from part of line

I've got a file with all Belgian cities. Some of these cities have boroughs. Lier;stad;Antwerpen;49,70;33930;Lier;Koningshooikt Knokke-Heist;gem.;WestVlaanderen;56,44;33825;Knokke;Westkapelle;Heist;...