Tag Info

Hot answers tagged

64

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


42

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.


20

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


20

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


19

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


18

You're talking about the greatest feature ever! To use vi commands to edit your shell commands (and history) add 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 commands to ...


17

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


17

Use the write command: :write Which can be abbreviated: :w If you want to write to another file without changing the current file, supply a different filename to the write command: :write newfile If you want to write to another file and change to that file, use the saveas command: :saveas newfile Which can be abbreviated: :s newfile


14

Vim was not designed for large files. It has certain features which drastically slow down the user experience. For instance, it loads the file into memory which basically limits to edit files smaller than your memory size. Furthermore, features such as syntax highlighting, swap file and undo are very inefficient with large files and slow thing down even ...


13

This behavior is editable as answered here, but stop and think about what's going on for a second. When you are in insert mode, you are not actually over a character but BETWEEN them. When you insert something, the cursor jumps to the end of what you inserted so that the next thing inserted will be after that. Now think about if you just typed a letter, then ...


13

According to the VIM FAQ you can use the :put command: 12.15. How do I insert a blank line above/below the current line without entering insert mode? You can use the ":put" ex command to insert blank lines. For example, try :put ='' :put! ='' For more information, read :help :put but then really it's easier to add: ...


13

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?


13

When you make no changes to the actual content of the file, you can simply quit with :q. However if you make edits, vim will not allow a simple quit because you may not want to abandon those changes (especially if you've been in vim for a long time editing and use :q by accident). The :q! in this case is a force the quit operation (override the warning). You ...


12

Press V to switch to VISUAL LINE mode and highlight the lines you want to indent by pressing j. Then press > to indent them. So the complete command would be Vjjj>. Alternatively, put your cursor on the <script> tag and use 4>> to indent four lines.


12

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


11

You could map a key(-sequence) to a command sequence, f.e.: :map <C-i> i_<Esc>r Ctrl-i takes one character and returns afterwards. To make it persistent, add the same line to the local or global vimrc file: ~/.vimrc /etc/vim/vimrc


11

:h user-manual | only only : Make the current window the only one on the screen. All other windows are closed. See: :h only Open from terminal: vi[m] -c 'h user-manual|only'


11

Visually, it makes more sense in gvim: When editing, your cursor is in between the characters: When in normal mode, it is on top of the last character: So it does not really go back a character, just from being between j and u to being on j


11

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


10

Part of the allure of using VI is having a command mode for manipulating the text, and an edit mode for adding text. This keeps you from having to hit CTRL-whatever to accomplish things. The other suggestions may work - I haven't tried them - but they seem to require quite a few characters or manipulating your VI environment too much. Try using o[ESC] ...


10

I tend to use ctrl+z to sleep vi, run what I need to in the shell, then fg to resume vi. Not exactly an answer to your question, but I find it a very fast way to work. If you do forget that you have vi open in the background (this can happen when you are busy), when you try to log out of the shell using ctrl+d you will be warned that you have background ...


10

I've had the most luck with this: :%!xmllint --format % It's strict about your tags, though, so it will error out if your opening and closing tags don't match. It also adds an XML declaration at the top of your file, if you don't have one as well. This page recommends the following, although I can't get it to work: :set filetype=xml :filetype indent on ...


10

You can use: :6,8s/^#// But much easier is to use Block Visual selection mode: Go to beginning of line 6, press Ctrl-v, go down to line 8 and press x. There is also "The NERD Commenter" plugin.


10

zt puts current line to top of screen z. puts current line to center of screen zb puts current line to bottom of screen More info about scrolling at http://vimdoc.sourceforge.net/htmldoc/scroll.html or in vim type :help scroll-cursor


9

You probably want to use D. Move the cursor to the first character you want to delete, then hit shift-D. Everything gone. Actually, it's in the default cut buffer, so you can P or p paste it back in. I use Dp (delete to end of line, then put it back), move to the end of some other line, then p again to paste the same text in at the end of this other ...


9

Elvis and Vim are both highly capable vi clones, so your finger memory will serve you well when switching between them. They share many vi extensions: Syntax highlighting Multiple undo and redo Visual mode, via v and V Command history and completion Tag stacks (e.g. :tags, :tn, etc.) Multiwindow editing, via :split, Ctrl-W, etc. Extended regexes: ...


9

Even though they type vi or call it vi it may still be vim. And at least vim can do all the "modern" features like auto-completion and syntax-highlighting, too. It can also mark/copy/paste text using the mouse if you wish. I however prefer vim and the console because I can do 100% of the work without ever taking one hand off the keyboard. Try that with a ...


9

You can use set -o vi to change your line editing commands as @jahroy posted, but you may be thinking of the fc command (available in bash and I think ksh, but probably not tcsh), which will put the previous command into an editor (FCEDIT or EDITOR, which you probably have set to vi) and then executes the command when you exit the editor. See the manpage or ...


9

The most general: Move cursor to first line of the group you want to write. Hit m and a sequentiall. That's "set mark named 'a'". Move cursor to last line of the group, hit 'm' and 'b'.' Change over to command mode hit: as a sequence do :'a,'b w filename then hit return. That will work in vi, nvi and vim. Another method, works in more modern vim: Put ...


9

That depends on what you define "normal". If that's turning off line editing, the documented way to unset -o vi is to set +o vi $ set -o vi $ set -o|egrep -w "(vi|emacs)" emacs off vi on $ set +o vi $ set -o|egrep -w "(vi|emacs)" emacs off vi off Chris has already answered if your normal mode is emacs.



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