码迷,mamicode.com
首页 > 其他好文 > 详细

Building Remote+Local *nix Develop Environment(II)

时间:2014-12-20 13:01:16      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:

This is the second article(collection) on how to build a *nix development environment by integrating remote servers and local Linux/Mac clients. For the previous article on this topic, please refer to Building Remote+Local *nix Develop Environment.

1. Vim Tips & Plugins

1.1 Highlight All Instances of Word Under Cursor

Add following line into your $HOME/.vimrc

  1. autocmd CursorMoved * exe printf(‘match IncSearch /\V\<%s\>/‘, escape(expand(‘<cword>‘), ‘/\‘))

Or use a more complicated one in the .vimrc:

  1. " Highlight all instances of word under cursor, when idle.
  2. " Useful when studying strange source code.
  3. " Type z/ to toggle highlighting on/off.
  4. nnoremap z/ :if AutoHighlightToggle()<Bar>set hls<Bar>endif<CR>
  5. function! AutoHighlightToggle()
  6. let @/ = ‘‘
  7. if exists(‘#auto_highlight‘)
  8. au! auto_highlight
  9. augroup! auto_highlight
  10. setl updatetime=4000
  11. echo ‘Highlight current word: off‘
  12. return 0
  13. else
  14. augroup auto_highlight
  15. au!
  16. au CursorHold * let @/ = ‘\V\<‘.escape(expand(‘<cword>‘), ‘\‘).‘\>‘
  17. augroup end
  18. setl updatetime=500
  19. echo ‘Highlight current word: ON‘
  20. return 1
  21. endif
  22. endfunction

1.2 Automatically Load Ctags

If you have generated ctags file, then you can automatically load it by:

  • export CTAGS_TAG in $HOME/.bashrc by export CTAGS_TAG=/path/to/your/tags.

  • add following lines into your $HOME/.vimrc

```Shell

  1. if filereadable($CTAGS_TAG)
  2. set tags=$CTAGS_TAG
  3. endif

```

1.3 Most Recently Used(MRU) Files

If you want to access the most recently used files in Vim, you need plugin MRU. The :MRU command will show you all the recently used files, and you can choose a file and press <Enter> to open it in current window. In addition

  • To open a file from the MRU window in a new tab, press the t key.
  • You can open multiple files from the MRU window by specifying a count before pressing <Enter> or v or o or t.
  • You can close the MRU window by pressing the q key or the <Esc> key or using one of the Vim window commands.
  • You can specify a pattern to the :MRU command, such as :MRU <pattern>.

1.4 Pathogen

Vim runtimepath manager, widely used by many plugins. Adding call pathogen#infect() to your .vimrc, then any plugins you wish to install can be extracted to a subdirectory under ~/.vim/bundle. And they will be added to the runtimepath.

1.5 NERDTree & NERDTree Tabs

The NERD tree allows you to explore your filesystem and to open files and directories, and NERDTree Tabs can make NERDTree available for all Vim tabs(sometimes it is useful). After installing the these plugins, you can add the following lines to .vimrc.

  1. " Nerd Tree
  2. " let g:NERDTreeDirArrows=0 " Do not use new arrows for directories
  3. map <C-n> :NERDTreeToggle<CR>
  4. let g:nerdtree_tabs_open_on_gui_startup=0 " no nerdtree_tabs by default

For some Linux distributions, the NERDTree could not show arrows for directories, then you need to uncomment the line let g:NERDTreeDirArrows=0 in your .vimrc.

1.6 Supertab

Supertab is a vim plugin which allows you to use <Tab> for all your insert completion needs (:help ins-completion).

1.7 CtrlP & Command-T

These two plugins are used for searching/opening files(even not in ctags) in Vim. CtrlP is written in pure Vimscript, so it is very slow. Although Command-T is faster, it relies on Ruby, which makes it difficult to install. Actually, I rarely use them in daily work.

My vimrc can be found at https://github.com/bo-yang/misc/blob/master/vimrc.

2. Cscope

Cscope is a tool for browsing source code. You can either run cscope standalone or use it with Vim. No matter in which way, you need to generate cscope database first. And the cscope DB depends on the source files you specified. General steps of using cscope are:

  1. find /my/project/dir -name ‘*.c‘ -o -name ‘*.h‘ > /foo/cscope.files
  2. cd /foo
  3. cscope -b
  4. CSCOPE_DB=/foo/cscope.out; export CSCOPE_DB

In Vim, you can load cscope DB by command :cs add <path_to_cscope_db>. For more cscope operations in Vim, please run command :cs help. To automatically load cscope into Vim, you can export CSCOPE_DB in $HOME/.bashrc, such as

  1. export CSCOPE_DB=/path/to/cscope.out

Then the CSCOPE_DB will be automatically loaded every time you run Vim.

To save the effort of building cscope DB, I wrote a cross-platform(Linux & Mac OS X) wrapper script, which can be found in my GitHub channel.

3. sshfs Wrapper

Since sshfs command requires too much parameters, and things will be worse when the network is not stable. Following script will ease your pain.

  1. #!/bin/sh
  2. USER=<your_name>
  3. SERVER=<your_server>
  4. remote_dir=/nobackup/$USER
  5. local_dir=$HOME/Documents/VMs
  6. if [ ! -d ${local_dir} -o ! -s ${local_dir} ]
  7. then
  8. sudo umount -f $local_dir
  9. fi
  10. cd ${local_dir}
  11. sshfs $USER@${SERVER}:${remote_dir} ${local_dir}

- See more at: http://www.bo-yang.net/2014/12/19/remote-local-linux-develop-env-2/#sthash.7IdS3E6c.dpuf

Building Remote+Local *nix Develop Environment(II)

标签:

原文地址:http://blog.csdn.net/bonny95/article/details/42041701

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!