Prepare vim environment to work with clang-format - c++

Problem:
E319: Sorry, the command is not available in this version
Problem
When I run vim environment and try reformat code (CTRL+K) i get this warning on the screen
Environment:
System: Mac OS X
Settings:
Vim:
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 17 2016 20:17:27)
MacOS X (unix) version
Included patches: 1-91
python:
python --version: Python 3.5.2
What I do
Update vim: 7.3 -> 8.0
Update python: ~2.7 -> ~3.5
I updated the .vimrc file
from
map <C-K> :pyf .../clang-format.py<cr>
imap <C-K> <c-o>:pyf .../clang-format.py<cr>
to
map <C-K> ggVG :py3f .../clang-format.py<cr>
imap <C-K> <c-o>:py3f .../clang-format.py<cr>
Also I update clang-format file
https://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/clang-format.py
Thx,

Solution:
1. Go to .vimrc file and add commands
map <C-K> :pyf <path-to-this-file>/clang-format.py<cr>
imap <C-K><c-o>:pyf <path-to-this-file>/clang-format.py<cr>
2.Add this https://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/clang-format.py source code to clang-format.py file, you can save this file to i.e
<path-to-this-file>/clang-format.py
where path-to-this-file is path to direction where you put this file.
3.Save clang-format.py file and run vim. Check that the command works.
You can also install macvim for OSX. Instruction you can find here. How can I install MacVim on OS X?
PS: If you get "Sorry, the command is not available in this version" error, try:
map <C-K> :py3f <path-to-this-file>/clang-format.py<cr>
imap <C-K><c-o>:py3f <path-to-this-file>/clang-format.py<cr>

Here
$ which clang-format
returns
/usr/local/bin/clang-format
Then
ls -ls /usr/local/bin/clang-format
points to
/usr/local/Cellar/clang-format/2018-04-24/share/clang/clang-format.py
So I do
$ vim ~/.vimrc
map <C-K> :pyf /usr/local/Cellar/clang-format/2018-04-24/share/clang/clang-format.py<cr>
imap <C-K> <c-o>:pyf /usr/local/Cellar/clang-format/2018-04-24/share/clang/clang-format.py<cr>
This works on vim (from terminal) but not on macvim.

Just mention the project https://github.com/rhysd/vim-clang-format
Which is very handy to use, and save us from repeated work.

Related

clang-format not working in vim - missing libtinfo.so.5 library

I'm trying to set up vim for C++ editing in Ubuntu 20. I'd like to use clang-format to format my files. My vimrc looks as follows:
map <C-K> :py3f /usr/local/clang-10.0.0/share/clang/clang-format.py<cr>
imap <C-K> <c-o>:py3f /usr/local/clang-10.0.0/share/clang/clang-format.py<cr>
When I run this in vim by hitting C-k over a block of code, I get this error:
b'clang-format: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory\n'
No output from clang-format (crashed?).
Please report to bugs.llvm.org.
Has anyone encountered this before? How do I resolve this?
Sorted it out. It looks like Ubuntu 20 has libtinfo.so.6. I installed the libtinfo.so.5 package using:
sudo apt update && sudo apt install -y libtinfo5
Note - I saw some posts on doing an alias "ln -s" on the libtinfo.so.6 file. This did not work for me.

Running configure file in MinGW64: default build_alias command and default prefix not found

I'm using MinGW64 via an MSYS2 download and am currently trying to install the Solar Geometry 2 library (http://www.oie.mines-paristech.fr/Valorisation/Outils/Solar-Geometry/) for use. I'm following their install README, which states to navigate to the directory and "configure" (I've been typing "./configure". However, when I do so, I get the following message in my terminal:
$ ./configure
configure: loading site script /mingw64/etc/config.site
/mingw64/etc/config.site: line 13: config.site:13: default build_alias set to x6_64-w64-mingw32: command not found
/mingw64/etc/config.site: line 20: config.site:20: default prefix set to /mingw4: No such file or directory
configure: error: cannot find install-sh or install.sh in . ./.. ./../..
When I initially installed MSYS2 I set up the etc/fstab file as recommended. However, I'm quite new to MSYS so I'm assuming I botched something in my setup. I haven't edited anything in the config.site file mentioned in the errors, so I'm wondering if it's something in there.
Any help is greatly appreciated, thank you
No where in the directions for "Solar Geometry" do I see reference to MSys or MSys2.
I suggest you install the compiler toolchain and base development file. No idea if you editing /etc/fstab will cause problems. I do not normmaly edit it!
Install MinGW Package build packages. You might need more packages installed.
pacman -S --needed base-devel mingw-w64-x86_64-toolchain

Clojure 1.9 command line tools - command not found clj.sh

I have just installed clojure 1.9 on my mac via Homebrew.
As expected I get 2 links in /usr/local/bin to the actual executables
clojure# -> ../Cellar/clojure/1.9.0.358/bin/clojure
clj# -> ../Cellar/clojure/1.9.0.358/bin/clj
running clojure from the command line works
$ clojure
Clojure 1.9.0
user=>
but for not for the command line tools
$ clj
zsh: command not found: clj.sh
both executable files exist
$ ls Cellar/clojure/1.9.0.358/bin
clj* clojure*
I've tried uninstalling clojure with brew uninstall and have deleted the cached version of clojure-tools-1.9.0.358.tar.gz in my ~/Library/Caches/Homebrew/ directory.
Installing it again was successful
$ brew install clojure
==> Downloading https://download.clojure.org/install/clojure-tools-1.9.0.358.tar.gz ####### 100.0%
==> ./install.sh /usr/local/Cellar/clojure/1.9.0.358
🍺 /usr/local/Cellar/clojure/1.9.0.358: 9 files, 19.4MB, built in 31 seconds
but still the same error.
Interestingly if I use the Finder to locate the file and double click on it, a new terminal window opens up and things seem to work.
Last login: Tue Mar 6 10:35:48 on ttys002
/usr/local/Cellar/clojure/1.9.0.358/bin/clj ; exit;
$ /usr/local/Cellar/clojure/1.9.0.358/bin/clj ; exit;
Clojure 1.9.0
user=>
Any ideas please on why this executable won't run directly from the command line?
Many thanks
The problem was that I'd set up an alias for clj in my shell profile file which referenced a shell script called clj.sh that I'd written but which no longer exists - hence why nothing happened except an error message.
Removing the alias from the shell profile file corrected the problem.

clang-format not working under gVim

I installed clang-format-3.8 via apt-get.
Now I try to use it in gVim, but it is not working.
I checked and clang-format-3.8 exists in the folder /usr/share/vim/addons/syntax.
But when I enter :pyf /usr/share/vim/addons/syntax/clang-format-3.8.py in my vim command line, it returns:
E319: Sorry, the command is not available in this version.
I use gVim 7.4 under Ubuntu 16.04.
Dahn's answer is correct that the Vim binary that ships with Ubuntu 16.04 is compiled with Python 3 rather than Python 2. The clang-format-3.8.py script in the Ubuntu 16.04 clang-format-3.8 package is not compatible with Python 3.
But the latest clang-format.py does work with Python 3. You can get it here:
https://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/clang-format.py
I think it was just a matter of putting parentheses around the print statements.
Save this file somewhere on your computer such as /usr/local/share/vim/addons/syntax/.
This script uses clang-format as the binary name, so you'll want to install the clang-format package, which installs the clang-format command as a symlink to clang-format-3.8.
Since Vim is now loading a Python 3 script, replace your :pyf (not available) command with :py3f:
:py3f /usr/local/share/vim/addons/syntax/clang-format.py
The Vim binary shipped with Ubuntu 16.04 is compiled with Python 3. The vim addons of clang-format is written by Python 2.
You need to either:
write your own addon by Python 3
Compile your own vim with Python 2, which is the easiest way
The instructions to build vim with Python can be found by Google.
In addition to the above answers I had to do a few more things. I downloaded a new python file and changed the key mapping recommended by in the clang python file to the following in my .vimrc:
map <C-I> :py3file <path-to-this-file>/clang-format.py<cr>
imap <C-I> <c-o>:py3file <path-to-this-file>/clang-format.py<cr>
This solved the E319 problem I was getting.
I solved the problem differently using a combination of bash and vim commands.
First, I installed clang-format package
# apt-get install clang-format-3.5
(I choose version 3.5 but you can choose a different one)
Second, Test if clang-format is working
$ clang-format-3.5 -style=Google test.cpp
Then, run vim
$ vim test.cpp
vim allows to run an external command and print it's output into current buffer
:r ! clang-format-3.5 -style=Google %
(more details about external commands in vim https://www.linux.com/learn/vim-tips-working-external-commands)
This will append the output of clang-format into current buffer. To replace current buffer, which is the desirable effect, specify the lines to output into
:%! clang-format-3.5 -style=Google %
(the first % means all line in current file)
You can make this process more productive by defining new commands in vim (using command) for both visual and command-line modes.

Inspectdb in Oracle-Django gets OCI-22061: invalid format text [T

I'm using Oracle Database 10g xe universal Rel.10.2.0.1.0 against cx_Oracle-5.0.4-10g-unicode-py26-1.x86_64 on a django project on Ubuntu 10.04
My db is generated by Oracle 10gr2 enterprise edition (on Windows XP, import done in US7ASCII character set and AL16UTF16 NCHAR character set, import server uses AL32UTF8 character set, export client uses EL8MSWIN1253 character set)
When I try django-admin.py inspectdb I get the following error:
......."indexes = connection.introspection.get_indexes(cursor,
table_name) File
"/usr/lib/pymodules/python2.6/django/db/backends/oracle/introspection.py",
line 116, in get_indexes
for row in cursor.fetchall(): File "/usr/lib/pymodules/python2.6/django/db/backends/oracle/base.py", line
483, in fetchall
for r in self.cursor.fetchall()]) cx_Oracle.DatabaseError: OCI-22061: invalid format text [T".
I am aware of "inspectdb works with PostgreSQL, MySQL and SQLite" but as I understand from other posts it also works with Oracle somehow.
Does anyone know why I get this error or how I could fix it?
can you try it with updating cx_Oracle 5.1.1 package, then try this:
python manage.py inspectdb --database dbname
You can download cx_Oracle-5.1.2 and fix the issue using below command.
$ wget -c http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.1.2-11g-py27-1.x86_64.rpm
Command to install rpm
$ sudo yum install cx_Oracle-5.0.4-11g-unicode-py27-1.x86_64.rpm
Also download Oracle instantclient http://download.oracle.com/otn/linux/instantclient/11101/basic-11.1.0.6.0-linux-x86_64.zip and http://download.oracle.com/otn/linux/instantclient/11101/sdk-11.1.0.6.0-linux-x86_64.zip
Extract the above downloaded zip file.
copy the include folder from sdk-11.1.0.6.0-linux-x86_64 and paste in basic-11.1.0.6.0-linux-x86_64
Set the below path in .bashrc file
export $LD_LIBRARY_PATH = $LD_LIBRARY_PATH:/oracle_lib/oracle_instantclient_11_1
export $ORACLE_HOME = /oracle_lib/oracle_instantclient_11_1
$ ls /oracle_lib/oracle_instantclient_11_1
You should find the include folder with list of files
Then execute .bashrc file using $ source ~/.bashrc
I have tested it.