你的 .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 中有什么? [关闭] 的相关文章

  • 使用 vim 处理文本文件中的 \r \n ^M ​​^@

    当我将 excel 文件中的数据行保存为制表符分隔的 txt 文件 然后在 VIM 中打开这些文件时 我发现 excel 中曾经的多行文件现在是 VIM 中的单行文件 可以使用一些替换命令在 VIM 中分隔 行 s M r n g 此后 线
  • Vim 和 Ctags:生成标签时忽略某些文件

    我有一个文件夹 llvm2 9 我在其中运行了此命令 gt ctags R sort 1 c kinds p fields iaS extra q language force C 这是 html 文件中的索引方法 也存在于 llvm2 9
  • 在 Vim 中将 DOS/Windows 行结尾转换为 Linux 行结尾

    如果我打开在 Windows 中创建的文件 所有行都以 M 如何一次性删除这些字符 dos2unix https sourceforge net projects dos2unix是一个可以执行此操作的命令行实用程序 In Vim s M
  • vim 命令可以映射到具有 >1 修饰符的组合键(例如 ctrl-alt-v)

    是否可以将 vim 命令映射到涉及多个修饰符的按键组合 例如 ctrl alt v 据我所知 唯一可以与另一个组合使用的修饰键是shift 例如
  • 在哪里可以找到有关重构的资源? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 重构是改进现有系统设计而不改变其行为的过程 除了马丁 福勒的开创性著作 重构 改进现有代码的设计 ht
  • 如何让 git 在 vi​​m 中显示更改,就像 hg 使用 hgeditor 脚本那样?

    Mercurial 的一个有趣的功能是能够查看将在 vim split 中提交的更改 请参阅VIM 中的 DiffsInCommitMessage https www mercurial scm org wiki DiffsInCommit
  • 如何在vim中的相同行数前面插入多行?

    假设我有两个文本块 其中之一在我的剪贴板中 one two three 另一个位于我正在 vim 中编辑的文件中 AAA BBB CCC 如何在第二个块前面插入第一个块以获得以下结果 oneAAA twoBBB threeCCC 我希望有一
  • 有没有一个 vim 命令可以重新定位选项卡?

    如何更改当前选项卡的位置 顺序Vim 例如 如果我想将当前选项卡重新定位为第一个选项卡 您可以使用以下命令重新定位选项卡 tabm使用相对或零索引绝对参数 绝对 将选项卡移至位置 i tabm i 相对的 将选项卡 i 位置向右移动 tab
  • 为什么 "map! :q " 在 vi​​m 中不起作用?

    I input map
  • 如何取消 Vim 中的粘贴操作?

    每当我不小心在 Putty 中右键单击 打开 Vim 时 我的剪贴板上就有相当多的文本 并且 Vim 启动了粘贴操作 该操作已经持续了大约十分钟 我不想丢失未保存的工作 有没有办法指示 Vim 停止粘贴文本 If you re in nor
  • 你能让 vi 在打开时“前进”屏幕吗?

    我经常在 vi 中工作 暂停 vi 在 cli 上运行一些东西 然后返回到 vi 来处理结果 例如 修复运行 cli 命令时出现的错误 但是 当我 fg vi 时 vi 会 擦除 当前终端缓冲区 并且我在回滚缓冲区中看不到终端输出的 最后一
  • 在Vim中,如何删除单词的后缀?

    在vim中 在正常模式下 如果光标位于单词中 而不是最后一个字母 de从光标位置删除单词的后缀 如果光标位于最后一个字母上 x也这样做 同时de会跳到下一个单词的末尾 您将使用什么命令在这两种情况下都有效 无论最后一个字母与否 目的是将命令
  • 如何在vim中将菜单键(“应用程序键”)映射到Escape键?

    我认为使用菜单键退出 vim 的插入模式将是一件很棒的事情 使用 Super 键也很好 但我不确定是否可能 因为 Super 键是一个修饰符 无论如何 我找不到任何与此相关的内容 寻求您的帮助并提前致谢 我认为没有任何方法可以配置 Vim
  • 文件保存期间语法突出显示随机消失

    我正在使用 vim 编辑一些 python 文件 最近偶尔会出现在 vim 中保存缓冲区后语法高亮消失的情况 我尝试重置syntax on and set filetype python但无济于事 我根本不知道是什么原因导致了这个问题 所以
  • Vim 关闭窗口而不关闭缓冲区

    如何在不删除缓冲区的情况下关闭窗口或取消分割 A window is a viewport on a buffer In vim to manage windows it is CTRL w the leading command that
  • Vim 中的空格作为制表符和退格键行为

    在我的 vimrc 中我有 set shiftwidth 4 set tabstop 4 set expandtab 当我点击 Tab 按钮时 设置为使用 4 个空格而不是 Tab 但是当我在 Tab 之后按退格键时 我需要退格所有 4 个
  • Vim / vi 生存指南

    基本的 vim 命令有哪些 新用户需要了解什么才能避免陷入麻烦 请每条评论一条命令 我发现不可替代的 因为它也可以在 vi 中使用 与 vim 的视觉模式不同 是标记 您可以用以下标记标记不同的点m 小写 然后是您选择的字母 例如 x 然后
  • 以 Vim 的 -o - 模式打开 Grep 输出中的文件

    如何将文件列表放入 Vim 的 o 模式 我有一个文件列表作为 Grep 的输出 我运行失败 1 grep il sid vim o 2 grep il sid xargs vim o 3 grep il sid xargs vim 4 v
  • 运行 tmux 时映射箭头键

    这些键映射在 tmux 中停止工作 在我的 vimrc 我有 nmap
  • vim 映射键不起作用

    我一直在尝试映射 ctrl 来在 vim 的插入模式下保存 它似乎永远不起作用 http vim wikia com wiki Map Ctrl S to save current or new files http vim wikia c

随机推荐