Tag Info

Hot answers tagged

31

From SO: :w !sudo tee % I actually find myself using this way to do it more frequently now: :%!sudo tee % I think it's a little more intuitive, as I know what :%! does, whereas I don't have a visceral understanding of :w !. Also, it's easy to miss the very important space between the w and the !.


30

gvim is a GUI version of vim (vi improved). There is also vim available for the Windows command line.


24

The simplest and fastest way is to use: : % y + and then go over to Google Docs (or wherever) and paste. Another way is g g " + y G but you will likely admitt that the above is faster and easier.


23

First, make sure you have the proper Vim packages installed. The default on many systems is to install a minimal Vim package that is closer to Vi in functionality. On Red Hat based systems (RHEL, CentOS, Fedora), you need the vim-enhanced package, for example from a CentOS system I have installed: vim-common-7.0.109-4.el5_2.4z ...


21

In your .bashrc: alias vi=vim


18

At least for vim (not sure about vi), you can do cat file.txt | vim - The '-' tells vim to read from stdin.


18

What about Go, successively? ;-)


16

You can use cat file and then select output and copy and paste if you need to paste it into your browser. For vi this is how you can select all text and write it into a new file: shift v -- visual mode shift g -- jump to eof "*y -- yank select text :e my_new_file -- create a new file "*p -- paste into a new file In theory this should work on both Linux ...


16

Of course. There's Vim - vi improved. It offers a Windows port. Highly recommended.


15

I use vim_mode.pl with irssi (in GNU screen) and am extremely satisfied with the combination. For anyone who doesn't know Irssi, it's terminal-based and there is no GUI available or planned. While this may put some people off, it makes for a great combination with GNU screen, and allows you to keep your connection while being logged out: Always a good ...


14

This should do the trick: vim $(find . -name "*.txt") Use VIM, it's better for your health. :-) Piping into xargs vi gives a Warning: Input is not from a terminal, plus a terminal with completely bogus behaviour afterwards. User grawity explained why in a comment below, and with a bit more explanation in this question.


13

Note: You should look at man zshzle for a lot of goodies about customizing bindkey and emulating GNU readline. This is how I mapped jj to Esc: bindkey -M viins 'jj' vi-cmd-mode If you're interested in distinguishing between insert-mode and normal-mode, you could try out the suggestion akira mentions here


13

I've been using these map <Enter> o<ESC> map <S-Enter> O<ESC> in my .vimrc for years. Press Enter to insert a blank line below current, Shift + Enter to insert it above.


12

Yes, you can do it with :%s//bar. Explanation: in the substitute command when the search pattern is empty, Vim uses the last search pattern. Alternatively, you can explicitly paste the last search pattern, which is stored in a special register. You can quickly insert its contents by typing Ctrl-R+/ in insert or command mode. So enter command mode, type ...


12

VI[M] is standard across all systems while the installation for Emacs will vary depending on any number of settings.


11

From command mode, type the upper case letter 'G'.


10

RedHat based systems have a package called vim-minimal installed by default, which has a limited set of features enabled. You want to install the vim-enhanced package. Debian based systems do something similar, where vim-tiny is the default install and has a minimal feature set. Your Ubuntu system must have one of the other Vim packages installed (likely ...


10

In this case, I write the file with :w /tmp/tmpfile. Then I go out and move /tmp/tmpfile to my old file with sudo rights.


10

If it is a Debian or Ubuntu system, and you want to make this change system wide, you should use update-alternatives (specify with the --config editor options, and you should be golden)


10

'< and '> are marks corresponding to the beginning and end of a visual selection. Separated by a , they form a range that is inserted automatically for you when you hit : while in visual mode. That way, you can execute an Ex command (like s or d) against the selected lines without having to type the range yourself. Handy! And the best part is that ...


9

You have to (either run or) add the following command to your ~/.vimrc file: :syntax on


9

The pasted message suggests you still have the "notes" file open in another Vim session. It is definitely not a good idea to edit a file that is being edited elsewhere. If that message is wrong, you need to determine how your Vim session exited improperly and avoid that in the future. As for recovering, that may be an issue in this one instance since ...


8

First press ESC so you get back to command mode, then do. :x (quit and save) or :w and :q or :wq


8

Another option is to select the lines using Shift+V as Ignacio suggests, but then press > (greater than sign). That does an indent according to your indentation settings (shiftwidth, expandtab, etc). You can also indent more than one level with number>, e.g. 2> to indent two levels. Finally, if Vim recognizes the file type (type :set filetype?, it should ...


8

:%s/x/y/g This command replaces all instances of x in the current file with y. This is basically just a find and replace, but I use it so often since I've learned it at work that it has become invaluable. Also, /search string then n to navigate through all instances of the search string within the file. Great for doing manual tweaks a lot more easily, ...


8

Well it actually seems like you can build vim without support for visual mode. Check the output of :ver and see whether it says +visual or -visual. Bad luck if it's the latter.


8

If you meant vim you can do this with visual-mode (:help visual-mode) and text-objects (:help text-objects). To select a curly-braced block do: v+a+{, to select the enclosing block repeat a+{. Note that you can choose to only select the contents of the braces by using i instead of a. These commands, as many others in vim, are built up by an action followed ...


7

I believe the command you're looking for is simply . (period/full stop key). It's a normal mode command, so simply press the key in normal mode.


7

I do the remapping system-wide via the registry modification outlined at http://vim.wikia.com/wiki/Map_caps_lock_to_escape_in_Windows. On the same page, there's also an AutoHotkey solution. You can limit the scope of AutoHotkey remappings like this, which should (untested!) limit to Windows console windows: #IfWinActive ahk_class ConsoleWindowClass ...



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