Tag Info

Hot answers tagged

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


45

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


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


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


11

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


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.


7

You can count words and lines inside vi using vi's own counter: Press g and then CTRL-g. Then the bottom line look for example like this: Col 1 of 11; Line 1 of 106; Word 1 of 344; Byte 1 of 2644 Or use vi's method to call shell commands: :w !wc -w This calls the save (:w) command first and then wc -w and shows the output. Example: :w !wc -w 344 ...


5

You may try loading it as a binary. I've had luck with that for really big, non-text files vim -b HUGEFILE It's also possible IIRC to use vim as a hex editor see: http://usevim.com/2012/06/20/vim-binary-files/


4

Hopefully your problem is more to do with VIMs need for temporary files (such as swap) more than RAM. In many cases, the temporary files created by VIM are in the same directory of the file you are opening. If this is the case for you, then you can verify by checking the available disk space in the current directory. Fortunately, there is good ...


4

Use external unix command nl. :'<,'>!nl -w 3 -n rz -s' '


4

The syntax for lookarounds in vim is different from the PCRE syntax that you appear to have assumed. Instead of (?! ) try \@! i.e. highlight SquishedCommas ctermbg=red guibg=red match SquishedCommas /, \@!/


3

No you don't have to put the command from the page you linked to in your ~/.vimrc, you can just type them after issuing : in vim to get the command prompt. However if you put the lines: set foldmethod=indent set foldnestmax=10 set nofoldenable set foldlevel=2 as indicated in the link you gave, in your ~/.vimrc, you don't have to type them every time ...


3

To save a lot of clipboard text to file quickly, you can run cat > file.txt, paste the contents, then press Ctrl-d. If you have xsel installed, you can do :r !xsel to insert the "primary" (aka. "mouse") selection in Vim, or :r !xsel -b to insert the "clipboard" (Ctrl-c) buffer. You can also save the selection directly to a file with xsel >file.txt or ...


3

Using regular expressions: :%s/.*is supposed.*/"&"/ If by "semi-automatic" you mean you would like to be prompted before each substitution, just add the /c modifier to the substitution pattern: :%s/.*is supposed.*/"&"/c Explanation :%s means apply this substitution to all lines in the current buffer The pattern we match is any line containing ...


3

I'm not entirely sure what form your database is in, but there is a decent chance the file is in binary or some other format which allows a dbms to handle it quickly and securely, which vim wasn't designed to open. I'm still not sure what you are trying to do, but I would recommend using mysql or another dbms to make your changes. They will maintain the ...


3

You can use the regexp just once (something like /^[^#], i.e. find a line which starts with other than # character) and then search for next occurence with simple n command.


3

In vim, you can use redir command. In command mode: :redir > vim.output | set fileencoding | redir END Then output of set fileencoding will be save to vim.output. There is many other options of redir, you can see :help redir for more details. This works in vim, not in vi.


2

mouse=a prevents the ability of copying and pasting out of vim with readable characters. Change mouse=a to mouse=r and that should fix your issue with that. one thing I am wondering is, are you changing the config file for your vim with the mouse set to mouse=a? orignal answer ^ If mouse=r doesn't give you all the copy past options change it to mouse=v ...


2

The problem is that each :match command overrides the pattern of the previous one; they are not cumulative! Because of that, there are :2match and :3match variants. Use one of them: highlight ExtraWhitespace ctermbg=darkred guibg=#382424 match ExtraWhitespace /\s\+$/ highlight OverLength ctermbg=red guibg=#525252 2match OverLength /\%81v.\+/ Additional ...


2

You can try: open my $fh, '>', 'test.txt' or die "$!"; binmode $fh; print $fh "QWERTY\n"; You only see $ in vim because by default, listchars for end of line only contains $. From :help listchars: 'listchars' 'lcs' string (default "eol:$") global {not in Vi} Strings to use in 'list' ...


2

The patch script is accessible here in it's own GitHub repo, titled: powerline-patcher. An experiment I first started by downloading the above patching script. $ git clone https://github.com/Lokaltog/powerline-fontpatcher.git I then selected a sample .ttf file to test out your question. $ ls -lr | grep ttf -rw-r--r--. 1 saml saml 242700 Jul 2 20:29 ...


2

A direct way to do it: vim ~/.bashrc && source $_ You can make an alias: alias vimbashrc='vim ~/.bashrc && source $_' This works in bash or zsh. In other shell, you must explicit name .bashrc to source to make it work: alias vimbashrc='vim ~/.bashrc && source ~/.bashrc'


2

A change is any command that modifies the text in the current buffer. You'll find all commands listed under :help change.txt. In insert mode, a change is further limited to a sequence of continually entered characters, i.e. if you use the cursor keys to navigate (which you shouldn't), only the last typed part is repeated. Commands like j are motions; i.e. ...


2

You don't have to use it systematically: I usually manually select folds by the motion or section. For example, folding a paragraph is zfip and folding the next 20 lines is zf20j. Use za to toggle and zd to remove. This requires a little more work but allows your folding to reflect the task at hand.


2

Some vim syntaxes set certain settings when the file is opened. As you've found, you can get around this by using an autocmd to set the setting after the syntax has finished. To get the autocmd to apply on all file types, use a *. For example: autocmd FileType * set noexpandtab


2

You need to tell vim using command! -bar that a command can be followed by another command with the pipe symbol |: command! -bar FixWhitespace %s/\s\+$//e command! FixCommas %s/,\S\@=/, /ge Now this is OK: command! Fix FixWhitespace|FixCommas but this isn't: command! Fix FixCommas|FixWhitespace See :h command-bar for more details. The error message ...


2

You can access environment variables in your vimrc using $NAME. ssh sets the environment variable SSH_CONNECTION within an SSH session to non-empty metadata about the connection. You can combine these two to run configuration code based on whether you're accessing vim over SSH or not: if $SSH_CONNECTION colorscheme solarized endif The body of the if ...


2

Sorry I am not able to comment yet. Try to run command :sudo -s by this you will login as root. Then, I guess, you can do whatever work you want to.


1

If you have xterm_clipboard feature, you can use the * and + registers. These registers interface with the X11 primary selection buffer, and clipboard (respectively). Thus if you've copied something via CTRL+c, you can paste it in vim with "+p. If you've simply highlighted it without copying, you can paste it with "*p. You can also make the * buffer the ...


1

One workaround is using (remotely accessed) scratch files to transfer the text: In case you can SSH back to your own system, you can just :split scp://hostname/path/to/file, put the yanked text there, and :write. If you can just use SSH from your system to the server box, open Vim locally and access the scratch file from the server: vim ...



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