Tag Info

Hot answers tagged

21

Enter paste mode before you paste: :set paste To switch back to "normal" mode: :set nopaste


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


10

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


10

Beside the paste option mentioned by Mat, you can also directly access the X clipboard from VIM: "*p to insert the X11 selection "+p to insert the X11 clipboard You need a VIM version with X11 support (in Debian and its derivatives you need to install the vim-gtk or vim-gnome package). For more information, see the documentation (:help x11-selection).


8

Suppose you have this other set of settings in /tmp/myvimrc. If my reading of man vim is correct you can start vim with this set of settings using the following: $ vim -u /tmp/myvimrc Thus, to make this an option for the rest of the session, I would create a function that sets this as an alias for vim. Thus, in bash I would put something like this in my ...


8

You can use the VIMINIT environment variable to override the use of the usual .vimrc while keeping other parts of the initialization process. VIMINIT should be set to one or more ex-style commands (“colon” commands; use pipe (|) to separate multiple commands), not just the path to a different initialization file. VIMINIT='so /tmp/myvimrc'; export VIMINIT ...


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


7

See the manpage: -u {vimrc} Use the commands in the file {vimrc} for initializations. All the other initializations are skipped. Use this to edit a special kind of files. It can also be used to skip all initializations by giving the name "NONE". See ":help initialization" within vim for more details.


6

using .zshrc to modify my environment variables That's the root cause of your problem. .zshrc is a startup file for interactive shell sessions. Use it to set shell settings, not to set environment variables. Environment variables are typically set in a session file such as .profile. See Alternative to .bashrc (what goes for .bashrc also goes for ...


6

Probably not what you would call a nice solution, but you could wrap an i or a command between if 0 and endif: if 0 i some multiline comment here. . endif


5

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


5

You have to change the color of your cursor line to a color other than the color of your cursor. If you're in a terminal emulator like st or rxvt, Vim cannot change the color of your cursor; it will always be the color your terminal application decides to make it. Only the graphical version of Vim is able to change the color of your cursor. You can change ...


5

You could use :confirm quit, e.g. map <C-w> :confirm quit<CR> By the way: C-w is a bad choice for a shortcut, because it is used as the start of other shortcuts, e.g. C-w v for splitting vertically. That's why you experience a short delay before the dialog pops open: after you press C-w, vim waits a short time for other keypresses, before it ...


5

I guess the reason is that your home directory ~ is changed, where contains vim configuration file .vimrc . Normally ~ is /root if you login as root, and is /home/YOURNAME if you login as YOURNAME.


5

Yes, it is possible. You can load menu.vim (the default gvim menu definitions), or you can just start from scratch and create your own, then access them through :emenu. This doesn't give you nano-like always-visible menus, though; it gives you the ability to navigate menus using command-line tab completion. If the user doesn't have a vimrc, you'll want to ...


5

Central configuration If it's okay to configure the local exceptions centrally, you can put such autocmds into your ~/.vimrc: :autocmd BufRead,BufNewFile /path/to/dir/* setlocal ts=4 sw=4 On the other hand, if you want the specific configuration stored with the project (and don't want to embed this in all files via modelines), you have the following two ...


5

You can use the last jump mark (m') as a temporary mark. To avoid using a different command to re-enter insert mode (i vs. a), you can use the gi command, which re-enters insert mode at the position where it was last exited: inoremap <F4> <Esc>m'ggVG=``zzgi


4

When you log in via ssh, ssh sets variable $SSH_CONNECTION. Your .bashrc could check for this var and if it is set sets alias that you want: if [ -n "$SSH_CONNECTION" ] then alias vim='vim -u /tmp/myvimrc' fi


4

Your server is trying to use a file for lexical highlighting. The file does not exist at the place where vim is looking for it. At this point, you can do any one of the following: Remove the reference to syntax in /etc/vimrc Look for the syntax file on your server (e.g. find / -name syntax.vim) and copy or symlink that file to the directory where vim is ...


4

Yes, the :! command takes the remainder of the command-line as arguments. To concatenate other Vim commands, you can wrap the command with :execute: nnoremap <leader>ss :w\|:silent execute '!execute_external_script > output_of_script.txt'\|:redraw!<cr> Alternatively, you can just issue multiple command-lines, separated by <CR>; after ...


4

Here's what's happening. There are Vim formatting options that automatically comment out new lines when you are on a comment line. Some of these options are usually enabled by default. For example, # a comment<CR> # As you can see, the new line was automatically prepended with a comment character. You can disable the majority of these options by ...


4

You can split and open a new file at the named tag with the command :stag, it appears to default to the binding Ctrl-w, Ctrl-]. You could bind that to whatever then: map <F2> :stag If needs to be done in a tab, then, you can do it in two steps: Ctrl-w,Ctrl-] Ctrl-w, T Or you can map it: map <F2> :tab split <CR>:exec("tag ...


4

This vim wikia article titled: Keep incremental backups of edited files, sounds like what you're looking for. There's this method which attaches a save routine so that it's mapped to the Esc key. With the following mapping: fun! InitBex() let myvar = strftime("(%y%m%d)[%Hh%M]") let myvar = "set backupext=_". myvar execute myvar ...


4

Unfortunately, there's no way to do this without support from the plugin. (Sort of.) The key lines here are: setlocal foldmethod=expr setlocal foldexpr=WorkflowishCompactFoldLevel(v:lnum) The first means "use the value of 'foldexpr' to determine the fold level of each line". The second sets that option to use the value of a function defined in the ...


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


4

You can press Ctrl-z to stop vim and go to CLI, do whatever you need to (edit another vim file perhaps), then press fg on command line to return back into vim at the same place you left off at. If you didn't see the command fg being typed, then it's very likely that screen was being used.


4

Use an environment variable. This way, you can set THEME=dark or THEME=light in a shell, and all programs started by that shell will use the desired scheme. In bash or any other shell: case $THEME in light) PS1='\[\e05m\]fancy stuff\[\e0m\]';; *) PS1='\w\$ ';; esac In your .vimrc: if $THEME == "light" … else … endif


4

Yes, the vim command you're looking for is :source or :runtime to pull them from runtimepath. For example, you could do this in your .vimrc: runtime custom/java.vim runtime custom/haskell.vim presuming ~/.vim is in your runtimepath (which it is by default). You could also drop your scripts in the ~/.vim/plugin directory; see write-plugin in the docs. ...


4

To determine what editor to run, sudo checks three environment variables (in order): SUDO_EDITOR, VISUAL, and EDITOR, and uses the first editor it finds. (If it doesn't find one, it falls back to a default.) So you can make it run vimdiff instead of vim as follows: $ VISUAL=vimdiff sudoedit file1 file2 If your sudoers policy only lets you edit certain ...


3

You can add your .vim runtimepath on top of your .vimrc file: :set runtimepath=/home/b/.vim,$VIMRUNTIME This makes vim search for plugins, colors etc. in /home/b/.vim first and then in the standard location (for example /usr/share/vim/vim72/ in debian squeeze). I'm using this together with an alias vim='vim -u /home/b/.vimrc'.



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