Tag Info

Hot answers tagged

294

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


188

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


144

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


71

Shiftzz in command mode saves the file and exits.


60

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


59

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


55

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


55

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


55

You can use the :edit command, without specifying a file name, to reload the current file. If you have made modifications to the file, you can use :edit! to force the reload of the current file (you will lose your modifications).


54

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


51

Although you restrict the commandline arguments there is nothing that prevents the user from using vim to open, edit and overwrite any random file once it is running as root. The user can run sudo vim /etc/httpd/conf/httpd.conf and then clear all that text from the edit buffer then for convenience source an existing file (although that is not even ...


49

There're two reasons: Auto insert comment Auto indenting For pasting in vim while auto-indent is enabled, you must change to paste mode by typing: :set paste Then you can change to insert mode and paste your code. After pasting is done, type: :set nopaste to turn off paste mode. Since this is a common and frequent action, vim offers toggling paste ...


48

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


46

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


38

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


37

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


35

There are many color schemes which are usually distributed together with vim. You can select them with the :color command. You can see the available color schemes in vim's colors folder, for example in my case: $ ls /usr/share/vim/vimNN/colors/ # where vimNN is vim version, e.g. vim74 blue.vim darkblue.vim default.vim delek.vim desert.vim elflord.vim ...


34

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


33

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


32

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


31

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


30

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


30

You can do that via scp like this: vim scp://user@myserver[:port]//path/to/file.txt Notice the two slashes // between server and path, which is needed to correctly resolve the absolute path. [:port]is optional. This is handled by vim's netrw.vim standard plugin. Several other protocols are supported.


29

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


28

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


28

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


27

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


27

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


27

In addition to manually refreshing the file with :edit, you can put into your ~/.vimrc :set autoread to make Vim automatically refresh any unchanged files. Also see :checktime.


26

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



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