Tag Info

Hot answers tagged

41

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


16

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


16

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


16

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


15

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


12

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


12

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?


11

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.


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

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


10

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


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


9

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


9

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


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

Type the following :r filename_to_paste This will paste the contents of the file after the line on which the cursor is present. If you need to copy/paste smaller range of lines/block of text from one file to other, you can also do the following assuming one file is opened in vim already Open 2nd file using :sp (split) or :vsp(vertical split) do a ...


9

Rather than yanking into the a register yank into the * or + register to yank the file contents into the X clipboard using one of: :%y* :%y+ This does require that you're using a copy of vim that has X support compiled in and is able to connect to your X server. Which of those works better for you will depend on which type of clipboard the target ...


8

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 between i and m to being on i


8

If you're using bash, as jahroy and evil otto have already answered, you can use set -o vi to cause bash to use vi-style editing commands. Once you've done this, you can type Esc v to launch the vi editor with a temporary file containing a copy of the current command line. You can edit the command, even replacing it with multiple lines; when you save the ...


8

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


8

Since you mentioned "get the stdout", note that you can do :r! command and the output of the command will be added to the file, or :<range>!command to have the content of the range filtered through the command [e.g. :1,$!wc]


8

I would have a hard time living without vim but I can't stand vi. However, learning the former will at least leave you with an idea of how to deal with the later when that's all that is available. The vim interface by default is actually pretty close to vi. If I'm working on a system with vim the first thing I do is add this stuff to ~/.vimrc: syntax ...


8

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


7

I don't know about vi, so that might not be useful, but in VIM you can do something like that: donald /mount/donald_01 mickey /mount/mickey_01 mickeym /mount/mickey_02 %s%\(..\)$%\1/\1% will give you the following output: donald /mount/donald_01/01 mickey /mount/mickey_01/01 mickeym /mount/mickey_02/02 The syntax is very close to that of sed. You might ...


7

You can use this mode in any program that uses the readline library by adding set editing-mode vi to ~/.inputrc. You can also use rlwrap to make other programs use readline.


7

Looks like Kevin has a pretty good answer, but if you want to lay eyes on each line you delete, then replace, a slightly different solution exists. 1. Find line to copy in some select number of places. 2. Put cursor on it. 3. "ayy copies that line into register 'a'. 4. Find line to replace. Put cursor on it. 5. dd deletes that line. "aP inserts the copied ...


7

Each line of the file contains the string ^M 1 twice. That is, <carriage-return><tab>1 ^M^I1 \r\t1 (Those are three different representations of the same control characters) When this is sent directly to your terminal, as cat will do, the terminal interprets this as an instruction to move back to the beginning of the line, move over 8 ...


7

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