Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Friday, November 07, 2014

Two copies of clang_complete makes vim throw error messages

Recently I found there was error messages when I open C/C++ files in Vim (see the following photo).


So I googled, and installed so-called libclang-dev. After the installation, the error message became more terrible:


XDD

Fortunately, I spotted a thread of clang_complete in GitHub, and the author's comment was the solution for me.


I must had installed the clang_complete manually and then it has been installed again by Vundle. :-p

---
Other useful link found during the search:
clang_complete can be configured to use the clang executable or the clang library

Sunday, November 02, 2014

Some settings to enable the vim-airline

I've tried to add some plugins to make Vim a better IDE. The article has helped me alot: vim + packet manager = Vundle

Just several minutes ago, I added the vim-airline and did something to make it work in my vim (not gvim).

After some tests, the only thing I have to do was to add the following line in my .vimrc to enable 256 colors in vim:
set t_Co=256
Another useful setting was
set laststatus=2
which lets the vim-airline show the status bar even there's only one file opened.

If you want to replace the symbols with some Unicode ones, then the so-called patch fonts are needed. They can be found in https://github.com/Lokaltog/powerline-fonts.

After installing the patched fonts, you can add the following settings in the .vimrc to enable the symbols:

if !exists('g:airline_symbols')
    let g:airline_symbols = {}
endif

" unicode symbols
let g:airline_left_sep = '»'
let g:airline_left_sep = '▶'
let g:airline_right_sep = '«'
let g:airline_right_sep = '◀'
let g:airline_symbols.linenr = '␊'
let g:airline_symbols.linenr = '␤'
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.branch = '⎇'
let g:airline_symbols.paste = 'ρ'
let g:airline_symbols.paste = 'Þ'
let g:airline_symbols.paste = '∥'
let g:airline_symbols.whitespace = 'Ξ'

set guifont=DejaVu\ Sans\ Mono\ 10
let g:airline_powerline_fonts = 1

Here's my vim with the vim-airline:




Wednesday, April 24, 2013

Some notes on find and replace using Vim, rename, and perl in command line...


Using rename in bash script

As mentioned in the previous post [1], I need to replace dots to other tokens in the filenames of a bunch of eps figures. The following script was used to do the work [2]:

#!/bin/sh
for f in $(find . -name "*.eps" -type f)
do
    echo "found: "$f
    # option -n is useful to preview the renamed results:
    rename -v 's/(\d+)\.(\d+)\.(\d+)/$1-$2-$3/' $f
done

In this case, I learned how to keep some parts of the old string and to replace other parts. The key concept was to use parentheses to group the parts we want to keep and then use $n to indicate the nth group in substitution expression. Use ``91.1.8.eps'' as the example:
  • \d stands for digits
  • \d+ means at least ONE digit
  • (\d+) hold the parts which are respectively 91, 1, and 8 in this example
  • $1 corresponds to the first group which is 91
  • $2 corresponds to the second group which is 1
  • $3 corresponds to the third group which is 8
Therefore, the dots between the digits will be replaced by dashes.

Substitution in Vim

After renaming all the eps files, I had another more complicated problem. All the corresponding filename strings resided in the tex files also had to be changed! At the beginning I edited one of the tex file in Vim and played with the substitution command in it. The final command I used was [3][4]:

:%s/\(\d*\)\.\(\d*\)\.\(\d*\)/\1-\2-\3/gc

Note that there are some minor differences when writing the expressions. Some of the modifications, e.g. the escaping backslash, were due to the difference between BRE and ERE [5].

Find and Replace in multiple files


Although I could do the find and replace works in Vim, it was not a good idea when there were maybe hundreds of such files. To write a bash script was my first thought and with information found on the internet [6][7][8] I got a usable script as the follows:

#!/bin/sh
for f in $(find . -name "*.tex" -type f)
do
    echo "found: "$f
    perl -p -i -e 's/(\d+)\.(\d+)\.(\d+)/$1-$2-$3/' $f
done

---
[1] XeTeX -- using dots in eps filenames would cause errors
[2] batch renaming with the rename command

[3] Vim Regular Expressions 101: Grouping and Backreferences
[4] Search/Replace in Vim

[5] Basic Regular Expressions and Extended Regular Expressions
[6] Eeasy Search and Replace in Multiple Files on Linux Command Line
[7] bash find directories
[8] Find file or directory in whole directory structure



Saturday, March 03, 2012

Set Vim in Windows to work with Unicode

My Windows has been installed and set for traditional Chinese environment and occasionally it makes some trouble when I need text files encoded in Unicode instead of Big5.

I've started to write some personal working logs in Markdown syntax with Vim. It's simple and quick. But when I tried to compile the plain text into HTML file, the Chinese characters introduced trouble for the Python implementation of Markdown. The error message was something like:
UnicodeDecodeError: 'utf8' codec can't decode byte
To prevent this kind of error, I thought the best approach was to make Vim work with Unicode in my Windows. The settings were added in C:\Program Files\Vim\_vimrc and they are as follows:

set fileencoding=utf8
set fileencodings=ucs-bom,utf-8,default,latin1

The first line tells Vim to save the text in utf8 and the second line gives Vim to open and convert the files in the given order of encoding.

Friday, October 01, 2010

[QnA] Change the permission of viminfo to enable the command histroy of Vim

After upgrading from Ubuntu 8.04 to 10.04, I found the command history of Vim was missing. The reason is simple: in Ubuntu 10.04, the ~/.viminfo file has a 600 permission so only the root can access it.

To get the command history of vim back, you may change the permission from 600 to 666. I don't know whether this change has any side effects, however. At least for only one user using one computer, this is a quick trick. :-)

---
Ref:

Thursday, November 12, 2009

[SW] Big5 and utf-8 in Vim

To make Vim open big5 files properly, just set the following
set fileencodings=utf-8,big5,euc-jp,gbk,euc-kr,utf-bom,iso8859-1
set encoding=utf8
set tenc=utf8
---
Ref: http://wiki.debian.org.tw/index.php/Unicode#VIM

Monday, October 26, 2009

[SW] Learning Lsip using Vim as the editor

I prefer Vim over Emacs. One day, I happened to be curious about Lisp, and then found the page ``Practical Common Lisp.'' The so-called ``programming environment'' confused me. Furthermore, Emacs seems to be the standard (or mainstream) editor/environment for the Lisp programming.

I've set the Emacs and SLIME for a try, but it's not easy for me to remember the key stroking in Emacs. So I also found some approaches to let me learning Lisp with my beloved Vim.

The first approach I found was: slime.vim, but I do neither understand the script nor the steps. After trying and trying, I gave it up.

The second approach is to install the Limp, a plugin for Vim. It does not work identically to what has shown on the web page, but it seems not bad and simple enough for me.

---
(Maybe my problems are due to my poor understanding of how Lisp works.)

Sunday, October 25, 2009

[SW] Taglist -- a Vim plugin for browsing the source code

To make Vim handier for programming, the taglist is a good choice. It works with Exuberant Ctags to make you browse the variables, functions, or classes of the source code easily.

Just make sure you have installed Exuberant Ctags:
$ sudo apt-get install exuberant-ctags

It's a good idea to set hot-key to toggle the TlistToggle function (use <F12> as the example):
nnoremap :TlistToggle
nnoremap <F12> :TlistToggle <CR>

[SW] Vimperator -- Let you use Firefox as in Vim

I read the article and it mentioned Vimperator, an add-on for Firefox. You would like it if you are a Vim fan. :-)

Saturday, September 05, 2009

[Chat] Sponsoring Vim

I have used Vim for many of my works, and it has gave me really good experience in editing or coding. Therefore, I decided to help the development of Vim: donate some money.

Thanks to the service like PayPal, which makes the sponsoring easier and quicker. I can only give a few money, though. I am happy to receive the reply from Vim:

Thank you very much for registering Vim! Your contribution will
motivate me to spend more time on improving Vim. The money will be used
to help needy children in Kibaale, Uganda.

Thursday, August 13, 2009

[SW] Regexp substitution in VIM

Vim is my favorite text editor. I use vim for editing plain text or programming. It has many features which I've not been familiar with, and the substitution with regexp is on of them.

I had a little problem in one of my script file, which has been used to chop some data files into shorter segments for further usage. When editing the script, I need to delete some parts which are in the form of ``some digits, some digits''.

For example, I need to delete ``90,185'' or ``1455,2010'' in the script for composing a newer one. Because the digits have different length, my original substituting pattern ``[0-9],[0-9]'' didn't work. I had tried many different regexp patterns as I've known, but no one match my requirement. Then, I think I have to add some more knowledge about the regexp used in vim to improve my skill as well as the work efficiency, so I went to the help of Google and find the following website: Vim Regular Expressions 101.

Finally, I found what I needed. Some quantifiers can be used to set how many times certain part of the pattern should repeat. So my working pattern of regexp become ``[0-9]\+,[0-9]\+''. Learnt something new again. :-)