Tag Info

Hot answers tagged

65

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


46

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


29

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


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.


18

:x is one key less than :wq


16

Create a custom mapping for frequenly used tasks. If you quit vim often, create a mapping with few key strokes, e.g. nnoremap <leader><leader> :xa<cr> If the <leader> is set to comma using let mapleader = "," hitting comma twice is a quick way of quitting vim and saving your changes. If you want to save one more key stroke when you ...


16

You can edit remotely with a local vim or gvim. :e scp://me@someplace.else/~/myfiles/whatever.file scp is a secure copy protocol. It authenticates the same way as ssh, so your ssh key needs to be available, etc. There are various other protocols supported (see :help netrw-externapp) but scp is probably the easiest if you are already using ssh to the ...


15

ZZ in normal mode saves the current file if modified and exits or closes the current window/tab (same as :x but not :wq which writes the file even if it hasn't been modified). To exit unconditionally after having written all the modified files in all windows, tabs and hidden buffers, you need :xa (it still won't exit if some files can't be written for a ...


15

There are several options to do so: You can use a terminal multiplexer like screen or tmux. In screen, for example, the shortcut Ctrl+a - a, has the same functiononality as Alt+Tab in graphical environments: switch to the last screen. Or you use vim's internal function. Type :!command in vim's command mode. For example: :!ls -l. After the command ...


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


12

You can add this to your .vimrcfile, or temporarily while in vim. vimrc - set laststatus=2 in vim - :set laststatus=2 To get the full path you can add this command, again to either your .vimrc or while in vim. vimrc - set statusline+=%F in vim - :set statusline+=%F Examples normal mode ...


12

From the command line, you could try paste -d '\0' file1 file2 > file3 That does exactly what you want. Visual Block mode in vim is also perfectly suited for this task. Are you sure you did it correctly? You should Go to visual block mode Select text and press y for yanking Go to the other file, on the upper left corner of the to be paste data (last ...


12

Try using less instead of vim if you want to view a large file directly. Vim tries to do a lot of different stuff when it first loads - scanning the file (potentially in multiple passes) to try to determine what syntax to use, and performing syntax highlighting, and searching for modelines at the top and bottom of the file. Then as you edit the file, vim ...


12

Considering the primary two modes, COMMAND and INSERT, demonstrates the purpose of a modal interface. In INSERT mode you can type normally, inserting text into the document. You can bind keys to perform special functions, although these are generally limited in complexity. COMMAND mode is sort of like an unlimited special function. Something similar ...


11

You may find q: useful. It opens the command-line window. The command-line window looks like this: I tried to make an animation of its usage: Also see c_CTRL-F, which opens the command-line window from command mode. You can also re-run the last command from normal mode by typing @:.


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


11

"load VIM without .vimrc and plugins (clean VIM) e.g. for HUGE files gvim -u NONE -U NONE -N largefile.sql


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

On terminals that support setting the scrolling region: tailf() ( # args: <file> [<number-of-header-lines>] trap 'tput csr 0 "$((LINES-1))"' INT tput csr "$((1+${2-1}))" "$((LINES-1))" tput clear { head -n"${2-1}" printf "%${COLUMNS}s\n" "" | tr ' ' = tail -n "$((LINES-1-${2-1}))" -f } < "$1" ) (assumes a shell like ...


9

When in vim I always use the :ls command. Example :ls 1 %a "blah.txt" line 1 Where blah.txt is the file's name.


9

According to this cheat sheet it would seem to come down to punctuation. w jump by start of words (punctuation considered words) W jump by words (spaces separate words) e jump to end of words (punctuation considered words) E jump to end of words (no punctuation) Example demo using w            ...


9

Entering : and then the beginning of the command previously issued followed by Up will retrieve the matching command. If there is more than one option available, you can cycle through them with Up and Down.


9

Ranges: You can do it with the following command: :66,70s/^/# for comment, and for uncomment: :66,70s/^#/ obviously, here we're commenting lines from 66 to 70 (inclusive). Hope this helps. Regards.


9

vim (on most systems these days vi is actually a symlink for vim) uses syntax files to define the coloring schemes for the various languages it can deal with. You have not specified which OS you use but on my LMDE system, these are found in /usr/share/vim/vim74/syntax/. When you open a file using vim, it will first try and figure out what type of file it ...


9

Yes, PIDs can be reused at any time. What you're seeing in that output is that the process that created that .swp file was 1466. It doesn't necessarily mean that process is still around. Remember that the file is static, it doesn't change just because the process which had it open died. So if 1466 is killed, the file still contains the information that said ...


9

Vim does not just load the file as-is into memory. It converts it into internal structures (lines, words, etc), performs syntax highlighting using an internal script language, and so on; all of which consumes memory (a whole lot more than a byte for a character) and CPU time.


9

Yes there is a way to automate this. And it starts with selecting the right tool, for the job. In this case you should be using e.g sed and not try to bend vi which was designed for interactive use (and not for automation). The replacement syntax for sed is largely the same as the one for vi. sed -i.backup 's/boy/Boy/g' file-name-1 file-name-2 ...


8

So any way to provide a different vimrc file ( maybe at command line, giving it as parameter each time as vim --vimrc=somefile file-to-open) ? Yes, use the -u parameter: vim -u ~/.my-custom-vimrc From man vim: -u {vimrc} Use the commands in the file {vimrc} for initializations. All the other initializations are skipped. Use ...


8

Use vim's filter functionality. Run: :%!cut -b36- to run the contents of your buffer through the cut command, retaining only bytes 36 and onwards. % means to run the entire buffer through and replace its contents with the output, then ! is the filter command, with the rest of the line as the program to run. This doesn't modify the underlying file unless ...



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