用于服务器端编辑的Vimconfiguration

我总是在我们的服务器上使用Vim(大部分是基于Ubuntu的),而且我总是缺乏一个适合vim而不需要太多装饰的好configuration。

我想尽可能地为那些在服务器上直接写入bash,zsh和ruby代码的人收集configuration设置。

我最近学到的最好的东西是使用jj而不是<esc>进入正常模式:

 imap jj <Esc> 

另外,如果你通过splitvsplit )或者vsplit (wide terminal)命令使用split,那么重新映射switch-split命令是非常有用的。 我用(逗号)切换我的分裂:

 map , <Cw><Cw> 

在Stack Overflow上查看关于vim的最重要的问题 。

基本上我使用的每个系统都使用以下内容。 尽pipe如此,我还是没有做太多的努力来修改它。 我使用vim作为一个configuration编辑工具,在大量的服务器上,但是我现在不倾向于在vim中进行大量的开发

 set modeline set background=dark set autowrite nmap <tab> :bn<cr> nmap <s-tab> :bp<cr> 

nmap选项允许我使用tab和shift-tab在多个打开的缓冲区之间切换,这对我来说非常宝贵。

检查dakrone的点文件中的.vimrc.vim

以下是我主要关注perl,mason和javascript IDE函数的.vimrc,但是您可以调整您在这里看到的有关ruby / sh的细节。 在SSH上使用了好几年了。 在IDE环境之外,自动备份不止一次地保存了我的屁股。

 " Embedded() is a function that will parse a text buffer " looking for embedded vim commands, and execute them. " Call it with a range of lines to check, eg to check the whole " file: " " :%call Embedded() " " Commands should be prefixed by the sequence :vim: . " function Embedded() range let n = a:firstline while n <= a:lastline let l = getline(n) let p = stridx(l,':vim:') if p > -1 let p = p + 5 let c = strpart(l,p) execute c endif let n = n + 1 endwhile endfunction " call Embedded() whenever a file is loaded and " parse the entire file. You may not want to do " this for *; maybe just your src tree or certain " file types or something. autocmd BufWinEnter * %call Embedded() " Create nested folds on custom expressions, based " on the current buffer's filetype or syntax. " let g:foldlevel = 0 let g:foldstartexpr = '' let g:foldendexpr = '' function GetCustomFold() if getline(v:lnum) =~ g:foldstartexpr let g:foldlevel = g:foldlevel + 1 return ">".g:foldlevel elseif getline(v:lnum) =~ g:foldendexpr let thislevel = g:foldlevel let g:foldlevel = g:foldlevel - 1 return "<".thislevel else return g:foldlevel endif endfunction function SetFoldType() let f = &filetype ? &filetype : &syntax if f == 'mason' let g:foldstartexpr = '^\s*<\(script\|style\|%init\|%attr\|%once\|%args\|%flags\|%shared\|%def\)[^>]*>\s*$' let g:foldendexpr = '^\s*</\(script\|style\|%init\|%attr\|%once\|%args\|%flags\|%shared\|%def\)[^>]*>\s*$' elseif f == 'perl' let g:foldstartexpr = '^sub.*{\s*$' let g:foldendexpr = '^}\s*$' elseif f == 'javascript' let g:foldstartexpr = '^function.*{\s*$' let g:foldendexpr = '^}\s*$' else return endif setlocal foldexpr=GetCustomFold() setlocal foldmethod=expr endfunction autocmd BufWinEnter * %call SetFoldType() function SetPerlIDE() " check perl code with :make setlocal makeprg=perl\ -c\ %\ $* setlocal errorformat=%f:%l:%m setlocal autowrite " comment/uncomment blocks of code (in vmode) map ^C :s/^/#/gi<Enter> map ^X :s/^#//gi<Enter> " my perl includes pod let perl_include_pod = 1 " syntax color complex things like @{${"foo"}} let perl_extended_vars = 1 " Tidy selected lines (or entire file) with _t: nnoremap <silent> _t :%!perltidy -q<Enter> vnoremap <silent> _t :!perltidy -q<Enter> " perlcritic selected lines (or entire file) with _p: nnoremap <silent> _p :%!perlcritic -q<Enter> vnoremap <silent> _p :!perlcritic -q<Enter> endfunction autocmd FileType perl call SetPerlIDE() " map II :r ~/.vim/template.pod<CR> set tabstop=4 set number set showmatch set ruler set backup set backupdir=~/.vim/backups set directory=~/.vim/backups set tags=~/.vim/tags set backupskip=/tmp/*,/private/tmp/*" " we get colors, we get lots and lots of colors syntax on set bg=dark colors darkblue 

如果你使用vim的话,你可能会喜欢它

步骤1:从vim.org下载最新版本的插件

从vim.org下载插件

$ cd / usr / src $ wget -O mru.vim http://www.vim.org/scripts/download_script.php?src_id=9274

第2步:安装MRU vim插件

$ mkdir〜/ .vim#如果目录不存在$ cd〜/ .vim / plugin / $ cp /usr/src/mru.vim。

7 MRU.vim的强大function

安装这个插件后,每当你打开一个文件读取或写入它将被添加到MRU列表。 1.在Vi / Vim编辑器中查看最近使用的文件

:MRU

注意::MRU(大写)工作。 :mru(小写)不起作用。

:如下图所示,MRU将显示最近使用的“最新使用”文件。 要打开文件,请按ENTER键,同时在该文件名的光标处。 图:显示“最近文档”列表的Vim编辑器

图:显示“最近文档”列表的Vim编辑器

注意:在安装MRU插件后,您可能不会在MRU列表中看到任何文件。 使用Vim编辑器在安装插件后打开几个文件,以便MRU列表增长。 2.如何增加MRU列表数量? (增加存储的文件数量)

默认情况下,MRU列表只存储最近使用过的10个文件。 将下面的行添加到〜/ .vimrc中,以增加此限制,如下所示。

$ cat〜/ .vimrc let MRU_Max_Entries = 20

  1. 如何searchMRU列表中的文件

当增加文件数量时,可能难以滚动浏览MRU列表来select要查找的文件。 相反,您可以使用普通的Vim命令在MRU列表中进行search。 所以你可以给(斜线)/并给出一个模式来search。

在下面的例子中,MRU列表非常长。 我做了一个“/ yum”,它将光标自动移动到/etc/yum.conf MRU条目中。 按回车,将打开这个文件。 图:searchMRU列表使用/

图:searchMRU列表使用/

您也可以使用MRUsearchfunction,如下所述。

 * Enter the partial file name and press TAB which will fill the file name, which you can open by pressing enter, * Enter one or two characters of the file name or the path name, and press tabs to rotate around the file names. 
  1. 在新选项卡中打开MRU列表中的文件

按下MRU条目上的input将默认在同一个窗口中打开文件。 如果在当前窗口中打开的文件尚未保存,它将在新窗口中打开。

 * To open the file from the MRU entry in a new Tab , press 't' when the cursor is on a file name in MRU window. * :tabn will take you to the next tab * :tabp will take you to the previous tab 
  1. 更新MRU窗口

要更新当前的MRU窗口,请按'u'。 当打开MRU窗口时,将始终打开新的内容。 6.使用MRU_Exclude_Files排除某些文件

要排除MRU中显示的某些文件,可以将正则expression式存储在MRU_Exclude_Filesvariables中,如下所示:

$ cat〜/ .vimrc let MRU_Exclude_Files ='^ / tmp /。 \ | ^ / var / tmp中/。 '“对于Unix

上面的内容将排除/ tmp和/ var / tmp被存储在MRU中。 7.使用MRU_Include_Files包含某些文件

要仅包含MRU中的某些types的文件,可以将正则expression式存储在MRU_Include_Filesvariables中,如下所示。 这将只包含在/ home / ramesh中的文件存储在MRU中。

$ cat〜/ .vimrc let MRU_Include_Files ='^ / home / rajat /.*'