Tag Info

New answers tagged

0

I think you need to set the EDITOR environment variable like so: EDITOR="/usr/bin/vim"; export EDITOR Also if you have an alternative to $HOME/.vimrc that you want to use instead you could do the following: EDITOR="/usr/bin/vim -u $HOME/.othervimrc"; export EDITOR


2

Sometimes the vi command is an alias for vim and when called as vi enables its vi-mode. Even in traditional mode backspace is deleting the character, but does not display it as deleted immediately. (After pressing ESC the characters are gone.) Guess you have to choose between using vi which comes with the described behavior or using vim which is able to do ...


1

Checkout whether your are actually using plain vi via $ vi --version | head -n 1 This gives on my machine (Debian 7) VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Feb 10 2013 02:27:59) vim can be made to behave more similar like vi. This is often enabled when calling vi instead of vim from the commandline, where vi is only a sym-link to vim. You can ...


0

If your goal is to prevent losing code maybe backup files could help you. set backup " keep a backup after overwriting a file set backupdir^=/tmp// " list of directories to put backup files in I have it in my .muttrc, it stores backup files until restarting the Mac in /tmp/


0

To open all index.php in the current working path vim -p `find . -name index.php`


3

If it is a well-formatted CRLF file, vim will recognize it as such and set fileformat to dos. Try it with :set fileformat?. Thus set list will interpret CRLF, correctly, as legitimate line endings for this file format. See :help fileformats for more on file format auto detection. Also, this tips page expands on this and for example how to convert between ...


0

I think the best way would be to look at VI/VIM cheatsheet : http://www.viemu.com/vi-vim-cheat-sheet.gif Enter normal mode (ESC) and then SHIFT + X.


0

There's still a famous and often-requested break indent patch in the queue for Vim; this will improve on the existing 'showbreak' by properly indenting the wrapped line.


1

Sublime Text 2 also has this feature, and the width and type of indent are configurable.


5

In vim you can do something like: :set showbreak=..


0

You would need to reference the text length in a different regular expression. Because Vim (unlike Perl) doesn't allow the evaluation of Vimscript expressions inside regular expressions, you need to resort to meta programming, i.e. build the syntax rules on the fly: :execute 'syntax match svndumpData /^\n\_.\{' . length . '}/' This simple sketch uses \_. ...


0

My DeleteTrailingWhitespace plugin does this and, in contrast to the various simple :autocmds floating around, also handles special cases, can query the user, or abort writes with trailing whitespace. The plugin page contains links to alternatives; there's also a large discussion on the Vim Tips Wiki.


0

As @Marco points out in the comments, you're probably looking for the surround plugin. Using this plugin you can change the surroundings of text. For example: "Hello World" Got inside of the text and pres cs"' and the surroundings will change to 'Hello World' I would also recommend Tim Pope's pathogen plugin to use to get everything set up. It will ...


2

To keep cursor position use something like: function! <SID>StripTrailingWhitespaces() let l = line(".") let c = col(".") %s/\s\+$//e call cursor(l, c) endfun else cursor would end up at beginning of line of last replace after save. Example: You have a space at end of line 122, you are on line 982 and enter :w. Not restoring ...


3

This works (in the .vimrc file) for all files: autocmd BufWritePre * :%s/\s\+$//e This works for just ruby(.rb) files: autocmd BufWritePre *.rb :%s/\s\+$//e


2

Using :set paste prevents vim from re-tabbing my code and fixes the problem. Also, :set nopaste turns it off I also put set pastetoggle=<F2>in my .vimrc so I can toggle it with the F2 key.


1

This short script will preserve the modified time if any parent dir of the file contains a .nomtime file: #!/bin/bash dir="${1%/*}" [ "$dir" = "$1" ] && dir=. dir=$( readlink -f "$dir" ) nomtime= while [ -n "$dir" ]; do if [ -f "$dir/.nomtime" ]; then nomtime=1 break fi dir="${dir%/*}" done if [ "$nomtime" = 1 ]; then ...


0

If you need to have some fun: file=path; mtime=`stat -c %y $file`; vi $file; touch -d "$mtime" $file Replace path with your actual file path


0

I've figured it out. vim which appears in package list is not the same as the one I installed from source. I manually removed 'vim' directory from /usr/share, /usr/local/share and /usr/local/bin and now it seems there is no trace of it left.


0

I've found a vim plugin that suits my need completely which is vim-qargs. The idea behind is almost the same with @Ingo.


4

I don't have an X11 machine around so I can't verify this myself, but you might want to look at a program like xclip: xclip is a command line interface to the X11 clipboard. That won't exactly let you paste into your current tty, but it should at least print the contents of the clipboard to stdout. Then you can capture that into a file, or pipe it to a ...


1

Saving on lost focus is achieved through the following command in the .vimrc: autocmd BufLeave,FocusLost * silent! wall The syntax is: :au[tocmd] [group] {event} {pat} [nested] {cmd} In your case, you want to add VimResized to the list of events, see full doc here. The final result in the .vimrc file looks like: autocmd BufLeave,FocusLost,VimResized ...


2

Those are pipes, not regular files. It goes away when vim closes the file descriptor. You could do: hg cat -r 42 somefile | vim - (there vim is told it may not be a regular file so behaves accordingly. Use vim -R - or view - if you don't want vim to complain that the data has not been saved on exit). Or with zsh, using a temporary file: vim =(hg cat -r ...


2

You can use dictionary completion, i.e. :setlocal dictionary+=/path/to/your/file and then trigger the insert-mode completion with <C-x><C-k>; see :help i_CTRL-X_CTRL-K. If you want this only for filetype xxx, put the :setlocal in ~/.vim/after/ftplugin/xxx.vim. In contrast, Omni completion gives you more power, but you have to write the ...


1

The issue is caused by the sensible plugin:line 93. :help t_Co " Allow color schemes to do bright colors without forcing bold. if &t_Co == 8 && $TERM !~# '^linux' set t_Co=16 " << --- Causes hickup endif If you run vim in verbose log mode (vim -V15load_log.vim) – and search for t_Co= and RedundantSpaces you'll see that sensible is ...


2

I got all the pieces together to do the trick. The best way is to create a custom mapping for all the commands: map <F8> :let mycurf=expand("<cfile>")<cr><c-w> w :execute("e ".mycurf)<cr><c-w>p Explanation: map <F8> maps on "F8" the commands that follow let mycurf=expand("<cfile>") gets the filename ...


0

That can't be done easily. A [count] before <C-w>f specifies which file match on 'path' is opened, it does not select an existing window. Only for the <C-w>w command, [count] means "go to existing window number". To get that functionality, you need to write a custom mapping which either grabs the file, goes to the [count] window and emulates ...


3

You can write the loop yourself: for file in ['foo.txt', 'bar.txt'] execute 'edit' fnameescape(file) " Your processing here. endfor Or if you already have all files loaded in Vim, use :bufdo and execute your commands conditionally, based on whether the buffer (or buffer number with bufnr('')) is in your list: bufdo if index(['foo.txt', 'bar.txt'], ...


1

I need this so often, I wrote a plugin to simplify and allow maximum speed: ReplaceWithRegister. This plugin offers a two-in-one gr command that replaces text covered by a {motion} / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently ...


2

I would do that in this way (really useful for many paste): Go somewhere into the word Linux, then "ayiw to copy the word "a to select register «a» y for copying i to specify we are "in" (the word, the paragraph, ...) w to choose the word Got to next word w (or somewhere into the word) Paste on time and save that as macro qbdiw"aPq qb to start recording ...


0

You might want to consider "0p when pasting in visual mode. Ref :help v_p Move to L in Linux ye # Yank to end of word. w # Move to next word. <C>ve # Highlight Solaris. "0p # Paste Linux, Solaris ends up in unnamed register and Linux in 0 w # Move to next word. <C>ve # Mark next word. (Or anywhere else) "0p # Paste Linux. ...


1

Use registers and avoid visual mode. Move to 'L' (type 0fL) |L|inux Solaris Irix HP-UX "lye 'Linux' is now in the 'l' register. Move to 'S' (type fS) Linux |S|olaris Irix HP-UX "sde"lP Linux Linu|x| Irix HP-UX 'Solaris' is now in the 's' register. ...


0

It looks like your Pathogen setup isn't working. Check that :set runtimepath? contains ~/.vim/bundle/calendar-vim. With :scriptnames, you can check which files have been sourced; to be successful, there must be a plugin/calendar.vim in there. It's difficult to troubleshoot the particular Pathogen problem with that little information, sorry; I hope you ...


1

After doing these commands: cd ~/.vim/bundle git clone git://github.com/mattn/calendar-vim You need to add the following line to your $HOME/.vimrc file: Bundle 'calendar-vim' After doing this when I start up vim I get the command: :Calendar Which shows the following in vim. screenshot ...


2

TTY framebuffer console has no way to have more than 8-16 colors without kernel hacking, see this quote: "Although the Linux frame-buffer supports 256 (or more) colors, the Linux console driver does not; therefore, console applications are still limited to 16 colors on the Linux console, frame-buffer or not." So you can have no more than 16 or 8 colors. ...


1

Try out this bash function in the console. Fittingly, it doesn't work in an X terminal (I think because of the tabs). Especially check out the three files used last, namely /sys/module/vt/parameters/default_red /sys/module/vt/parameters/default_grn /sys/module/vt/parameters/default_blu clr () { clear # GFX bug otherwise setterm -regtabs 4 ...


0

You might want to try these settings in your .vimrc: set wildmode=list:longest,full set wildmenu Instead of the DOS cmd. window style of searching for files by repeating hitting tab, this setting makes it work like tab completion in a bash shell. Screenshot of vim ...


5

You should add it to your shell’s configuration file. For Bash, this is ~/.bashrc or ~/.bash_profile. You should also set $VISUAL, as some programs (correctly) use that instead of $EDITOR. Additionally, unless you know why, you should set it to vim instead of vi. TL;DR, add the following to your shell configuration (probably ~/.bashrc): export VISUAL=vim ...



Top 50 recent answers are included