Tag Info

New answers tagged

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.


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 /, \@!/


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


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


0

There is a hook that you can use to have vim execute a command after writing a file. For example here I use it to auto-reload vim's rc file after saving: autocmd BufWritePost $MYVIMRC source $MYVIMRC Unfortunately this will not help you at all with what you want to do. This is because the commands that get run are executed as children of the vim process. ...


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


0

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


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.


1

You can enable folding in current session like @Anthon's answer. But if you want make it permanent, you must setting at least this line in .vimrc to folding work: set foldmethod=indent indent is kind of folding, you can see more from :help foldmethod 'foldmethod' 'fdm' string (default: "manual") local to window ...


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


0

Add these lines to your .vimrc: let s:hidden_all = 0 function! ToggleHiddenAll() if s:hidden_all == 0 let s:hidden_all = 1 set noshowmode set noruler set laststatus=0 set noshowcmd else let s:hidden_all = 0 set showmode set ruler set laststatus=2 set showcmd endif ...


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


0

With vim only (don't use external command): let i=1 | '<,'>g/^/ s//\=printf("%03d ",i) / | let i+=1 Change let i=1 to number you want to start.


4

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


0

A POSIX portable means of viewing non-printable characters in a text file might be: sed -n l <file Besides being portable, sed will also default to printing the line twice if you eschew the -n - once with nonprintable characters represented with C-style or octal escapes immediately followed by another printing of the line as it would normally display. ...


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


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


1

If it did not have a control mode and an insert mode it would not have been able to distinguish between the operations on a text and the text itself.


1

Syntax highlighting of less, works just fine on most *nix systems. Even on Cygwin you can do it with the minor adjustment of the shell script path and installing with apt-cyg. apt-cyg install source-highlight export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s" export LESS=' -R ' However, using this drastically slows down browsing of large files. I ...


0

to answer your question: Is there a a kind of motion to move the cursor down to the next non-commented line without using hard to type regular expressions? No there isn't any direct way to do this beyond using a regular expression such as :/^[^#]. There are other plugins to Vim which you can use such as vim-identifier-movement, which allow you to move ...


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.


-1

Multiple solutions probably exist based on your preferences and workflow, as indicated in the comments above. But if you're using OS X, I'd recommend just using Command + C and Command + V to copy and paste so that it's the same in all applications you're working between.


0

I occasionally open large database backups in .sql text format. Very large files, or files with very long lines often sometimes seem to take a long time to open in vim. This might be related to syntax processing and colour highlighting, as mentioned in answers by @zzapper and @demonkoryu. A quick workaround might be to press "control-G" during loading ...


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


1

May be your colorscheme had overrided your configuration. You can add those lines at the end of .vimrc to prevent from overriding or add these lines to your .vimrc: "" Highlight trailing white spaces highlight ExtraWhitespacea ctermbg=darkred guibg=#382424 match ExtraWhitespace /\s\+$/ autocmd BufWinEnter * match ExtraWhitespace /\s\+$/ autocmd InsertEnter ...


0

:bufdo vimgrepadd yoursearchterm % | copen


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/


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.


44

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


54

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


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


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


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


0

I almost always prefer macros to search n substitute because they are more powerful and less to memorize while still retaining the option to interactively check before you leap. Try this on the first line you would like to change (do not type the spaces I put around ESC and ENTER for readability): qqI" ESC $bea" ESC /is supposed ENTER zzq What it does: ...


1

The famous surround plugin provides various mappings that make this quick and easy. To quote an entire line (without indent), just use yss". You can apply this to all matching lines of your example text automatically via the :global command and :normal: :g/is supposed/normal yss" Or just do a search for matching lines and repeat via n and .


0

The regular expression version works if your lines really are like that, and there's some distinguished string that identifies which lines are which. Otherwise, we can record a macro to do what you want. To do that, go to the start of line 2 and press: qq I" Escape A" Escape 3j q That will quote the first line and take us to the next one to look at. Then ...


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


0

I would attempt to launch vim and then from within edit a file over FTP. :e ftp://[user@]machine/path/ The plugin to vim that provides this feature is called netrw, it's included with vim by default. I'd take a look at the documentation specifically this section: INTRODUCTION TO BROWSING. It describes how to browse directories remotely through FTP.


0

Regarding the particular case of compiling source code. Short answer: see Chris's answer: http://unix.stackexchange.com/a/7825/3240 Long and more precise answer: here is mine on SO: http://stackoverflow.com/a/21477312/15934 And if you have something that can compile python, set makeprg accordingly.


-1

!gcc file.c && ./a.out This will compile your C file as well as run the executable asking for the input all within you vim window.


2

The filetype plugin enforces the preferred Git commit message style: Short title, and hard line breaks. If you don't agree with that style, undo the settings by putting the following into ~/.vim/after/ftplugin/gitcommit.vim: setlocal wrap formatoptions<


0

file /usr/share/man/man1/vim.1.gz from install of vim-common-2:7.4.179-1.fc20.x86_64 conflicts with file from package vim-minimal-2:7.4.027-2.fc20.x86_64 Both vim-common and vim-minimal ship a copy of the vim man page. Ordinarily, this does not result in an RPM conflict, since the files will be identical in both packages. However, you seem to have ...


0

If you're using NeoBundle then using NeoBundleLazy 'tpope/vim-sensible', then NeoBundleSource at the end of your vimrc does the trick. Also see https://github.com/tpope/vim-sensible/issues/74.


2

I suppose doing: "yum update vim-minimal" and then "yum install vim" source: https://bugzilla.redhat.com/show_bug.cgi?id=1066983



Top 50 recent answers are included