1

I have some plugins I would prefer load by default in the terminal, and cause performance issues or ux glitches in jetbrains ides running ideavim. Neovim needs to start getting adopted, but that's an aside. How can I detect intellij ides through vimscript?

I have used this in the past to detect the name of the terminal tmux is running in:

echo $(basename "/"$(ps -f -p $(cat /proc/$(echo $$)/stat | cut -d \  -f 4) | \
    tail -1 |\ sed 's/^.* //'))

I'm looking for, essentially, a vimscript equivalent of the above bash using vim built-ins for querying the state of the environment. Is there a vimscript api for that?

1
  • Off topic but I couldn't help but notice that shell command. Way too long. There's "useless use of cat" (and echo) and other redundancies. I have to guess a bit what you're doing since there are different versions of some of these commands but just paring it down in a tokenized fashion I get basename "/"$(ps -f -p $(cut -d \ -f 4 < /proc/$$/stat) | sed -n '$ s/^.* //p') But then I looked at it a little closer...are you trying to parse ps output for the parent of the current process? Then for that part, depending on environment, you may just need ps -f -p $PPID ! – B Layer Feb 2 '19 at 3:00
3

Generally speaking ideavim can handle consuming of native vimrc. That's because it doesn't actually parse it as vimscript. It just does pattern matching so anything non-compatible is skipped over. Most people get away with this just fine...

source ~/.vimrc

And that command is recommended on ideamvim's github homepage.

Unfortunately, if you want to pick and choose parts of vimrc to include there's no proper way. But there is a workaround based on the aforementioned fact that ideavim isn't a vimscript parser....you can source things in vimrc that you don't want sourced by ideamvim using this:

exe "source ~/someconfig.vim"

Ideavim will skip over such lines so you could have common stuff in vimrc and source vim-only stuff by way of the above command. Then you can safely source vimrc in ideavim.

Update: To reiterate, ideavim does not have a vimscript/VimL interpreter. It does a simple pattern-based scan of any sourced vimrc file, recognizing a few directives/commands...

Currently IdeaVim parses several .vimrc commands (:set, :map, :source, etc.) via pattern matching, i. e. it doesn't fully understand syntax of Vim configuration files.

The above quote is from an issue in the ideavim bug tracker that is requesting more expansive capabilities in this area.

Until/unless there are any such enhancements made, the things OP would like to do (e.g. conditional sourcing based on environment via something like if has('win32') ... endif) are not possible except to the limited extent that I mention above and which is also discussed on Stack Overflow How To Include Only Some of Vimrc in IdeaVimrc

3
  • I guess I'm asking how in vimrc to selectively load settings in a specific environment. Say, detect whether running on windows, Mac, or Linux and load a plugin or change from tabs to spaces. Using similar concepts I was wondering if it would be possible to detect some jetbrains software and change settings based on that. I do not know how much of vimscript ideavim implements. Hopefully, enough to accomplish what I am attempting to do. – ZeroPhase Feb 22 '19 at 22:52
  • My answer directly addresses the question of how the Vim emulator in Intellij processes vimrc files. It doesn't work anything like native vim. It just looks for basic patterns (e.g. set some-setting=foo) and ignores everything else including system type directives. So while native vim can conditionally execute vimscript only on a Windows system with if has('win32') <vimscript> endif Intellij can't execute vimscript at all!. You can only do basic configuration conditionally on Intellij vim vs native vim using the hack I describe. – B Layer Feb 23 '19 at 10:35
  • @ZeroPhase Thanks! Cheers. – B Layer Mar 31 '19 at 6:17
0

Not really sure why you want to check that, since IdeaVim uses .ideavimrc and not .vimrc or init.vim.

And so you can not have single common rc file for both IntelliJ and Vim. Contents of .vimrc and .ideavimrc can be same but the files have to be different.

2
  • Yeah, my .ideavimrc just sources my .vimrc. I still need to detect IdeaVim to keep config files maintainable. This will end up with .vimrc refactored to .ideavimrc just including common functions through a shared .sh script, included in each. The solution is Jetbrains deprecating IdeaVim and replacing it with the neovim engine so everything just works. But, that's probably five years off, and a .vimrc customized for Vim causes issues in Rider, in particular; it would be nice to track the particular variable down to make Rider usable in long files. (different issue from CLion) – ZeroPhase Jan 28 '19 at 19:35
  • I do agree that Neovim engine would be solution to all issues with Ideavim but yeah as you should there is no time line on that. What i would recommend is to break down your vimrc into multiple files, like one for settings, mappings, plugins etc, and then just source the specific ones in ideavimrc and in vimrc just source them all. As you might know there are number of things that don't work in Ideavim, few to name are commnad mode mappings, Autocommands, and some G commands in visual mode. – Rohit Bhanot Jan 29 '19 at 5:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.