Vim runs shell command turning Chinese character into sign '?' - vim

I've tried to run set .*encoding (for example, encoding, fileencoding, etc.) into utf-8 but the question does not solved.
The question is: when I run command in normal shell, everything going well:
$ make SQL
+-----+-----------+------------------+-------+
| Sno | Sname | Cname | Grade |
+-----+-----------+------------------+-------+
| 01 | Peter | C Language | 98.1 |
| 01 | Peter | Data Struct | 89.3 |
...
| 08 | 王小明 | NULL | NULL |
| 09 | 王明儿 | NULL | NULL |
| 10 | A明B | NULL | NULL |
| 11 | A明B | NULL | NULL |
...
+-----+-----------+------------------+-------+
It works well, but when I run it under vim with vim-command :r!make SQL, it will print with '?' sign:
+-----+-----------+------------------+-------+
| Sno | Sname | Cname | Grade |
+-----+-----------+------------------+-------+
| 01 | Peter | C Language | 98.1 |
| 01 | Peter | Data Struct | 89.3 |
...
| 08 | ??? | NULL | NULL |
| 09 | ??? | NULL | NULL |
| 10 | A?B | NULL | NULL |
| 11 | A?B | NULL | NULL |
...
+-----+-----------+------------------+-------+
I am not sure what happen, but I have a solution that can work:
Run make SQL > tmp in shell.
Run :r!cat tmp in vim.
I also know that :r!make SQL > tmp && cat tmp still has the '?' problem. I do want to use r!make SQL directly in vim, and that's why I ask this question. Thanks for your help.
The :r!locale's result is:
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en
LANGUAGE=
LC_CTYPE="en"
LC_NUMERIC="en"
LC_TIME="en"
LC_COLLATE="en"
LC_MONETARY="en"
LC_MESSAGES="en"
LC_PAPER="en"
LC_NAME="en"
LC_ADDRESS="en"
LC_TELEPHONE="en"
LC_MEASUREMENT="en"
LC_IDENTIFICATION="en"
LC_ALL=

en is not a valid locale on many systems, and even where accepted, it's not going to have the results you want. Typically a locale is of the format xx_XX.CHARSET, where xx is a language code, XX is a country code, and CHARSET is a character set. For example, you could write en_US.UTF-8 for American English with UTF-8, or fr_CH.UTF-8 for Swiss French with UTF-8.
Because most Unix operating systems precede the existence of UTF-8 (macOS being a possible exception), generally the default locales on a system are not UTF-8, so if you specify a locale that does not declare UTF-8 explicitly, your tools will not use UTF-8.
As a result, you'll need to set your locale appropriately, in the format above, so that your system uses UTF-8 everywhere. That will make programs behave correctly.
Specifically to Vim, if you read data in from a piped command like this, Vim will do character set detection (controlled by fileencodings). If you don't have encoding set and your locale is a Unicode locale, Vim will look for a byte-order mark, then Unicode, and then default to latin1. If it's not a Unicode locale and the value is not set, then Vim will just your current locale, which is probably going to be interpreted as latin1, and you'll be sad. This looks like what's happening here.
You can, of course, adjust encoding, fileencoding, and fileencodings, but the easiest way to get sane behavior in Vim and across all programs is to set your locale to one that uses UTF-8.

Related

Horizontal vs Vertical array delimiters - International

Following up on an earlier question I had about horizontal vs vertical arrays, I have a question about it's respective delimiters.
Problem definition:
Hereby an example of an incorrect way of comparing two arrays:
{=SUMPRODUCT(--({"Apple","Pear"}={"Apple","Lemon","Pear"}))}
The correct way, in case of an English application countrycode would be:
{=SUMPRODUCT(--({"Apple","Pear"}={"Apple";"Lemon";"Pear"}))}
Within an English version (most likely more than just English) of Excel these delimiters would respectively be a comma , for horizontal arrays and a semicolon ; for vertical ones. Plenty of online information to be found on this.
Working on a machine with a Dutch country code on it's application however, it't a complete other story. It does frustrate that my delimiters would both be different, respectively ; and a \. Being able to rather simply retrieve the semi-colon it's proven to be tricky to find any documentation on these delimiters for international version.
Workaround:
Not knowing these delimiters up-front makes it tricky for anyone on a variety of international versions of the application to work with these type of formulas. A rather easy workaround would be to use TRANSPOSE():
{=SUMPRODUCT(--({"Apple";"Pear"}=TRANSPOSE({"Apple";"Lemon";"Pear"})))}
Going through the build-in evaluation we can then retrieve the backslash as the column seperator. Another way would be to use the Application.International property and it's xlColumnSeparator and xlRowSeparator.
Question
We can both find and even override the xlDecimalSeparator and xlThousandsSeparator through Excel (File > Options > Advanced), or VBA (Application.DecimalSeparator = "-") but where can we find:
A place to actually see which xlRowSeparator and xlColumnSeparator are used within your own application, other than the workarounds I described. Looking for an interface similar to thousands and decimal seperator and/or official MS-documentation.
Furthermore (not specifically looking for this), is there:
A place to override them just like the decimal and thousand seperators
If not through Excel interfaces, can we brute-force this somehow through VBA?
I'm very curious if official documentation is present, and/or if the above can be done.
Not claiming this is the right answer, but with the help from comments from other users, maybe the below can clarify things a bit:
With no sign of any official documentation on this matter, and seemingly random row and column delimiters #Gserg showed a trick to retrieve information for any LCID using these unique id's on MS office support under "Create one-dimensional and two-dimensional constants". While this is MS office support information, the delimiters you see there are FALSE. They might come up as . a , a ; a : a \ or even a |. You get this results by changing the LCID from the URL to a LCID of interest, e.g.: fr-fr.
Although there are about 600 different LCID's they all get redirected to a default LCID. With the help of #FlorentB. we discovered that not only the MS office support documentation is wrong, it seems that these delimiters are not that random after all. Looking at countries using a decimal point, they use the , as a column delimiter (a horizontal array) and a ; as a row delimiter (a vertical array). Countries using a decimal comma however use a \ as a column delimiter and a ; for rows respectively.
Changing the system country settings, checking all default LCID's in Excel, we ended up with the matrix below showing all row and column delimiters per default LCID:
| LCID | Row | Column |
|-------|-----|--------|
| ar-sa | ; | , |
| bg-bg | ; | \ |
| cs-cz | ; | \ |
| da-dk | ; | \ |
| de-de | ; | \ |
| el-gr | ; | \ |
| en-gb | ; | , |
| en-ie | ; | , |
| en-us | ; | , |
| es-es | ; | \ |
| et-ee | ; | \ |
| fi-fi | ; | \ |
| fr-fr | ; | \ |
| he-il | ; | , |
| hr-hr | ; | \ |
| hu-hu | ; | \ |
| id-id | ; | \ |
| it-it | ; | \ |
| ja-jp | ; | , |
| ko-kr | ; | , |
| lt-lt | ; | \ |
| lv-lv | ; | \ |
| nb-no | ; | \ |
| nl-nl | ; | \ |
| pl-pl | ; | \ |
| pt-br | ; | \ |
| pt-pt | ; | \ |
| ro-ro | ; | \ |
| ru-ru | ; | \ |
| sk-sk | ; | \ |
| sl-si | ; | \ |
| sv-se | ; | \ |
| th-th | ; | , |
| tr-tr | ; | \ |
| uk-ua | ; | \ |
| vi-vn | ; | \ |
| zh-cn | ; | , |
| zh-hk | ; | , |
| zh-tw | ; | , |
The apparent conclusion is that all countries use a semicolon as a row (vertical) delimiter. And depending on decimal seperator countries use a backslash or comma as a column (horizontal) delimiter within array formulas.
So even without proper MS-documentation, nor a place within the Excel interface (like thousand en decimal delimiter do have), on this matter it is apparent that knowing your country's decimal seperator will automatically mean you either use a \ or , as a column delimiter.
| Dec_Seperator | Row | Column |
|---------------|-----|--------|
| . | ; | , |
| , | ; | \ |
I would happily recieve more information about the above and/or presence of any correct MS office documentation to add to this.
It is possible to do this through native Excel (without VBA or add-ins) by querying Excel's C API, but I don't know of anywhere this is documented.
Go into Excel's Name Manager and click 'New...'. Enter a name such as GetColumnSeparator.
In the 'RefersTo:' box, enter the following to get the column separator:
=INDEX(GET.WORKSPACE(37), 14)
In an Excel cell, you can now enter this:
=GetColumnSeparator
and the comma (in English - or whatever symbol is in use on your machine) will be shown.
For the row separator you need to change the index number to 15:
=INDEX(GET.WORKSPACE(37), 15)
On an English machine, this will be the semicolon by default.
On machines where Excel's 'display language' is not English (meaning Excel's function names are translated), you will need a translated version of the above formula. Again I don't know of any documentation on this, so my best suggestion would be to install the English language pack, enter the formula in English, save the workbook, then revert to your original Excel language and re-open the workbook; Excel will translate the formula automatically.
Note that you will need to save the workbook as macro-enabled (e.g. .xlsm rather than .xlsx).
Sorry this is nearly three years late but I hope it helps.

Can we combine grid layout and terminal panel in vscode?

There is the grid layout in vs-code, and there is the terminal panel. Is there a way to combine both?
Lets say I want this :
--------------------------------------------------------------
| | |
| | |
| | |
| | something |
| | here |
| editor here | |
| | |
| | |
| |---------------------------|
| | |
| | |
| | terminal |
| | here |
| | |
| | |
| | |
--------------------------------------------------------------
I know we can put the terminal on the right, but I do not know if we can put it in the bottom of the right column. It works with other panel though, like editor.
To my best understanding, you cannot put the whole terminal panel (thinking of the combined: problems, output, debug console, terminal, ... group) in the grid layout.
However, you can put individual terminal shells into the editor and they will behave like opened files, able to be moved between editor panes.
After you have opened the terminal panel, you can drag and drop the shell's name (located just left of the little + sign where you can create a new terminal. It will have a name like bash or any other shell you are using) into the editor.
To make it easier, there is a setting for terminal.integrated.defaultLocation where you can specify the value to be editor. You split the editor panel as you see fit and then press workbench.action.terminal.new (default keycode is Ctrl+`) and you terminal will appear in the selected grid section.

NERDTree: Opening a file below the file explorer

I'm using NERDTree and (1) want to have the following layout in a single window to save the resolution in the horizontal direction. Does NERDTree support such a layout? In addition, I need to (2) arrange the display ratio in the vertical direction.
-----------------------------------
| |
| File Explorer: |
| |
| Always open. |
| |
-----------------------------------
| |
| Multiple Files: |
| |
| Only a single file is |
| displayed. You can display |
| a specific file in the |
| buffer invoking ":b [n]". |
| |
-----------------------------------
By default NEDTree opens files on the right of the file explorer as follows:
-----------------------------------
| | |
| | |
| | |
| F.E. | Multiple Files |
| | |
| | |
| | |
-----------------------------------
I do not use nerdtree, but a quick search in the source shows following lines:
call s:initVariable("g:NERDTreeWinPos", "left")
call s:initVariable("g:NERDTreeWinSize", 31)
So i bet you can use this in your .vimrc:
let g:NERDTreeWinPos = "top"
let g:NERDTreeWinSize = X
For the ration you can do some math with the &lines variable.
However you will have to do this in two autocmds VimResized and BufEnter and probably BufNew too.
There are a lot of questions and answers about autocmd on SO so i will not explain it any further unless you need some specific help.

Switch between layouts in Sublime Text 3

I'm working in a project with lots of files and switching between different tasks. And having a lot of files open at once clog the tabs in the panes (and my brain). So therefore I would like to be able to switch out all my panes/views much like switching workspace in Linux. And when I switch back it remembers the files/views/tabs.
In short: ability to toggle between this:
Layout 1 Layout 2
---------------------------- ----------------------------
| | | | | |
| file a | file a2 | | file b | file b2 |
| (+3 tabs) | | | | |
| | | | | |
| | | | | |
| |-------------| | | |
| | file a3 | | | |
| | | | | |
---------------------------- ----------------------------
Does Sublime 3 has this functionality or is there a package that can help with this?
Here is detail explenation for layout creating in sublime text : example
My suggestion is to create those two layouts and put key shortcut for both.
Install chain of command plugin. Create key shortcut for mulitple commands :
1. set layout 2
2. move focus to group 1
3. open "file b" by name [plugin]
4. move focus to group 2
5. open "file b2" by name [plugin]
Do same thing for layout 1 scenario. Here is example how to create plugin for opening file by name how-to-open-file-using-only-keyboard-in-sublime-text . You need to modify some part of that plugin because it use input dialog.

Can I escape the pipe in specflow (or gherkin)

I've got a specflow step table that I want to have the | (pipe) character as a part of the content.
Example:
Then the data should be
| Field | Value |
| SomeField | a|b|c |
But this doesn't work. How can I escape the pipe character?
Bah. I can't believe I didn't find this earlier. You CAN escape a pipe with the backslash, but the specflow syntax highlighter gets confused by it.
Then the data should be
| Field | Value |
| SomeField | a\|b\|c |

Resources