Showing posts with label VIM. Show all posts
Showing posts with label VIM. Show all posts

Apr 25, 2012

HOWTO: use pathogen to manage vim plugins

I am now using pathogen and GitHub to manage my vim plugins.
They are not difficult to use, but you need a few git commands to set it up, which I found very annoying.

To init .vim folder in Linux (or vimfiles for Windows), type:


mkdir .vim
cd .vim
git init
wget https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim -P ~/.vim/autoload
git add .
git commit -m 'initial commit'


To install each vim plugin, type: (here I use neocomplcache-snippets-complete as an example)


git submodule add https://github.com/Shougo/neocomplcache-snippets-complete.git bundle/neocomplacahe-snippets-complete
git add .gitmodules bundle/neocomplcache-snippets-complete
git submodule init



Jul 11, 2011

A Sleep function for VIM

I need to let VIM wait for cscope.exe to rebuild the tag file, but there are no build-in sleep function for VIM, so I made one here:

"a sleep function which allows vim to wait for the other processes to finish
com! -complete=command -nargs=+ Sleep call s:Sleep(<q-args>)
fun! s:Sleep(millisec)
  let ct = localtime()
  let dt = 0
  while dt < (a:millisec/1000)
    let dt = localtime() - ct
  endwhile
endfun

Just put it into your _vimrc.
To invoke it, type ":Sleep 10000" to let VIM wait for 10 secs.

Jun 17, 2010

SuperTab complete for neocomplcache

As I said in my previous post, neocomplcache is a very powerful vim plugin.
It incoporates the funtionality of SnipMate and  AutoComplPop while providing efficient search
for potential completion items.

However, SuperTab does not support neocomplcache. It is very bad since I like to tab complete
everything, including snippets. Here is the solution -- put the following in you .vimrc:

imap  <silent><expr><tab>  neocomplcache#sources#snippets_complete#expandable() ? "\<plug>(neocomplcache_snippets_expand)" : (pumvisible() ? "\<c-e>" : "\<tab>")
smap  <tab>  <right><plug>(neocomplcache_snippets_jump) 
inoremap <expr><c-e>     neocomplcache#complete_common_string()

The above setting allows you to trigger a snippet with "tab" key when possible. If not, it will simply trigger omni completion. I set it to complete the longest common string. It is just a personal taste. You can set it to other type of completion as well.

*Update 2010/12/11 for necomplcache V5.2 compatiblity
*Update 2012/04/24 for necomplcache V7 compatiblity

Mar 6, 2010

open files in new tabs of GVIM from command line

Name the following file gvim.bat
and put it into C:\Windows

@echo off
start gvim.exe -p --remote-tab-silent "%1"
echo on

Feb 17, 2010

Hacking SuperTab.vim

I have been unhappy about the longest common text of auto-complete provided by VIM for a long long time.
I try to find a good solution on the Internet, but all I got is
Put
completeopt += menuone,longest
in your .vimrc
It does provide a longest common text of auto-complete FOR THE FIRST TIME. After I type one more character and press <tab>, it just starts to move on the popup menu. No more longest common text of all matches anymore.
To work around this, I hacked the SuperTab to provide longest common text.
Here is how:

  1. open supertab.vim in your /plugin directory
  2. find function! s:SuperTab(command)
  3. change the code
    " handle 'context' completion.
    if b:complType == 'context'
      let complType = s:ContextCompletion()
      if complType == ''
        exec "let complType = \"" .
          \ escape(g:SuperTabContextDefaultCompletionType, '<') . "\""
      endif
        return complType . key
    endif

to
    " handle 'context' completion.
    if b:complType == 'context'
      let complType = s:ContextCompletion()
      if complType == ''
        exec "let complType = \"" .
          \ escape(g:SuperTabContextDefaultCompletionType, '<') . "\""
      endif
         if pumvisible()
             return "\<ESC>a" . complType . key
         else
            return complType . key
        endif

    endif

The idea is simple. Just close the popup menu each time users press <tab>, since VIM will do longest common text before the popup menu appears.

Feb 15, 2010

The plugin list of VIM

It's time to organize my VIM plugins

My VIM Plugin Lists

  1. SnipMate – provide TextMate like snippet. Use neocomplcache instead
  2. SuperTab – use tab to complete words or sentence  Use neocomplcache instead    Can be configured to use tab key to trigger the snippet and word complete at the same time. Very cool~~~
  3. FuzzyFinder – find files and functions in an instant 
  4. L9 – required for new version of FuzzyFinder
  5. EnhancedCommentify– comment and uncomment a piece of codes with single keystroke
  6. DoxygenToolkit – generate function comment
  7. a.vim – switch between .cpp and .h files
  8. visual_studio.vim – compile VS files in VIM Not compatible with VS2010, 
  9. omnicppcomplete – complete c++ files Use neocomplcache instead
  10. surround.vim – make hello_world to "hello_world" with few key strokes
  11. repeat.vim – make "surround" operation repeatable(with ".")
  12. vim-latex – latex syntax support
  13. matlab_run.vim – run matlab script in vim
  14. matlab plugin for vim – provide syntax highlighting and indention of matlab
  15. tlib – provides utilities for viki Use AsciiDoc instead
  16. viki – support viki ( a kind of wiki language ) Use AsciiDoc instead
  17. neocomplcache – it has been actively developed during recent months. It's mature enough.   It's interesting to see the author reply every blog which has questions about this plugin. It seems that the author really cares about his work.
  18. neocomplcache-snippets-complete – since neocomplcache V7, the snippets have been separated from neocomplcache. You need to download it individually. 
  19. delimitMate – parenthesis completion, very handy
  20. cscope_map – provide keyboard mapping for cscope

Required Software:

  1. Deplate – convert viki to html
  2. Python 2.4.4 – required by Visual_Studio.vim
  3. Ruby 1.86 – required by Deplate
  4. ctags – required for omni-complete 
  5. cscope 15.7 – a better ctags for python. The zip file contains windows binary.
  6. Python for Windows Extension – required by Visual_Studio.vim

Abandoned plugins:

  1. taglist – use FuzzyFinder instead
  2. project – use FuzzyFinder instead
  3. RltvNmbr – too slow included in VIM 7.3
  4. snippetsEmu – too old, use SnipMate instead
  5. neocomplcache – too new. It is a combination of omnicppcomplete, SnipMate, AutoComplPop and SuperTab. It doesn't not work properly if you set the same trigger key to complete and snippet. However, it supports nested snippet and longest common string complete. Very promising.

Plugins needs modified:

  1. visual_studio.vim
    1. needs to update error message format for visual studio 2008 to work (I set it to set errorformat= %#%f(%l) : %#%t%[A-z]%# %m )
    2. needs to change key binding to avoid conflicts with viki.vim ( I changed them from vc to ic)
  2. SnipMate.vim
    1. needs to update snippets (of course) 
*Update 2010/12/11 for Vim 7.3
*Update 2011/03/10 for delimitMate  
*Update 2011/07/11 for cscope 
*Update 2012/04/24 for neocomplcache 

Add VIM to the right-click menu

The default VIM 7.2 right-click menu will open the new file in the current buffer.
It's quite annoying because I want to open the new file in a new tab most of the time.

To solve the problem, just import the following setting to the windows registery


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Edit with &Vim\command]
@="\"c:\\Program Files\\Vim\\vim72\\gvim.exe\" -p --remote-tab-silent \"%1\""

Jan 28, 2010

VIM useful commands

gw exchange two words
CTRL-X CTRL-L complete line
CTRL-X CTRL-F complete file
CTRL-X CTRL-P complete word, useful when you use snippet and still want to have omni-complete
tab complete word
\s substitude the current word
\S substitude with question
ALT-O open file with the same name
\F find in all files
\g find file
\f find tag
,r run matlab script
,o open matlab
:make check matlab syntax

\ll compile latex
\lv view latex

Jun 28, 2009

VIM Color Theme (Ayende)



Oren Eini made a great color theme for Visual Studio. I ported it to VIM. You can get it here


Here is a list of my previous VIM themes:
1. AF.vim


2.VividChalk.vim (it's specialized for Ruby)

Jun 27, 2009

Use Consolas font in Japanese VIM

Consolas is a font which is specialized to display source codes.
To use the font in Japanese VIM, add the following line in .vimrc

set guifont=Consolas:h11:cSHIFTJIS


Then import the following into your registry and reboot.


Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink]
"Consolas"=hex(7):4d,00,49,00,4e,00,47,00,4c,00,49,00,55,00,2e,00,54,00,54,00,\
43,00,2c,00,4d,00,69,00,6e,00,67,00,4c,00,69,00,55,00,00,00,53,00,49,00,4d,\
00,53,00,55,00,4e,00,2e,00,54,00,54,00,43,00,2c,00,53,00,69,00,6d,00,53,00,\
75,00,6e,00,00,00,42,00,41,00,54,00,41,00,4e,00,47,00,2e,00,54,00,54,00,43,\
00,2c,00,42,00,61,00,74,00,61,00,6e,00,67,00,00,00,00,00


Since Consolas supports English only. It's necessary to tell system how to display the words in other Languages or all Japanese words cannot be display normally.
The above registry setting assign
"MINGLIU.TTC,MingLiU
SIMSUN.TTC,SimSun
BATANG.TTC,Batang" to Consolas font to display both Japanese and Chinese words.

The result is here:



To get into the nutshell, see how font linking works

Jun 20, 2009

The VIM Settings to replace Visual Studio 2008

Just start to shift from Visual Sudio 2008 to VIM. I heard that keyboards can bring a lot of fun to programming, but I cannot live without Visual Studio 2008. There are too many great features of it, like completion, source code browsing, etc. All I need to do now is to being these features into VIM. (Why does no one make a power pack of VIM to beat Visual Studio?)
1. SnipMate
Provide a Textmate-like snippet functionality. It's a better substitude of snippetsEmu. However, snippetsEmu has more snippets. Perhaps I should port them to SnipMate, hmm...

2. SuperTab
3. FuzzyFinder
4. CTAGs
5. EnhancedCommentify
6. DoxygenToolkit
7. a.vim
8. visual_Studio.vim

Used plugins:
1. taglist
2. project
3. RltvNmbr

Jun 17, 2009

Abandon Textmate...Now!!!

Textmate hasn't release any new versions for several years. I don't think a software does have a future if it's not actively supported. Therefore, I decided to switch to the old good VIM. Perhaps I could master VIM this time.

*Update 2011/11/15: There will be Textmate 2 alpha release around Christmas.  After 2 years, it doesn't matter anymore. VIM FTW!

Feb 5, 2009

VIM

I am trying to adapt VIM in recent days. Still fill painful, though.

Here is my plugin list:
a.vim
include_complete.vim
supertab.vim
omnicppcomplete.vim
taglist.vim
visualmark.vim

 
TEMPLATE HACKS AND TWEAKS BY [ METAMUSE ] BLACKCAT 1.1
/scripts/shBrushJScript.js'/>