Tag Info

Hot answers tagged

240

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 ...


155

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, ...


99

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$.


66

Shiftzz in command mode saves the file and exits.


55

Vim sometimes has trouble with files that have unusually long lines. It's a text editor, so it's designed for text files, with line lengths that are usually at most a few hundred characters wide. A database file may not contain many newline characters, so it could conceivably be one single 100 Mb long line. Vim will not be happy with that, and although it ...


50

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 ...


46

First of all, in vim you can enter : and then help help, ala :help for a list of self help topics, including a short tutorial. Within the list of topics move your cursor over the topic of interest and then press ctrl-] and that topic will be opened. A good place for you to start would be the topic |usr_07.txt| Editing more than one file Ok, on to your ...


45

You, glen, are the owner of the directory (see the . file in your listing). A directory is just a list of files and you have the permission to alter this list (e.g. add files, remove files, change ownerships to make it yours again, etc.). You may not be able to alter the contents of the file directly, but you can read and unlink (remove) the file as a whole ...


45

In my experience Vim chokes not on large files, but on long lines. Use this command to have mysqldump use shorter lines at the expense of a larger file: $ mysqldump --complete-insert -u -p Additionally, you can open Vim and ask it not to parse your .vimrc file or load any plugins with this command: $ vim -u NONE output.sql Loading Vim in this manner ...


32

If the cursor is already on line 12, then a simple :4y P does it for me.


30

do (diff obtain) and dp (diff put) is what you need. Here is a small list of other helpful commands in this context. ]c - advance to the next block with differences [c - reverse search for the previous block with differences do (diff obtain) - bring changes from the other file to the current file dp (diff put) - send changes ...


30

In addition to uprego's answer, you can press Ctrl+G (in normal mode) to get the current buffer's name as well as the total number of lines in it and your current position within it. Update As per rxdazn's comment, you can press 1 before Ctrl+G to get the full file path. If you press 2, you get the full file path and the buffer number you currently have ...


29

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


27

The following will work only if vim --version indicates that you have +xterm_clipboard feature. If not, you will have to install extra packages or recompile vim with that feature added. There are actually two options for this: "+y copies to the "usual" clipboard buffer (so you can paste using Ctrl+V, right click and select "Paste" etc), while "*y ...


27

This feature is called Software Flow Control (XON/XOFF flow control) When one end of the data link (in this case the terminal emulator) can't receive any more data (because the buffer is full or nearing full or the user sends C-s) it will send an "XOFF" to tell the sending end of the data link to pause until the "XON" signal is received. What is ...


26

sudo cannot change the effective user of an existing process, it always creates a new process that has the elevated privileges and the original shell is unaffected. This is a fundamental of UNIX design. I most often just save the file to /tmp as a workaround. If you really want to save it directly you might try using a feature of Vim where it can pipe a file ...


26

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#


24

You can use SSHFS to mount a remote home in a local folder. Has the advantage of using the current infrastructure and low latency of local vim.


23

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. ...


23

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 ...


22

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 ...


22

Here's an actual fix. Add the following to .tmux.conf: set -s escape-time 0


21

Cygwin vim ships with vim's default configuration, which leaves vim in vi compatibility mode where it tries to emulate the original vi as closely as possible. Among other limitations, arrow keys do not work in that mode, and backspace just moves the cursor left rather than erasing a character. Creating an empty ~/.vimrc is sufficient to disable vi ...


21

d is delete and G moves to the end of the file, so dG will delete to the end of the file. It includes the entire current line though; if you're mid-line and want to preserve everything before the current position you need to use Mark's method


21

When Vim reads an existing file, it tries to detect the file encoding. When writing out the file, Vim uses the file encoding that it detected (except when you tell it differently). So a file detected as UTF-8 is written as UTF-8, a file detected as Latin-1 is written as Latin-1, and so on. By default, the detection process is crude. Every file that you open ...


21

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 ...


21

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 ...


21

The ^M is a carriage-return character. If you see this, you're probably looking at a file that originated in the DOS/Windows world, where an end-of-line is marked by a carriage return/newline pair, whereas in the Unix world, end-of-line is marked by a single newline. Read this article for more detail, and also the Wikipedia entry for newline. This article ...


21

Enter paste mode before you paste: :set paste To switch back to "normal" mode: :set nopaste


20

It has insert and normal mode (the insert mode is default, and escape for normal mode) but no visual mode. In bash: set -o vi You can run it at the command line for just this session or add it to your .bashrc file. Many programs use readline for input, and you can make any of them use vi-style keybindings by setting up your .inputrc with set editing-mode ...



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