'detect vrapper in .vimrc
In my .vimrc I have the following:
" Use j/k to navigate the word completion popup menu
inoremap <expr> j pumvisible() ? "\<C-N>" : "j"
inoremap <expr> k pumvisible() ? "\<C-P>" : "k"
This works perfect when using vim within a terminal, however this is not compatible with vrapper (eclipse vim plugin). Vrapper completely stops working when these settings are in my .vimrc. In my home directory I have a .vrapperrc
file, which is simply a symobolic link pointing to my .vimrc
file. Hence the vim settings which are loaded for vim / vrapper are equal.
Is there a way that in my .vimrc I can detect that the settings are loaded for vrapper instead of default (terminal) vim. That way I would like to disable these settings for vrapper and just load them when vim is used from the command line. Perhaps there is a different smart way to solve this issue. Of course I could create two .vimrc files, one for default vim and one for vrapper, however that way I would need to maintain two files which I would like to prevent.
Solution 1:[1]
I had a similar problem in which Vrapper executed the contents of my functions immediately because it didn't understand what they were.
I solved it by wrapping the vim only code with
if has("eval")
" vim only code
endif
which caused Vrapper to ignore it.
Solution 2:[2]
As @romainl noted, Vrapper only understands a limited set of Vim commands and features. Function definitions, ternaries and <expr>
are definately not supported.
If you are willing to split your rc files, you could use the source
command to at least reuse one of them.
For example, put these basic settings in your .vrapperrc
:
set ignorecase
set hlsearch
Then you can do this in your .vimrc
:
" Load common settings for Vim / Vrapper
source .vrapperrc
" ... Other Vim-specific settings
Note that Vrapper also has a source
command, so you could in theory have 3 rc files with the "common" settings shared between the two:
Example .vrapperrc
:
set novisualmouse
source .vimcommonrc
Example .vimrc
" Use j/k to naviage the word completion popup menu
inoremap <expr> j pumvisible() ? "\<C-N>" : "j"
inoremap <expr> k pumvisible() ? "\<C-P>" : "k"
source .vimcommonrc
And the common settings:
set hlsearch
set ignorecase
It's your choice.
Solution 3:[3]
I don't think you can detect Vrapper, but you can instead write a command that real Vim will process and Vrapper will ignore.
Example: mapping <KMinus>
:
nnoremap <KMinus> q
If Vrapper runs that, it crashes. Let's make it ignore it. There are many ways:
if v:true
nnoremap <KMinus> q
endif
if v:true | nnoremap <KMinus> q | endif
exec 'nnoremap <KMinus> q'
There's also this more "aggressive" version, if the other ones don't work. It's useful for multiple commands:
if v:true |
\nmap <C-Bslash> gcc |
\vmap <C-Bslash> gc |
\imap <C-Bslash> <C-o><C-Bslash> |
\endif
You can even add a finish
statement which Vim will treat as "I should stop reading this file" and Vrapper will probably ignore and keep executing the file, making it ideal to precede Vrapper-only commands:
if v:true
" Vim-only stuff
finish
endif
" Vrapper-only stuff
Solution 4:[4]
How do you think it would work?
Your ~/.vimrc
is not a sentient being that can take decisions by itself: it needs to be sourced by a program that understands it and… that program is Vim.
Vrapper only supports a subset of Vim's vocabulary so it is not very reasonable to expect it to behave exactly like Vim. The main missing feature that would make possible the detection you are asking about is vimscript: since Vrapper doesn't support it you can't use an if-else-endif
construction!
Because the two programs support vastly different sets of options and commands I'm afraid you will have to manage two separate files.
Did you try Vrapper's :source
command?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | hortman |
Solution 2 | Community |
Solution 3 | |
Solution 4 |