Hot answers tagged


I use both, although if I had to choose one, I know which one I would pick. Still, I'll try to make an objective comparison on a few issues. Available everywhere? If you're a professional system administrator who works with Unix systems, or a power user on embedded devices (routers, smartphones with Busybox, …), you need to know vi (not Vim), because it's ...


I'll post what I think are the main benefits of each: Emacs has considerably more extensions to let you do tasks that are only vaguely text-editor related, like browsing the filesystem or messing with version control, and extensions that are in no way text-editor related, like reading RSS feeds. If you want an environment instead of just a text editor, ...


The command dw will delete from the current cursor position to the beginning of the next word character. The command d$ will delete from the current cursor position to the end of the current line. D is a synonym for d$.


In vi do :1,$d to delete all lines. The : introduces a command (and moves the cursor to the bottom). The 1,$ is an indication of which lines the following command (d) should work on. In this case the range from line one to the last line (indicated by $, so you don't need to know the number of lines in the document). The final d stands for delete the ...


In vi I use :%d where : tells vi to go in command mode % means all the line d : delete On the command line, > test.txt will do also. What is the problem with dd? dd if=/dev/null of=test.txt where /dev/null is a special 0 byte file if is input file of is ouput file


There is a vi available on every unix system (or almost), however you can't say this about any other editor. This is the #1 reason, imo, to learn and familiarize yourself with vi (please note 'vi' not 'vim'). I've never seen Emacs be available in a default install. I'm not saying don't use Emacs or this is the only reason to use Vim, but when you want to be ...


You should add it to your shell’s configuration file. For Bash, this is ~/.bashrc or ~/.bash_profile. You should also set $VISUAL, as some programs (correctly) use that instead of $EDITOR (see VISUAL vs. EDITOR). Additionally, unless you know why, you should set it to vim instead of vi. TL;DR, add the following to your shell configuration (probably ...


Running vi or vim with '-' as an argument makes it read the file to edit from standard input. Hence: grep -e Peugeot -e PeuGeot carlist.txt | vi - will do what you need.


POSIX requires this behavior, so it's not in any way unusual. From the POSIX vi manual: INPUT FILES See the INPUT FILES section of the ex command for a description of the input files supported by the vi command. Following the trail to the POSIX ex manual: INPUT FILES Input files shall be text files or files that would be text files ...


Pressing dd will remove that line (actually it will cut it). So you can paste it via p.


In the page Top Ten One-Liners from CommandLineFu Explained is suggested this trick (the #3): :w !sudo tee % this write the current buffer to the stdin of the command after the !. The % symbol is substituted with the current filename.


Visual Block Mode First, move the cursor to the first char of the first line in block code you want to comment, then type: CTRL + V then vim will go in to VISUAL BLOCK mode. Use j to move the cursor down until you reach the last line of your code block. Then type: Shift + I now vim go to INSERT mode and the cursor is at the first char of the firts ...


In normal mode, do 100dd. dd deletes the current line. Prefacing that command with 100 causes it to repeat 100 times.


I'd recommend that you just do this (should work in any POSIX-compliant shell): > test.txt If you really want to do it with vi, you can do: 1G (go to first line) dG (delete to last line)


Yes, e.g if you want to do ls, try: :!ls To spawn a shell, use :shell


vi is (also) a standard. There are plenty of implementations and vim is likely the most popular at least on Linux. While many traditional Unix compliant OSes provide vi implementations very close to the standard, vim has added a lot of extra features that make it a double-edged sword. Of course, these extensions are usually designed to ease the editing ...


By setting your readline editing to either emacs (the default) or vi (set -o vi) you are essentially standardizing your editing commands, across the shell and your editor of choice1. Thus, if you want to edit a command in the shell you use the same commands2 that you would if you were in your text editor. This means only having to remember one command ...


Ranges: You can do it with the following command: :66,70s/^/# for comment, and for uncomment: :66,70s/^#/ obviously, here we're commenting lines from 66 to 70 (inclusive). Hope this helps. Regards.


In insert mode, the cursor is between characters, or before the first or after the last character. In normal mode, the cursor is over a character (newlines are not characters for this purpose). This is somewhat unusual: most editors always put the cursor between characters, and have most commands act on the character after (not, strictly speaking, under) the ...


Vim tries to resemble the syntax and semantic of Vi command as much as possible. But being an "improved version", Vim adds new commands and features. It also changes the semantic of some Vi commands to better match the current expectations of its programmers. A detailed list of changes between vim and Vi can be found using the command :help compatible in ...


You're talking about the greatest feature ever! You can use vi commands to edit shell commands (and command history) by adding this to your .bashrc file: set -o vi You can also run that command from the command line to affect only your current session. If you don't use bash, substitue the appropriate rc file for your shell. This allows you to use vi ...


From man less, v Invokes an editor to edit the current file being viewed. The editor is taken from the environment variable VISUAL if defined, or EDITOR if VISUAL is not defined, or defaults to "vi" if nei‐ ther VISUAL nor EDITOR is defined. See also the discussion of LESSEDIT under the section on PROMPTS below. ...


You can use another character instead of slash / as delimiter to substitution command. Example using #: :%s#/a/b/f/g/d/g#/s/g/w/d/g/r#


No vi doesn't have any significant advantage over vim rather its the other way around. Vim has more advantages then Vi. You may be interested in : Why, oh WHY, do those #?@! nutheads use vi? Edit also read : Is learning VIM worth the effort?


I think they're both awesome. I think either one can do just about anything you can imagine, and they're both so customizable, that by the time you finish customizing them, they're both just exactly what you want them to be, nothing more nor less. Emacs stands out to me in being a bit closer (although still does not meet) to ISO/IEC standards of usability ...


This is the expected vi behavior. Your file has an incomplete last line so strictly speaking (i.e. according to the POSIX standard), it is not a text file but a binary file. vi which is a text file editor, not a binary one, gracefully fixes it when you save it. This allows other text file tools like wc, sed and the likes to provide the expected output. ...


Do this: rm -f ~/.viminfo The .viminfo file keeps metadata about various useful, but non-critical state information. Yours is corrupt. Remove it.


You could also set your default text editor by using the following command. sudo update-alternatives --config editor


delete 100 lines forward from (including) the current one repeat dd (delete current line) 100 times: 100dd delete from current line to 99 lines forward d99j delete 100 lines backwards from (including) the current one d99k delete lines in a specific range by line number :1,100d delete lines in a range beginning with the current line :.,.+99d ...


zt puts current line to top of screen z. or zz puts current line to center of screen zb puts current line to bottom of screen More info about scrolling at or in vim type :help scroll-cursor

Only top voted, non community-wiki answers of a minimum length are eligible