Questions tagged [vi]

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

412 questions
384
votes
12 answers

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 is not a good option. There can be many lines.
Cold
  • 4,153
85
votes
1 answer

vi - How go to line N?

In vi editor how do I go to a particular line? For example if I open a file named file.py is there an option for open the file at a particular line, or can I open my file and then go to line with keyboard shortcut?
11
votes
6 answers

backspace in insert mode not erasing characters

I am new to vi, actually I have started learning vi from today and I have got stuck at the behavior of the backspace key. Actually when I fired up vi on my Ubuntu 12.04 for the first time my backspace key was working normally but after that it has…
8
votes
2 answers

vim: delete lines before cursor

We can delete lines after the cursor (e.g.: the next 3 lines) with: 3dd But how can we delete the lines before the cursor? (e.g.: 3 lines before cursor)?
LanceBaynes
  • 40,135
  • 97
  • 255
  • 351
8
votes
2 answers

Unable to write to file on FreeBSD -- read-only filesystem

I bought a load balancer that runs the application on of FreeBSD. I found the configuration file that has all the settings and login information for both the admin and read-only users. I logged in as the root user, but when I try to alter any files…
user160246
7
votes
2 answers

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 allow encryption. Surely there's a cancel command…
user5817
  • 181
6
votes
2 answers

Searching for a specific string at beginnning and end of the line in Vi

What command is used to search for a specific string at the beginning of line and at the end of the line in vi editor?
6
votes
2 answers

In VI how do I paste text into my file from a range of lines I have yanked?

I am using vi in Solaris 10. I am yanking a range of lines by doing 283,295y, and I do believe the yank command is working as it says 12 lines after I execute the command. However when I try to copy the lines into the file p or P commands don't…
DemiSheep
  • 953
5
votes
2 answers

vi: how to use a line as a command?

cat a.txt echo hi echo hu echo ha Q: how can I execute ex.: the second line in a.txt when it is opened with vi? so "vi a.txt" -> then SOMEMAGICCOMMAND -> then the "echo hu" is executed as a command. How?
gasko peter
  • 5,514
5
votes
3 answers

How to replace words in more than one line in the vi editor?

For example in the vi editor a file is created with 8 lines of the word today and I was wondering how I would change 4 lines to the word yesterday with once command.
5
votes
2 answers

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 or locations such as /etc/virc or ~/.virc
vincentleest
  • 163
  • 1
  • 1
  • 7
3
votes
1 answer

vi - how to add specific characters at the end of line

I would like to know if is possible in vi to add at the end of a line some specific character of ther line itself. Example: Before donald /mount/donald_01 mickey /mount/mickey_01 mickeym /mount/mickey_02 After some :%s%"last two…
gogolb
  • 97
3
votes
2 answers

Pressing $ then Enter adds a newline before the last character, not after

I'm trying to add another line at the end of the last line in the VI editor and I need to go to the very last of the last line (command $) to insert a new line by hitting the enter key. But the cursor stays on the last character: if I have to hit…
Zeus
  • 242
2
votes
1 answer

set hlsearch not working in vi

I want the result to be highlighted when I search for it in a file.So,I opened a file with vi(version 7.2) and then used command :set hlsearch to enable highlighting.But even then I don't get my search results highlighted.Any idea what else to check…
g4ur4v
  • 1,764
  • 8
  • 29
  • 34
2
votes
2 answers

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 get "s#_decoded_block_" as substitutions but…
1
2 3