{"id":2305,"date":"2015-07-06T00:04:16","date_gmt":"2015-07-05T16:04:16","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2305"},"modified":"2015-07-06T00:04:16","modified_gmt":"2015-07-05T16:04:16","slug":"vim%e4%b8%ad%e7%9a%84%e6%8c%89%e9%94%ae%e6%98%a0%e5%b0%84","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2305.html","title":{"rendered":"Vim\u4e2d\u7684\u6309\u952e\u6620\u5c04"},"content":{"rendered":"<h6>\u7f18\u7531\uff1a<\/h6>\n<p>\u4eca\u5929\u5728\u6574\u7406\/\u7f16\u8f91\u81ea\u5df1\u7684Vim\u7684\u914d\u7f6e\u6587\u4ef6\/etc\/vimrc\u65f6\uff0c\u5728\u7f51\u4e0a\u770b\u5230\u7684\u4e00\u4e9b\u4e0d\u9519\u7684vimrc\u914d\u7f6e\u6587\u4ef6\u4e2d\u53d1\u73b0\u4e86\u81ea\u5b9a\u4e49\u7684mapping\uff1a<\/p>\n<ul>\n<li>nmap<\/li>\n<li>imap<\/li>\n<li>vmap<\/li>\n<li>map<\/li>\n<li>nnoremap<\/li>\n<\/ul>\n<p>\u4e4b\u524d\u542c\u8bf4\u8fc7Vim\u7684\u6309\u952e\u6620\u5c04\uff0c\u81ea\u5df1\u4e5f\u7528\u8fc7\u4e00\u4e9b\uff0c\u4e0d\u8fc7\u4e00\u76f4\u90fd\u6ca1\u6709\u8f83\u4e3a\u6df1\u5165\u7684\u4e86\u89e3\u8fc7\uff0c\u8fd9\u6b21\u8d81\u7740\u6574\u7406vimrc\u7684\u673a\u4f1a\u5b66\u4e60\u4e00\u4e0bVim\u7684map\u8bbe\u7f6e\u3002<\/p>\n<h6>\u641c\u7d22\u5173\u952e\u5b57\uff1a<\/h6>\n<ul>\n<li>Linux vim map nnoremap<\/li>\n<li>linux vim \u5171\u4eab\u526a\u8d34\u677f<\/li>\n<li>linux vim \u683c\u5f0f\u5316<\/li>\n<li>linux vim\u914d\u7f6e\u6587\u4ef6<\/li>\n<li>Linux vim multi tab<\/li>\n<\/ul>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/vim.wikia.com\/wiki\/Mapping_keys_in_Vim_-_Tutorial_(Part_1)\" target=\"_blank\">http:\/\/vim.wikia.com\/wiki\/Mapping_keys_in_Vim_-_Tutorial_(Part_1)<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/3776117\/what-is-the-difference-between-the-remap-noremap-nnoremap-and-vnoremap-mapping\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/3776117\/what-is-the-difference-between-the-remap-noremap-nnoremap-and-vnoremap-mapping <\/a>\u00a0#Nice!<\/li>\n<li><a href=\"http:\/\/learnvimscriptthehardway.stevelosh.com\/chapters\/03.html\" target=\"_blank\">http:\/\/learnvimscriptthehardway.stevelosh.com\/chapters\/03.html<\/a><\/li>\n<li><a href=\"http:\/\/vimdoc.sourceforge.net\/htmldoc\/map.html\" target=\"_blank\">http:\/\/vimdoc.sourceforge.net\/htmldoc\/map.html<\/a><\/li>\n<li>=<\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/3446320\/in-vim-how-to-map-save-to-ctrl-s\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/3446320\/in-vim-how-to-map-save-to-ctrl-s<\/a><\/li>\n<li><a href=\"http:\/\/unix.stackexchange.com\/questions\/84534\/vim-map-not-working\" target=\"_blank\">http:\/\/unix.stackexchange.com\/questions\/84534\/vim-map-not-working<\/a><\/li>\n<li><a href=\"http:\/\/unix.stackexchange.com\/questions\/78505\/vim-command-mapping-help\" target=\"_blank\">http:\/\/unix.stackexchange.com\/questions\/78505\/vim-command-mapping-help<\/a><\/li>\n<li><a href=\"http:\/\/www.frankhq.io\/blog\/2011\/10\/08\/the-difference-between-map-and-noremap-in-vim\/\" target=\"_blank\">http:\/\/www.frankhq.io\/blog\/2011\/10\/08\/the-difference-between-map-and-noremap-in-vim\/<\/a><\/li>\n<li>=<\/li>\n<li><a href=\"http:\/\/www.pythonclub.org\/linux\/vim\/map\" target=\"_blank\">VIM\u952e\u76d8\u6620\u5c04 (Map)<\/a><\/li>\n<li><a href=\"http:\/\/www.pythonclub.org\/vim\/map-basic\" target=\"_blank\">Vim\u6309\u952e\u6620\u5c04<\/a><\/li>\n<\/ul>\n<h5>\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n<p>There are six sets of mappings<\/p>\n<ol>\n<li>For <span style=\"color: #ff0000;\"><strong>Normal mode<\/strong><\/span>: When typing commands.<\/li>\n<li>For <span style=\"color: #ff0000;\"><strong>Visual mode<\/strong><\/span>: When typing commands while the Visual area is highlighted.<\/li>\n<li>For <span style=\"color: #ff0000;\"><strong>Select mode<\/strong><\/span>: like Visual mode but typing text replaces the selection.<\/li>\n<li>For <span style=\"color: #ff0000;\"><strong>Operator-pending mode<\/strong><\/span>: When an operator is pending (after &#8220;d&#8221;, &#8220;y&#8221;, &#8220;c&#8221;, etc.).\u00a0 See below: |omap-info|.<\/li>\n<li>For <span style=\"color: #ff0000;\"><strong>Insert mode<\/strong><\/span>.\u00a0 These are also used in Replace mode.<\/li>\n<li>For <span style=\"color: #ff0000;\"><strong>Command-line mode<\/strong><\/span>: When entering a &#8220;:&#8221; or &#8220;\/&#8221; command.<\/li>\n<\/ol>\n<p>Vim\u67096\u79cd\u6620\u5c04\u96c6\u5408\uff0c\u4f46\u53ea\u8981\u4e86\u89e3\u6700\u57fa\u672c\u76843\u79cd\uff0c\u57fa\u672c\u4e0a\u5c31\u53ef\u4ee5\u6ee1\u8db3\u65e5\u5e38\u5e94\u7528\u4e86\u3002<\/p>\n<ol>\n<li>\n<h6>Normal mode \uff08\u5e38\u6001\u6a21\u5f0f\uff09<\/h6>\n<\/li>\n<\/ol>\n<p>\u8fd0\u884cVim\u540e\u8fdb\u5165\u7684\u5c31\u662fNormal\u6a21\u5f0f\uff0c\u5728\u8fd9\u79cd\u6a21\u5f0f\u4e0b\u53ef\u4ee5\u79fb\u52a8\u9f20\u6807\u3001\u5bfb\u627e\u3001\u66ff\u6362\u3001\u7f16\u8f91\u6307\u4ee4\uff0c\u4f46\u4e0d\u80fd\u8f93\u5165\u6587\u5b57\u2014\u2014\u8fd9\u4e0e\u5176\u5b83\u7f16\u8f91\u5668\u6709\u5f88\u5927\u7684\u5dee\u522b\u3002<\/p>\n<ol start=\"2\">\n<li>\n<h6>Insert mode \uff08\u63d2\u5165\u6a21\u5f0f\uff09<\/h6>\n<\/li>\n<\/ol>\n<p>\u5728Insert \u6a21\u5f0f\u4e0b\uff0c\u53ef\u4ee5\u50cf\u5728\u5176\u5b83\u7f16\u8f91\u5668\u4e2d\u4e00\u6837\u8f93\u5165\u6587\u5b57\u3002\u6b64\u65f6\u5de6\u4e0b\u89d2\u72b6\u6001\u5217\u4f1a\u6709\u201c-INSERT-\u201d\uff08-\u63d2\u5165-\uff09\u5b57\u6837\u3002\u5728Normal\u6a21\u5f0f\u6309\u4e0b\u4e0b\u9762\u7684\u952e\u53ef\u4ee5\u8fdb\u5165Insert \u6a21\u5f0f\uff1ai \uff08\u5728\u5f53\u524d\u5b57\u7b26\u7684\u524d\u9762\u63d2\u5165\uff09\uff1ba \uff08\u5728\u5f53\u524d\u5b57\u7b26\u7684\u540e\u9762\u63d2\u5165\uff09\uff1bo \uff08\u5728\u5f53\u524d\u884c\u7684\u540e\u9762\u6dfb\u52a0\u65b0\u7684\u4e00\u884c\uff09\uff1bO \uff08\u5728\u5f53\u524d\u884c\u7684\u4e0a\u9762\u6dfb\u52a0\u65b0\u7684\u4e00\u884c\uff09\u3002<\/p>\n<ol start=\"3\">\n<li>\n<h6>Visual mode \uff08\u53cd\u767d\u6a21\u5f0f\uff09<\/h6>\n<\/li>\n<\/ol>\n<p>\u5728Visual \u6a21\u5f0f\u4e0b\u53ef\u4ee5\u628a\u6587\u5b57\u53cd\u767d\u8d77\u6765\uff0c\u6b64\u65f6\u5de6\u4e0b\u89d2\u72b6\u6001\u680f\u4f1a\u6709\u201c-VISUAL-\u201d\u6216\u201c-VISUAL LINE-\u201d\u6216\u201c-VISUAL BLOCK-\u201d\u5b57\u6837\u3002\u5728Normal\u6a21\u5f0f\u4e0b\u6309v\u6216V\u6216Ctrl-v\uff08\u6709\u4ec0\u4e48\u5dee\u522b\u5462\uff1f<span style=\"color: #ff0000;\"><strong>\u6309\u4e0bv\u662f\u8fdb\u5165\u5b57\u7b26\u9009\u53d6\u7684virtual\u6a21\u5f0f\uff1b\u6309\u4e0bV\u662f\u8fdb\u5165\u884c\u9009\u62e9\u7684virtual line\u6a21\u5f0f\uff1b\u6309\u4e0bCtrl-v\u662f\u8fdb\u5165\u5757\u9009\u62e9\u7684virtual block\u6a21\u5f0f<\/strong><\/span>\uff09\u53ef\u4ee5\u8fdb\u5165Visual \u6a21\u5f0f\u3002<\/p>\n<p>\u4e0d\u7ba1\u662f\u5728Insert\u6a21\u5f0f\u6216Visual\u6a21\u5f0f\u6216\u5176\u5b83\u7684\u4ec0\u4e48\u6a21\u5f0f\uff0c\u6309Esc\u952e\u90fd\u53ef\u4ee5\u8fd4\u56deNormal\u6a21\u5f0f\u3002<\/p>\n<hr \/>\n<h6>\u6309\u952e\u6620\u5c04<\/h6>\n<p><span style=\"color: #ff0000;\"><strong>nmap<\/strong><\/span>\uff1a\u6620\u5c04\u4e00\u4e2aNormal\u6a21\u5f0f\u4e0b\u7684\u952e\uff0c\u53ea\u6709\u5728Normal\u6a21\u5f0f\u8fd9\u4e2a\u547d\u4ee4\u624d\u4f1a\u751f\u6548\u3002<\/p>\n<p><span style=\"color: #ff0000;\"><strong>imap<\/strong><\/span>\uff1a\u6620\u5c04\u4e00\u4e2aInsert \u6a21\u5f0f\u4e0b\u7684\u952e\uff0c\u53ea\u6709\u5728Insert \u6a21\u5f0f\u8fd9\u4e2a\u547d\u4ee4\u624d\u4f1a\u751f\u6548\u3002<\/p>\n<p><span style=\"color: #ff0000;\"><strong>vmap<\/strong><\/span>\uff1a\u6620\u5c04\u4e00\u4e2aVisual\u6a21\u5f0f\u4e0b\u7684\u952e\uff0c\u53ea\u6709\u5728Visual\u6a21\u5f0f\u8fd9\u4e2a\u547d\u4ee4\u624d\u4f1a\u751f\u6548\u3002<\/p>\n<p>==<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0bVim\u7684map\u6620\u5c04\u662f\u9012\u5f52\u8fdb\u884c\u7684\uff0c\u9664\u975e\u4f60\u663e\u793a\u6307\u5b9anoremap\uff1a<\/p>\n<p><span style=\"color: #ff0000;\"><strong>:map<\/strong><\/span>\u00a0and\u00a0<span style=\"color: #ff0000;\"><strong>:noremap<\/strong><\/span>\u00a0are\u00a0<strong>recursive<\/strong>\u00a0and\u00a0<strong>non-recursive<\/strong>\u00a0versions of the various mapping commands.<\/p>\n<p>\u5177\u4f53\u89e3\u91ca\u5982\u4e0b\uff1a<\/p>\n<pre class=\"lang:default decode:true\">:map j gg\n:map Q j\n:noremap W j<\/pre>\n<p>\u5f53\u4f60\u6309\u4e0bj\u65f6\u4f1a\u88ab\u6620\u5c04\u5230gg\uff0c\u6309\u4e0bQ\u65f6\u4e5f\u4f1a\u88ab\u6620\u5c04\u5230gg\uff08\u5148\u6620\u5c04\u5230j\uff0c\u7136\u540e\u6620\u5c04\u5230gg\uff09\uff0c\u56e0\u4e3aVim\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0bmap\u6620\u5c04\u662f\u9012\u5f52\u8fdb\u884c\u7684\uff1b\u5f53\u4f60\u6309\u4e0bW\u65f6\u4f1a\u88ab\u6620\u5c04\u5230j\u4f46\u4e0d\u4f1a\u88ab\u7ee7\u7eed\u6620\u5c04\u5230gg\uff0c\u56e0\u4e3a\u8fd9\u91cc\u6211\u4eec\u663e\u793a\u6307\u5b9a\u4e86noremap\u975e\u9012\u5f52\u6620\u5c04\u3002<\/p>\n<h6>==\u5e38\u7528\u7684Vim\u6309\u952e\u6620\u5c04==<\/h6>\n<pre class=\"lang:default decode:true \">\"\u5171\u4eab\u526a\u8d34\u677f(\u540e\u9762\u590d\u5236\/\u7c98\u8d34\u64cd\u4f5c\u7684\u524d\u63d0)\nset clipboard=unnamed\n\n\"\u5c06Tab\u66ff\u6362\u4e3a4\u7a7a\u683c\n:nmap tt :%s\/\\t\/    \/g&lt;CR&gt;\n\n\"\u5168\u6587\u590d\u5236\n:map &lt;C-A&gt; ggVG$\"+y\n\n\"\u9009\u4e2d\u72b6\u6001\u4e0b Ctrl+c \u590d\u5236 \/ Ctrl-v \u7c98\u8d34\n:map &lt;C-v&gt; \"*pa\n:imap &lt;C-v&gt; &lt;Esc&gt;\"*pa\n:vmap &lt;C-c&gt; \"+y\n\n\"\u65e0\u8bba\u662f normal\u6a21\u5f0f \/ insert\u6a21\u5f0f\uff0c\u6309 Crtl+s \u4fdd\u5b58\u6587\u4ef6\n:nmap &lt;c-s&gt; :w&lt;CR&gt;\n:imap &lt;c-s&gt; &lt;Esc&gt;:w&lt;CR&gt;a\n\n\"\u81ea\u52a8\u8865\u5168\u62ec\u53f7\n:inoremap ( ()&lt;Esc&gt;i\n:inoremap { {}&lt;ESC&gt;i\n:inoremap [ []&lt;ESC&gt;i\n\n\"\u5728\u63d2\u5165\u6a21\u5f0f\u4e0b\u5feb\u901f\u8fdb\u884c\u884c\u9996\/\u884c\u5c3e\u8df3\u8f6c\n:imap &lt;C-a&gt; &lt;Esc&gt;^\n:imap &lt;C-e&gt; &lt;Esc&gt;$\n\n\n\"\u5728 Tab\u9875 \u4e4b\u95f4\u5207\u6362\n:map &lt;F2&gt; :tabp&lt;CR&gt;\n:map &lt;F3&gt; :tabn&lt;CR&gt;\n\n\"\u53bb\u7a7a\u884c\n:nnoremap &lt;F4&gt; :g\/^\\s*$\/d&lt;CR&gt;\n\n\"\u5728(normal\/insert\u6a21\u5f0f\u4e0b)\u6309F5\u63d2\u5165\u5f53\u524d\u65f6\u95f4\n:nnoremap &lt;F5&gt; \"=strftime(\"%F %R\")&lt;CR&gt;gP\n:inoremap &lt;F5&gt; &lt;C-R&gt;=strftime(\"%F %R\")&lt;CR&gt;\n\n\"\u5168\u6587\u683c\u5f0f\u5316\n:map &lt;F12&gt; gg=G<\/pre>\n<p>=Update below=<\/p>\n<p>\u540e\u6765\uff0c\u6709\u770b\u5230\u4e86\u51e0\u7bc7\u4ecb\u7ecdVim\u7684mapleader\u7684\u6587\u7ae0\uff0c\u8bd5\u4e86\u8bd5\uff0c\u679c\u7136\u6548\u7387\u5927\u6709\u63d0\u5347\uff0c\u9042\u66f4\u65b0vimrc\u8bbe\u7f6e\u5982\u4e0b\uff1a<\/p>\n<pre class=\"lang:default decode:true\">\"Set mapleader\nlet mapleader=\",\"\n\n\"Fast reloading of the \/etc\/vimrc\nmap &lt;silent&gt; &lt;leader&gt;ss :source \/etc\/vimrc&lt;cr&gt;\n\"Fast editing of \/etc\/vimrc\nmap &lt;silent&gt; &lt;leader&gt;ee :e \/etc\/vimrc&lt;cr&gt;\n\"When \/etc\/vimrc is edited, reload it\nautocmd! bufwritepost \/etc\/vimrc source \/etc\/vimrc\n\n\"\u5feb\u901f\u65b0\u5efaTab\nnnoremap &lt;leader&gt;n :tabnew&lt;cr&gt;\n\"\u5feb\u901f\u4fdd\u5b58\nnnoremap &lt;leader&gt;w :w&lt;cr&gt;\n\"\u5feb\u901fsudo\u4fdd\u5b58\nnoremap &lt;silent&gt; &lt;leader&gt;ww :w !sudo tee %&lt;cr&gt;\n\"Disable highlight when &lt;leader&gt;&lt;cr&gt; is pressed\nmap &lt;silent&gt; &lt;leader&gt;&lt;cr&gt; :noh&lt;cr&gt;\n\n\"Smart way to move between splited windows\nmap &lt;C-j&gt; &lt;C-W&gt;j\nmap &lt;C-k&gt; &lt;C-W&gt;k\nmap &lt;C-h&gt; &lt;C-W&gt;h\nmap &lt;C-l&gt; &lt;C-W&gt;l<\/pre>\n<p>=EOF=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7f18\u7531\uff1a \u4eca\u5929\u5728\u6574\u7406\/\u7f16\u8f91\u81ea\u5df1\u7684Vim\u7684\u914d\u7f6e\u6587\u4ef6\/etc\/vimrc\u65f6\uff0c\u5728\u7f51\u4e0a\u770b\u5230\u7684\u4e00\u4e9b\u4e0d\u9519\u7684vimrc\u914d\u7f6e\u6587\u4ef6 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11,12],"tags":[43,537],"class_list":["post-2305","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-tools","tag-vim","tag-vimrc"],"views":5192,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2305"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2305\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}