How do I set the UI language in vim? - vim

I saw this on reddit, and it reminded me of one of my vim gripes: It shows the UI in German. I want English. But since my OS is set up in German (the standard at our office), I guess vim is actually trying to be helpful.
What magic incantations must I perform to get vim to switch the UI language? I have tried googling on various occasions, but can't seem to find an answer.

For reference, in Windows (7) I just deleted the directory C:\Program Files (x86)\Vim\vim72\lang. That made it fallback to en_US.

Try this in _vimrc. It works with my win7.
set langmenu=en_US
let $LANG = 'en_US'
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim

As Ken noted, you want the :language command.
Note that putting this in your .vimrc or .gvimrc won’t help you with the menus in gvim, since their definition is loaded once at startup, very early on, and not re-read again later. So you really do need to set LC_ALL (or more specifically LC_MESSAGES) in your environment – or on non-Unixoid systems (eg. Windows), you can pass the --cmd switch (which executes the given command first thing, as opposed to the -c option):
gvim --cmd "lang en_US"
As I mentioned, you don’t need to use LC_ALL, which will forcibly switch all aspects of your computing environment. You can do more nuanced stuff. F.ex., my own locale settings look like this:
LANG=en_US.utf8
LC_CTYPE=de_DE.utf8
LC_COLLATE=C
This means I get a largely English system, but with German semantics for letters, except that the default sort order is ASCIIbetical (ie. sort by codepoint, not according to language conventions). You could use a different variation; see man 7 locale for more.

Putting this line of code at the top of my _vimrc file saved my day:
set langmenu=en_US.UTF-8

This worked for changing vim's menu language
set langmenu=en_US.UTF-8 [or just set langmenu=en for short]
But
language en
gave me an error sayng it couldn't set en as a language but this line did the job
:let $LANG = 'en'
The latter come from the Vim's docs. I added both lines at the beginning of the _vimrc file. I use a Windows 7 64 computer.
PS: this line changes both language and menus language
language messages en
In the .vimrc file (or _vimrc file if you are in windows)

Ubuntu 10.10 + VIM 7.2 IMproved. Code below changes language for console vim.
Add it at top of your vim.rc
if has('unix')
language messages C
else
language messages en
endif

Adding this to _vimrc works for me in windows 8:
set langmenu=en_US
let $LANG = 'en_US'
(note that _vimrc is in the same directory that contains my vim74 dir, thats the _vimrc file that vim reads at startup)

:help language
:language fr_FR.ISO_8859-1

These two lines at the begining of your .vimrc file will do the job:
let $LANG = 'en'
set langmenu=none

Start vim with a changed locale:
LC_ALL=en_GB.utf-8 vim
Or export that variable per default in your bashrc/profile.

Two Vim installations on Windows
Nothing from here around have helped me until I have realized that I have 2 Vim installed.
Git Bash via MinGW (Cygwin, mintty)
A separate installation in the Program Files on Windows
Next command will filter you all watched vimrc-files and their locations.
vim --version | grep vimrc
_vimrc (Windows & CMD)
.vimrc (Bash for Git)
vimrc (has different locations for both)
1: Vim on Windows & CMD
Only renaming (deletion) of the lang folder helped me.
You can find it here C:\Program Files (x86)\Vim\vim80\lang
I tried all config settings listed here around and it was useless.
2.1: Git Bash through MinGW, Cygwin, mintty
For Git Bash I added language messages en_US at the top of C:\Program Files\Git\etc\vimrc
Of course, if you prefer to delete the lang folder you can find it here
C:\Program Files\Git\usr\share\vim\vim80\lang
C:\Users\User_name_xxx\AppData\Local\Programs\Git\usr\share\vim\vim80\lang for a local user installation.
2.2: Tuning only Git's Bash (MinGW64, Cygwin, mintty)
At the end, for Bash on Windows I have chosen to skip manipulations with vimrc
I opened C:\Program Files\Git\etc\bash.bashrc
and added the following line
LANG='en_US'
or
LANG=C
Try to do not use en_US.UTF-8 because it forces some bash commands to produce weird chars. For example in find 'xxx_yyy_zzz_aaa.bbbddd' for a non-existing file.

I don't know why all of the above answers did not work for me. I kept getting errors about the locales not existing. Maybe it's a Windows thing. At any rate, my solution was to add this to my vimrc:
let $LANG = 'en'
Ah, I spoke too soon. The menus of gVim are still in Japanese, but the intro screen is in English.

Try adding this to your _vimrc:
let $LANG='en_US'

I simply disabled the Native Language Support when installing gvim
(thus making it a custom installation).
Tested successfully with gvim82.exe under Windows 7.

Had similar issue, but neither one of above solution worked:
https://superuser.com/questions/552504/vim-ui-language-issue/552523
I've resolved it by removing all vim packets and build vim from sources.
Hope it'll help someone.

If you're on Windows and don't want to be bothered issuing commands
To prevent the GUI from loading localization files
Just go to Program Files\Vim\vim80\lang and put an underscore as a prefix in front of all the files that look like they have something to do with your locale.
To prevent VIM itself from loading localization files
In the same folder as above, prefix with an underscore the folder named with your country code.
Note: Windows 10 will probably ask for Administrator privileges by raising a UAC warning.
By the way
This same technique can be applied to a lot of Unix/Linux tools ported on Windows, and generally all software packages where the localization files can readily be accessed. If you rename those to prevent the application from finding them, the fallback language will most probably be English.

Related

Why does my shell prompt disappear when I install vim 7.4?

I'm using CentOS 6. Since the CentOS repos have an older version of vim (7.2), I have compiled my own. However, I am having a weird issue. After running and exiting vim, I've found that my shell prompt has disappeared. Also, when I type, it does not appear in the terminal, nor does any output. What's weird is that it looks as though something is being outputted, since the cursor will move down the screen, but I can't see anything.
It must have something to do with compiling an X version, because it does not happen when I compile vim without X windows support (but I would like to have gvim, too). Here are the configuration options I supplied when compiling:
./configure --prefix=$OPT/Cellar/vim/7.4 --with-features=huge --enable-gui=auto --with-x --enable-xim
I also tried compiling without Xim. I've also tried explicitly setting --enable-gui=gtk2 (which is what gvim 7.2 from the CentOS repos uses).
I am using KDE4. The problem occurs both when running tcsh and bash. I have tried with $TERM set to both xterm and xterm-256color as well.
Additionally, running neither reset nor stty sane restores the shell to its proper behavior.
Any idea why my prompt disappears when running vim? As I missing a config flag or some other compilation issue?
I ultimately traced this down to an error in my ~/.vimrc file. I had some lines like this:
if has('gui_running')
# Gvim customization
endif
if has('gui_gtk2')
# GTK2-specific Gvim customization
endif
The second block was running every time vim loaded. Because it changed some window geometry, it ended up messing up bash; when I dropped back to bash, bash thought it only had ~53 columns to work with (and possibly some other things were messed up).
Solution: The second if block should be inside the first.

Linux, Xterm, and VIM localization behavior of setenv LANG vs. setenv LC_CTYPE

I am writing some perl scripts to process some files with Japanese names and contents. I wanted to see the file names when I do ls in xterm, instead of garbage characters.
Here is my configuration:
Client OS:
Windows XP Japan
Server:
Red Hat Enterprise Linux Server release 6.2
VIM : VIM version 7.2.411
Xterm : ASTEC-X version 6.0
CSH: tcsh 6.17.00 (Astron)
After I updated my .cshrc to use setenv LANG ja_JP.UTF.8, and re-open my xterm window, it was really hard for me to back out because of the following:
1) In VIM, I would try to open the .cshrc file, and delete a comment line above by pressing backspace, but instead the line below the cursor disappear, and then the top line is copied. All the VI errors are in garbage characters.
2) I could not back up my file in shell, and I also get unreadable error.
[someguy#simunec1 ~]$ copy .cshrc .cshrc.bak
copy: -Ac3c3cch&c$ccc>c (B.
[someguy#simunec1 ~]$ 1;2c
3) I could not use visual mode in VIM to copy the entire content of .cshrc (somehow only the beginning parts gets to the clipboard).
4) Eventually, I managed to get the pieces I want to back out in my .cshrc in the clipboard before deleting most of it and reloading xterm.
Questions:
1) Anyone can help explained what just happened above?
2) I later found another source that suggested setenv LC_CTYPE ja_JP.UTF-8 (https://unix.stackexchange.com/questions/16771/foreign-characters-wont-display-in-ssh). It gave me the ability to see the files in Japanese when I do ls, while keeping the vim and shell error messages in English, and I can see also the Japanese characters in VIM in my perl scripts. Pressing backspace in VIM doesn’t result in the cursor jumping about and new lines being pasted. Somehow I got the best of both worlds, and I am not sure why that works and set LANUG doesn't, although the font for the English characters has become bulky, and it is hard to program in.
Thanks.

Running gvim from MSYS --- how to avoid/change MSYS enviroment variables?

When I run gvim from MSYS, things go wrong during initialization. Namely, gvim can't find the initialization files that are in 'C:\Documents and Settings\username\vimfiles.
[Specifically, gvim reports the error E117: Unknown function: pathogen#infect during initialization, so it never found autoload\pathogen.vim. Doing :scriptnames also confirms that none of the setup files from vimfiles\ are run.]
I think I've debugged why it goes wrong. When you start MSYS, the MSYS shell inherits the windows enviroment variables, but changes some of them to it's custom values. C:\Documents and Settings\username is the value of $HOME in Windows, but MSYS sets it to something like C:/msys/user name. And of course, Vim uses $HOME to find the right initialization files.
I also notice set shell? has changed to something like shell=C:/msys/bin/sh instead of shell=C:\WINDOWS\system32\cmd.exe, but I hope this isn't important for fixing the initialization problem.
I need to run gvim with the normal windows environment variables. At least I need to be able to manually override a few important ones like $HOME to something I specify (i.e., I'm not concerned about my windows $HOME changing, so it's fine to use a static value).
I tried to reset $HOME manually in my vimrc, but by then it is too late.
Is there some trick to specifying $HOME early on during initialization, or as an extra command line parameter?
Alternatively, is there some trick with running commands from msys differently? I know almost nothing about how the shell C:/msys/bin/sh works, but I could conceive of some extra arguments that changes the visibile environment for the command (e.g. gvim.exe) you are typing.
---Edit---
Reposting the solution that worked (it achieves the later idea):
Instead of running gvim.exe, run the command HOME="C:\Documents and Settings\username" gvim.exe
In bash and other UNIX shells, you can do:
$ HOME='/path/to/dir' gvim
to temporarily set $HOME to a different value.
I admit I'm not familiar at all with the Windows command line, but it might be worth a try.
I believe you can define $HOME just like any other environment variable.
Try adding this to the start of your .vimrc.
let $HOME="C:\Documents and Settings\username"
I had a similar issue when running Cygwin (which is similar to MSYS).
The easiest solution for me was to simply set the HOME environment variable to an empty string. Otherwise, the Cygwin HOME value would be appended to the Windows USERPROFILE in GVim and it would fail to start correctly. Not explicitly setting the full path of the HOME means that I can use the same start-up files on different systems where the USERNAME may not be the same.
Likewise, the SHELL environment variable should not be inherited from Cygwin Bash. This results in errors when running shell or external programs via !. Again, I set this to be an empty variable since Vim is smart enough to figure out what it should be.
In my .bashrc, I set the following alias for running Windows gvim which starts GVim with the HOME and SHELL variables set to an empty string – just for that command.
gvim="/cygdrive/c/Program Files (x86)/Vim/vim74/gvim"
if [ -x "$gvim" ]; then
alias gvim="HOME= SHELL= \"$gvim\""
fi
unset gvim
I achieved this by making a windows symbol link (Win 7 or higher).
Via a symbol link, you can even make vim and gvim to use the same configuration and plugin.

vim unmap everything (completely stripped down vim)

Love vim. Tried Janus. Like the idea, but it's too slow, 100 plugins competing for keybindings. I want to actually understand what every vim configuration I make does.
Is there a way to "unmap" all vim keys or as much as possible. Remove most commands, etc. The point of this is an exercise for myself. I want a super small subset of maps, settings, bindings, so I can add things one by one as I need them.
Have you seen efforts like this?
Try to run vim with the following command :
"vim -u NONE"
from man vim
-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.
It should start vim without any plugin or customisation.
Aside from
:mapclear
:nmapclear
:vmapclear
:xmapclear
:smapclear
:omapclear
:mapclear
:imapclear
:lmapclear
:cmapclear
starting it like
vim -U NONE -C -Z
will start
-U without startupfile
-C in compatible mode
-Z in restricted mode
I tried to do something similar and posted that on reddit post.
I try to restrict the mappings I define in my vimrc and load only some
plugins that I find essential.

Is it possible to "extend" IntelliJ such that I can open the current file in VIM

I use IntelliJ for most of my Java programming, but every once in a while I need to make certain changes which are much easier done in VIM.
Thus, the question:
While I'm editing a file in IntelliJ, it is somehow possible to tell IntelliJ to start VIM with the same file that is currently under cursor.
Thanks !!
Absolutely!
Go to File -> Settings -> External Tools and add a new one.
Program and Working Directory fields should be self-explanatory. The parameter field should be $FilePath$. Click the Insert macro button to see more token values that you could use.
You can also bind keyboard shortcuts to the external tools you define.
See the help page on configuring third party tools for more info.
Also, see the answers below with helpful screenshots for Windows or Mac.
Even though the original question is about VIM, I'd like to share my settings for GVIM. Especially useful is the parameter used to take it to the current line.
I find it useful to have Gvim open up the file AND take me to the current line. This is done using the following parameters: +$LineNumber$ $FilePath$.
When executed, Gvim should open up and take you to the line you were at in Intellij.
Here's how to set this up with the Homebrew version of MacVim (i.e. the mvim command) on Intellij IDEA 14.
Go to Preferences->Tools->External Tools and click the plus symbol.
Set up the new tool with these parameters
Program:
/usr/local/bin/mvim
Parameters:
+"silent! "$LineNumber$"|norm! zz" $FilePath$
Working Directory:
$SourcepathEntry$
For macOS 10.12+ users, If you want to open it in iTerm2, here is a latest solution:
#!/bin/sh
vim="vim $1"
osascript -e "
tell application \"iTerm\"
set myterm to (create window with default profile)
tell myterm
activate current session
launch session \"Default Session\"
tell the current session
write text \"$vim\"
end tell
end tell
end tell
"
Date: Apr 5, 2018
iTerm2: 3.1.5
IntelliJ IDEA: 2018.1
https://gist.github.com/backslash112/open_vim_in_iterm.sh
This was somewhat more involved on the Mac OS X (Lion), especially if you'd like to use Terminal.app
The only difference on Linux is the shell script would be much simpler... (really it'd be simple to not even use a shell script for this on Linux, with a terminal that accepts the -e argument!)
Here's my working solution:
#! /bin/sh
vim="vim $1"
osascript -e "tell app \"Terminal\"
activate
do script \"$vim\"
end tell"
I am using these parametrs for launching vim: +$LineNumber$ --remote-tab-silent "$FilePath$". It allows you to open each new file in vim's tabs. Works fine)
Go to Settings -> Tools -> External Tools
Click the + to add a tool.
Here are the settings I use:
Name: Vim
Program: /usr/bin/gvim
Arguments: --servername $ProjectFileDir$ --remote "+call cursor($LineNumber$,$ColumnNumber$)" $FileDir$/$FileName$
Working directory: $ProjectFileDir$
I turn off "Open console for tool output".
The arguments will use Vim in client-server mode, so if you jump to Vim from IntelliJ in the same project dir multiple times, the existing Vim instance will be reused, and they will also place the cursor in Vim exactly where it is in IntelliJ.
Try out the VIM Plugin, http://plugins.intellij.net/plugin/?id=164
I have experienced some bugs but for the most part it works.

Resources