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

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

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


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

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

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

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

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


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


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

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

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.


3

If it is not an interactive or a login shell I think you're left with using ~/.zshenv. The following is from section "STARTUP/SHUTDOWN FILES" in zshall(1): Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login shell, commands are read from /etc/zsh/zprofile and then $ZDOT- DIR/.zprofile. Then, if the shell is interactive, commands ...


3

Due to the way that the keyboard input is handled internally, this unfortunately isn't generally possible today, even in GVIM. Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. (Unless your terminal sends a distinct termcap code for it, which most don't.) In insert or ...


3

See this wikia.com article for the exact thing you're tyring to do: http://vim.wikia.com/wiki/Map_Ctrl-S_to_save_current_or_new_files In a nutshell you need to do the following. 1. Add this to ~/.vimrc " If the current buffer has never been saved, it will have no name, " call the file browser to save it, otherwise just save it. nnoremap <silent> ...


3

Once you use sub-replace-special, introduced with \=, everything has to be a Vim expression; you cannot prepend / append literal replacement text. Therefore, your static text has to be encoded as Strings, and concatenated with .: :let i=1 | g/name/s//\='_first' . i/ | let i=i+1


3

The autoread option does not have a timer. A reload is triggered when a shell command is launched or checktime is executed. Furthermore, vim does not have built-in timer functionality, so there's no simple way (meaning without plugins or ugly hacks) to call checktime every n seconds. You can misuse updatetime and events like CursorHold to execute checktime ...



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