你的 .vimrc 中有什么? [关闭]

2024-01-08

Vi 和 Vim 允许真正出色的定制,通常存储在.vimrc文件。程序员的典型功能是语法突出显示、智能缩进等。

你还有哪些隐藏在 .vimrc 中的高效编程技巧?

我最感兴趣的是重构、自动类和类似的生产力宏,尤其是 C#。


你自找的 :-)

"{{{Auto Commands

" Automatically cd into the directory that the file is in
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')

" Remove any trailing whitespace that is in the file
autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif

" Restore cursor position to where it was before
augroup JumpCursorOnEdit
   au!
   autocmd BufReadPost *
            \ if expand("<afile>:p:h") !=? $TEMP |
            \   if line("'\"") > 1 && line("'\"") <= line("$") |
            \     let JumpCursorOnEdit_foo = line("'\"") |
            \     let b:doopenfold = 1 |
            \     if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
            \        let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
            \        let b:doopenfold = 2 |
            \     endif |
            \     exe JumpCursorOnEdit_foo |
            \   endif |
            \ endif
   " Need to postpone using "zv" until after reading the modelines.
   autocmd BufWinEnter *
            \ if exists("b:doopenfold") |
            \   exe "normal zv" |
            \   if(b:doopenfold > 1) |
            \       exe  "+".1 |
            \   endif |
            \   unlet b:doopenfold |
            \ endif
augroup END

"}}}

"{{{Misc Settings

" Necesary  for lots of cool vim things
set nocompatible

" This shows what you are typing as a command.  I love this!
set showcmd

" Folding Stuffs
set foldmethod=marker

" Needed for Syntax Highlighting and stuff
filetype on
filetype plugin on
syntax enable
set grepprg=grep\ -nH\ $*

" Who doesn't like autoindent?
set autoindent

" Spaces are better than a tab character
set expandtab
set smarttab

" Who wants an 8 character tab?  Not me!
set shiftwidth=3
set softtabstop=3

" Use english for spellchecking, but don't spellcheck by default
if version >= 700
   set spl=en spell
   set nospell
endif

" Real men use gcc
"compiler gcc

" Cool tab completion stuff
set wildmenu
set wildmode=list:longest,full

" Enable mouse support in console
set mouse=a

" Got backspace?
set backspace=2

" Line Numbers PWN!
set number

" Ignoring case is a fun trick
set ignorecase

" And so is Artificial Intellegence!
set smartcase

" This is totally awesome - remap jj to escape in insert mode.  You'll never type jj anyway, so it's great!
inoremap jj <Esc>

nnoremap JJJJ <Nop>

" Incremental searching is sexy
set incsearch

" Highlight things that we find with the search
set hlsearch

" Since I use linux, I want this
let g:clipbrdDefaultReg = '+'

" When I close a tab, remove the buffer
set nohidden

" Set off the other paren
highlight MatchParen ctermbg=4
" }}}

"{{{Look and Feel

" Favorite Color Scheme
if has("gui_running")
   colorscheme inkpot
   " Remove Toolbar
   set guioptions-=T
   "Terminus is AWESOME
   set guifont=Terminus\ 9
else
   colorscheme metacosm
endif

"Status line gnarliness
set laststatus=2
set statusline=%F%m%r%h%w\ (%{&ff}){%Y}\ [%l,%v][%p%%]

" }}}

"{{{ Functions

"{{{ Open URL in browser

function! Browser ()
   let line = getline (".")
   let line = matchstr (line, "http[^   ]*")
   exec "!konqueror ".line
endfunction

"}}}

"{{{Theme Rotating
let themeindex=0
function! RotateColorTheme()
   let y = -1
   while y == -1
      let colorstring = "inkpot#ron#blue#elflord#evening#koehler#murphy#pablo#desert#torte#"
      let x = match( colorstring, "#", g:themeindex )
      let y = match( colorstring, "#", x + 1 )
      let g:themeindex = x + 1
      if y == -1
         let g:themeindex = 0
      else
         let themestring = strpart(colorstring, x + 1, y - x - 1)
         return ":colorscheme ".themestring
      endif
   endwhile
endfunction
" }}}

"{{{ Paste Toggle
let paste_mode = 0 " 0 = normal, 1 = paste

func! Paste_on_off()
   if g:paste_mode == 0
      set paste
      let g:paste_mode = 1
   else
      set nopaste
      let g:paste_mode = 0
   endif
   return
endfunc
"}}}

"{{{ Todo List Mode

function! TodoListMode()
   e ~/.todo.otl
   Calendar
   wincmd l
   set foldlevel=1
   tabnew ~/.notes.txt
   tabfirst
   " or 'norm! zMzr'
endfunction

"}}}

"}}}

"{{{ Mappings

" Open Url on this line with the browser \w
map <Leader>w :call Browser ()<CR>

" Open the Project Plugin <F2>
nnoremap <silent> <F2> :Project<CR>

" Open the Project Plugin
nnoremap <silent> <Leader>pal  :Project .vimproject<CR>

" TODO Mode
nnoremap <silent> <Leader>todo :execute TodoListMode()<CR>

" Open the TagList Plugin <F3>
nnoremap <silent> <F3> :Tlist<CR>

" Next Tab
nnoremap <silent> <C-Right> :tabnext<CR>

" Previous Tab
nnoremap <silent> <C-Left> :tabprevious<CR>

" New Tab
nnoremap <silent> <C-t> :tabnew<CR>

" Rotate Color Scheme <F8>
nnoremap <silent> <F8> :execute RotateColorTheme()<CR>

" DOS is for fools.
nnoremap <silent> <F9> :%s/$//g<CR>:%s// /g<CR>

" Paste Mode!  Dang! <F10>
nnoremap <silent> <F10> :call Paste_on_off()<CR>
set pastetoggle=<F10>

" Edit vimrc \ev
nnoremap <silent> <Leader>ev :tabnew<CR>:e ~/.vimrc<CR>

" Edit gvimrc \gv
nnoremap <silent> <Leader>gv :tabnew<CR>:e ~/.gvimrc<CR>

" Up and down are more logical with g..
nnoremap <silent> k gk
nnoremap <silent> j gj
inoremap <silent> <Up> <Esc>gka
inoremap <silent> <Down> <Esc>gja

" Good call Benjie (r for i)
nnoremap <silent> <Home> i <Esc>r
nnoremap <silent> <End> a <Esc>r

" Create Blank Newlines and stay in Normal mode
nnoremap <silent> zj o<Esc>
nnoremap <silent> zk O<Esc>

" Space will toggle folds!
nnoremap <space> za

" Search mappings: These will make it so that going to the next one in a
" search will center on the line it's found in.
map N Nzz
map n nzz

" Testing
set completeopt=longest,menuone,preview

inoremap <expr> <cr> pumvisible() ? "\<c-y>" : "\<c-g>u\<cr>"
inoremap <expr> <c-n> pumvisible() ? "\<lt>c-n>" : "\<lt>c-n>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\<lt>cr>"
inoremap <expr> <m-;> pumvisible() ? "\<lt>c-n>" : "\<lt>c-x>\<lt>c-o>\<lt>c-n>\<lt>c-p>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\<lt>cr>"

" Swap ; and :  Convenient.
nnoremap ; :
nnoremap : ;

" Fix email paragraphs
nnoremap <leader>par :%s/^>$//<CR>

"ly$O#{{{ "lpjjj_%A#}}}jjzajj

"}}}

"{{{Taglist configuration
let Tlist_Use_Right_Window = 1
let Tlist_Enable_Fold_Column = 0
let Tlist_Exit_OnlyWindow = 1
let Tlist_Use_SingleClick = 1
let Tlist_Inc_Winwidth = 0
"}}}

let g:rct_completion_use_fri = 1
"let g:Tex_DefaultTargetFormat = "pdf"
let g:Tex_ViewRule_pdf = "kpdf"

filetype plugin indent on
syntax on
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

你的 .vimrc 中有什么? [关闭] 的相关文章

  • 如何在 Vimscript 中调用普通模式的递增和递减命令?

    我正在尝试创建一个 Vimscript 函数 该函数随机递增 ro 递减光标下的数字 以便我可以从宏中调用它 到目前为止 我已经得到了这个 function RandomIncDec python import random python
  • 在没有 Resharper 的情况下删除 C# 项目中未使用的引用 (!= usings)?

    有没有办法在 C 项目中删除未使用的程序集引用 而不需要 Resharper 的帮助 这MSDN 文档确实概述了 Visual Basic 的一些内容 http msdn microsoft com en us library 7sfxaf
  • Python:如何重构循环导入

    我有件事可以帮你做engine setState
  • git commit 保存 vim 文件时出错

    我正在遵循简单的 git 指南nettuts 简易 git 指南 http net tutsplus com tutorials other easy version control with git 我在我的中初始化了一个空的 git 实
  • 如何在存储过程中查找数据表列引用

    我更改了 SQL Server 2005 数据库表中的列名称 我还有一个相当大的存储过程集合 它们可能引用也可能不引用该列 有没有办法找到哪些存储过程引用该列 而无需实际遍历每个存储过程并手动搜索它 有没有办法自动查找哪些存储过程现在会中断
  • vim 使用外部文件上的行号突出显示行

    我有两个文本文件 一个是我当前正在工作的文件 另一个包含行号列表 我想做的是突出显示第一个文件中行号与后一个文件匹配的行 E g File1 I like eggs I like meat I don t like eggplant My
  • Windows 上 gnu make 的 libintl3 和 libiconv2 在哪里,需要在 MinGW 上用 ruby​​ 编译 vim

    我正在尝试为 Windows 运行 gnu make 但它无法运行 因为libint3 dll没找到 果然 http gnuwin32 sourceforge net packages make htm http gnuwin32 sour
  • 通过列表字符仅显示前导空格的“空格”字符

    Vim 中是否可以有我的编辑器 编辑时 c and h文件 显示通过listchars 一个特殊字符 仅用于leading空格字符 我发现一个单独的帖子指出 从版本 7 4 开始 Vim 现在支持通过以下方式突出显示所有空格字符listch
  • 如何中断一个花费太多时间的 Vim 命令?

    有时 Vim 命令需要花费太多时间来执行 典型示例 gf通过网络发送具有巨大路径的命令 最多可能需要 30 秒才能结束 我想在执行过程中中断它 有没有办法取消命令执行并返回到正常模式 无需杀死 Vim 并重新启动 您可以中断它发送 SIGI
  • Vim:无法让病原体加载包

    我在 Stackoverflow 和 github 等上阅读了有关此问题的其他五个问题 但一直无法解决这个问题 此时我完全迷失了 我使用的是 Ubuntu 11 10 和 Vim 7 3 这是我的 vimrc set nocp call p
  • 检测重复代码的工具(Java)[关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我在一个项目中 以前的程序员一直在到处复制粘贴代码 这些代码实际上是相同的 或非常相似 并且可以将它们重构为一个 我花了无数的时间手动重构
  • 如何设置 Vim 进行 Android 开发?

    谁能描述一下用于 Android 开发的良好 Vim 设置吗 我现在使用 Eclipse 但我真的很想使用 Vim 因为它更快 而且我更喜欢它 例如 我对 Eclim 不感兴趣 我对使用哪些 Vim 插件 用于 Java 自动完成等 如何
  • @VisibleForTesting 的替代方案

    我知道 VisibleForTesting 是不可取的 因为它只是为了测试目的而更改类的接口 理想情况下 我们应该测试我们实际使用的接口 但什么是一个好的替代方案呢 You use VisibleForTesting正如您所说 当您想要测试
  • C# - 使用 Vim 作为主编辑器 [关闭]

    Closed 这个问题是无关 help closed questions 目前不接受答案 我已经喝了酷乐了 Vim 优雅美丽 我必须学习如何使用它并配置它以拥有一个出色的编译器 这是最好的学习方式 问题是 我从哪里开始 是否有一个很好的教程
  • vim 按语法高亮类型搜索

    我正在将 i18n 添加到现有项目 Web 应用程序 这涉及到用对 i18n 库的调用来替换静态文本的每一位 如果能够搜索该文本 而不是依靠语法突出显示来直观地识别它 将会很方便 在 vim 中 是否可以在文件中搜索特定突出显示类型的出现
  • Vim 和 Mac:如何在不使用 pbcopy 的情况下复制到剪贴板

    我有一个同时支持剪贴板和 xterm clipboard 的 vim 版本 然而 y or y不要复制到系统剪贴板 我知道我可以使用 w pbcopy 甚至为其创建快捷方式 但我真的想要标准方式 我也看到了 fakeclip 但希望找到一个
  • 在.vimrc中设置expandtab不生效

    由于某种原因set expandtab命令在我的 vimrc文件没有任何作用 这是我的 vimrc tab settings set expandtab set smarttab set softtabstop 2 set tabstop
  • 代码折叠未保存在我的 vimrc 中

    我将以下代码添加到我的 vimrc 中 save and restore folds when a file is closed and re opened autocmd BufWinLeave mkview autocmd BufWin
  • 有选择地设置 iskeyword

    通常我需要搜索大型 xml 模式文件以查找光标下单词的下一个出现位置 但如果它是一个标签或结束标签 则最好不要搜索 在下面的示例中 是光标所在的位置 使用 or 与 iskeyword 不包括 gt or lt 将在之间移动
  • Vim 中退格键的奇怪行为(从 Mac SSH 到 Linux)

    I didn t change any setting of my Vim but today the Backspace gets some crazy behavior Every time when I hit it it does

随机推荐