我听说过很多关于Vim的事,包括优点和缺点。 (作为一名开发人员)使用Vim确实应该比使用其他任何编辑器都要快。 我用Vim来做一些基本的事情,我用Vim最多只能减少10倍的效率。

当你谈论速度时,只有两件事你应该关心(你可能不够关心,但你应该关心):

左右交替使用的 用手是最快的方法 键盘。 永远不要碰鼠标 第二种方法是尽可能快。 你要花很长时间才能移动你的手, 抓住鼠标,移动它,把它带来 回到键盘上(你经常这样做 看看键盘,确保你 将你的手正确地回到正确的位置)

下面的两个例子说明了为什么我使用Vim效率低得多。

复制/剪切和粘贴。我一直都这么做。在所有当代编辑器中,你用左手按Shift键,用右手移动光标来选择文本。然后按Ctrl+C复制,移动光标,按Ctrl+V粘贴。

Vim的情况很糟糕:

Yy复制一行(你几乎不需要整行!) [number xx]yy复制xx行到缓冲区。但你永远不知道你是否选择了你想要的。我经常要做[number xx]dd然后u来撤销!

另一个例子吗?搜索和替换。

在PSPad中:按Ctrl+f,然后输入你想要搜索的内容,然后按Enter。 在Vim: /中,然后输入你想要搜索的内容,然后如果有一些特殊字符,在每个特殊字符前放\,然后按Enter。

Vim的一切都是这样的:似乎我不知道如何正确处理它。

注:我已经读了Vim小抄:)

我的问题是:

与当代编辑器相比,您使用Vim的哪些方式使您的工作效率更高?


当前回答

多个缓冲区,特别是在它们之间快速跳转,以比较:bp和:bn的两个文件(正确地重新映射到a Shift + p或Shift + n)

Vimdiff模式(在两个垂直缓冲区中分割,用颜色显示差异)

区域复制Ctrl + v

最后,标签完成标识符(搜索“mosh_tab_or_complete”)。这改变了我的生活。

其他回答

一些提高效率的技巧:

智能运动

*和#在向前/向后光标下搜索单词。 W到下一个单词 W到下一个空格分隔的单词 B /e到当前单词的开头/结尾。(B / E只代表空格) gg / G跳转到文件的开始/结束。 %跳转到匹配{..}或(..)等. . {/}跳转到下一段。 ”。跳转回上次编辑的行。 g;跳回上次编辑的位置。

快速编辑命令

我在开头插入。 end的附加语句。 o / o打开一个新的行后/前电流。 v / v / Ctrl+ v可视模式(选择文本!) Shift+R替换文本 C更改剩余部分行。

结合命令

大多数命令接受数量和方向,例如:

改变直到单词结束 改变3个单词 BcW =开始全字,更改全字 ciW =改变内心的词。 Ci " =改变内部之间的".." Ci(=更改文本之间(..) Ci < = change text between < ..>(需要在vimrc中设置匹配对+=<:>) 4dd =删除4行 3x =删除3个字符。 3s =替换3个字符。

有用的程序员命令

R替换一个字符(例如rd用d替换当前字符)。 ~改变情况。 J连接两条线 Ctrl+A / Ctrl+X增加/减少一个数字。 . 重复最后一个命令(一个简单的宏) ==修复行缩进 >缩进块(可视模式下) < unindent block(在可视模式下)

宏录制

按q[键]开始录音。 然后按q键停止录制。 宏可以使用@[key]播放。

通过使用非常特定的命令和动作,VIM可以为下一行重新播放这些确切的动作。(例如A表示尾尾,b / e表示将光标移动到单词的开头或结尾)

良好设置的示例

# reset to vim-defaults
if &compatible          # only if not set before:
  set nocompatible      # use vim-defaults instead of vi-defaults (easier, more user friendly)
endif

# display settings
set background=dark     # enable for dark terminals
set nowrap              # dont wrap lines
set scrolloff=2         # 2 lines above/below cursor when scrolling
set number              # show line numbers
set showmatch           # show matching bracket (briefly jump)
set showmode            # show mode in status bar (insert/replace/...)
set showcmd             # show typed command in status bar
set ruler               # show cursor position in status bar
set title               # show file in titlebar
set wildmenu            # completion with menu
set wildignore=*.o,*.obj,*.bak,*.exe,*.py[co],*.swp,*~,*.pyc,.svn
set laststatus=2        # use 2 lines for the status bar
set matchtime=2         # show matching bracket for 0.2 seconds
set matchpairs+=<:>     # specially for html

# editor settings
set esckeys             # map missed escape sequences (enables keypad keys)
set ignorecase          # case insensitive searching
set smartcase           # but become case sensitive if you type uppercase characters
set smartindent         # smart auto indenting
set smarttab            # smart tab handling for indenting
set magic               # change the way backslashes are used in search patterns
set bs=indent,eol,start # Allow backspacing over everything in insert mode

set tabstop=4           # number of spaces a tab counts for
set shiftwidth=4        # spaces for autoindents
#set expandtab           # turn a tabs into spaces

set fileformat=unix     # file mode is unix
#set fileformats=unix,dos    # only detect unix file format, displays that ^M with dos files

# system settings
set lazyredraw          # no redraws in macros
set confirm             # get a dialog when :q, :w, or :wq fails
set nobackup            # no backup~ files.
set viminfo='20,\"500   # remember copy registers after quitting in the .viminfo file -- 20 jump links, regs up to 500 lines'
set hidden              # remember undo after quitting
set history=50          # keep 50 lines of command history
set mouse=v             # use mouse in visual mode (not normal,insert,command,help mode


# color settings (if terminal/gui supports it)
if &t_Co > 2 || has("gui_running")
  syntax on          # enable colors
  set hlsearch       # highlight search (very useful!)
  set incsearch      # search incremently (search while typing)
endif

# paste mode toggle (needed when using autoindent/smartindent)
map <F10> :set paste<CR>
map <F11> :set nopaste<CR>
imap <F10> <C-O>:set paste<CR>
imap <F11> <nop>
set pastetoggle=<F11>

# Use of the filetype plugins, auto completion and indentation support
filetype plugin indent on

# file type specific settings
if has("autocmd")
  # For debugging
  #set verbose=9

  # if bash is sh.
  let bash_is_sh=1

  # change to directory of current file automatically
  autocmd BufEnter * lcd %:p:h

  # Put these in an autocmd group, so that we can delete them easily.
  augroup mysettings
    au FileType xslt,xml,css,html,xhtml,javascript,sh,config,c,cpp,docbook set smartindent shiftwidth=2 softtabstop=2 expandtab
    au FileType tex set wrap shiftwidth=2 softtabstop=2 expandtab

    # Confirm to PEP8
    au FileType python set tabstop=4 softtabstop=4 expandtab shiftwidth=4 cinwords=if,elif,else,for,while,try,except,finally,def,class
  augroup END

  augroup perl
    # reset (disable previous 'augroup perl' settings)
    au!  

    au BufReadPre,BufNewFile
    \ *.pl,*.pm
    \ set formatoptions=croq smartindent shiftwidth=2 softtabstop=2 cindent cinkeys='0{,0},!^F,o,O,e' " tags=./tags,tags,~/devel/tags,~/devel/C
    # formatoption:
    #   t - wrap text using textwidth
    #   c - wrap comments using textwidth (and auto insert comment leader)
    #   r - auto insert comment leader when pressing <return> in insert mode
    #   o - auto insert comment leader when pressing 'o' or 'O'.
    #   q - allow formatting of comments with "gq"
    #   a - auto formatting for paragraphs
    #   n - auto wrap numbered lists
    #   
  augroup END


  # Always jump to the last known cursor position. 
  # Don't do it when the position is invalid or when inside
  # an event handler (happens when dropping a file on gvim). 
  autocmd BufReadPost * 
    \ if line("'\"") > 0 && line("'\"") <= line("$") | 
    \   exe "normal g`\"" | 
    \ endif 

endif # has("autocmd")

设置可以存储在~/中。Vimrc,或在/etc/vimrc.系统范围Local,然后从/etc/vimrc文件中读取:

source /etc/vimrc.local

(为了使它在VIM中工作,您必须将# comment字符替换为“”,我想在这里给出正确的语法高亮显示)。

我在这里列出的命令都是非常基本的,也是到目前为止我使用的主要命令。它们已经让我变得更有效率,而不需要知道所有花哨的东西。

In addition to the great reply about grokking vi, it should be noted that vim does add some very vi-like features that make using vi commands nicer. The one that comes to mind first are text objects: instead of {!}fmt to reformat the current paragraph, !apfmt does the same. It works by first specifying that we want to select a text object, which is the current paragraph. Similar, to change the current string literal (foo to bar for an example), instead of T"ct"bar (move to just after the previous ", change until just before the next ", insert bar), you can say ci"bar: change inside (innermost) quotes, inserting bar.

从文本对象而不是移动命令的角度思考是非常不错的。

巧妙的TAB补全^^

http://vim.wikia.com/wiki/Smart_mapping_for_tab_completion

我惊讶地发现没有人提到t运动。我经常把它和参数表一起用dt或者yt,

花30分钟做vim教程(在终端运行vimtutor而不是vim)。您将学习基本的动作和一些击键,这将使您使用vim至少与使用之前使用的文本编辑器一样高效。在那之后,好吧,再读一遍吉姆·丹尼斯的回答:)