如何给<ul struct和class的区别6="slides">加外链

是时候显出杀器了。&br&&a href=&//link.zhihu.com/?target=http%3A//stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/88282& class=& external& target=&_blank& rel=&nofollow noreferrer&&&span class=&invisible&&http://&/span&&span class=&visible&&stackoverflow.com/quest&/span&&span class=&invisible&&ions/388242/the-definitive-c-book-guide-and-list/282&/span&&span class=&ellipsis&&&/span&&/a&&br&&br&链接里具体书单如下(从易到难)&br&BeginnerIntroductory, no previous programming experience&ul&&li&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Programming: Principles and Practice Using C++&/a& (Bjarne Stroustrup) (&strong&updated for C++11/C++14&/strong&) An introduction to programming using C++ by the creator of the language. A good read, that assumes no previous programming experience, but is not only for beginners.&/li&&/ul&Introductory, with previous programming experience&ul&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&C++ Primer&/a& * (Stanley Lippman, Josée Lajoie, and Barbara E. Moo) (&strong&updated for C++11&/strong&) Coming at 1k pages, this is a very thorough introduction into C++ that covers just about everything in the language in a very accessible format and in great detail. The fifth edition (released August 16, 2012) covers C++11. &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D1848& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a&&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&A Tour of C++&/a& (Bjarne Stroustrup) The &tour& is a quick (about 180 pages and 14 chapters) tutorial overview of all of standard C++ (language and standard library, &strong&and using C++11&/strong&) at a moderately high level for people who already know C++ or at least are experienced programmers. This book is an extended version of the material that constitutes Chapters 2-5 of The C++ Programming Language, 4th edition.&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/X& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Accelerated C++&/a& (Andrew Koenig and Barbara Moo) This basically covers the same ground as the &em&C++ Primer&/em&, but does so on a fourth of its space. This is largely because it does not attempt to be an introduction to &em&programming&/em&, but an introduction to &em&C++&/em& for people who've previously programmed in some other language. It has a steeper learning curve, but, for those who can cope with this, it is a very compact introduction into the language. (Historically, it broke new ground by being the first beginner's book to use a modern approach at teaching the language.) &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D1185& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a&&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Thinking in C++&/a& (Bruce Eckel) T is a tutorial style &em&free&/em& set of intro level books. Downloads: &a href=&//link.zhihu.com/?target=http%3A//www.mindviewinc.com/downloads/TICPP-2nd-ed-Vol-one.zip& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&vol 1&/a&, &a href=&//link.zhihu.com/?target=http%3A//www.mindviewinc.com/downloads/TICPP-2nd-ed-Vol-two.zip& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&vol 2&/a&. Unfortunately they’re marred by a number of trivial errors (e.g. maintaining that temporaries are automatically const), with no official errata list. A partial 3rdparty errata list is available at (&a href=&//link.zhihu.com/?target=http%3A//www.computersciencelab.com/Eckel.htm& class=& external& target=&_blank& rel=&nofollow noreferrer&&&span class=&invisible&&http://www.&/span&&span class=&visible&&computersciencelab.com/&/span&&span class=&invisible&&Eckel.htm&/span&&span class=&ellipsis&&&/span&&/a&), but it’s apparently not maintained.&/p&&/li&&/ul&&p&* Not to be confused with &a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&C++ Primer Plus&/a&(Stephen Prata), with a significantly less favorable &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D1744& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&review&/a&.&/p&Best practices&ul&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Effective C++&/a& (Scott Meyers) This was written with the aim of being the best second book C++ programmers should read, and it succeeded. Earlier editions were aimed at programmers coming from C, the third edition changes this and targets programmers coming from languages like Java. It presents ~50 easy-to-remember rules of thumb along with their rationale in a very accessible (and enjoyable) style. For C++11 and C++14 the examples and a few issues are outdated and Effective Modern C++ should be preferred. &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D700& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a&&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Effective Modern C++&/a& (Scott Meyers) This is basically the new version of &em&Effective C++&/em&, aimed at C++ programmers making the transition from C++03 to C++11 and C++14. &/p&&/li&&li&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Effective STL&/a& (Scott Meyers) This aims to do the same to the part of the standard library coming from the STL what &em&Effective C++&/em& did to the language as a whole: It presents rules of thumb along with their rationale. &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D67& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a&&/li&&/ul&Intermediate&ul&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/X& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&More Effective C++&/a& (Scott Meyers) Even more rules of thumb than &em&Effective C++&/em&. Not as important as the ones in the first book, but still good to know.&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Exceptional C++&/a& (Herb Sutter) Presented as a set of puzzles, this has one of the best and thorough discussions of the proper resource management and exception safety in C++ through Resource Acquisition is Initialization (RAII) in addition to in-depth coverage of a variety of other topics including the pimpl idiom, name lookup, good class design, and the C++ memory model. &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D209& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a&&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/X& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&More Exceptional C++&/a& (Herb Sutter) Covers additional exception safety topics not covered in &em&Exceptional C++&/em&, in addition to discussion of effective object oriented programming in C++ and correct use of the STL. &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D784& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a&&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Exceptional C++ Style&/a& (Herb Sutter) Discusses generic programming, optimization, and this book also has an excellent exposition of how to write modular code in C++ by using nonmember functions and the single responsibility principle. &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D107& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a&&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&C++ Coding Standards&/a& (Herb Sutter and Andrei Alexandrescu) &Coding standards& here doesn't mean &how many spaces should I indent my code?& This book contains 101 best practices, idioms, and common pitfalls that can help you to write correct, understandable, and efficient C++ code. &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D1439& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a&&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&C++ Templates: The Complete Guide&/a& (David Vandevoorde and Nicolai M. Josuttis) This is &em&the&/em& book about templates as they existed before C++11. It covers everything from the very basics to some of the most advanced template metaprogramming and explains every detail of how templates work (both conceptually and at how they are implemented) and discusses many common pitfalls. Has excellent summaries of the One Definition Rule (ODR) and overload resolution in the appendices. A &a href=&//link.zhihu.com/?target=http%3A//amzn.com/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&second edition&/a& is scheduled for 2016. &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D506& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a&&/p&&/li&&/ul&Advanced&ul&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Modern C++ Design&/a& (Andrei Alexandrescu) A groundbreaking book on advanced generic programming techniques. Introduces policy-based design, type lists, and fundamental generic programming idioms then explains how many useful design patterns (including small object allocators, functors, factories, visitors, and multimethods) can be implemented efficiently, modularly, and cleanly using generic programming. &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D979& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a&&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&C++ Template Metaprogramming&/a& (David Abrahams and Aleksey Gurtovoy)&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&C++ Concurrency In Action&/a&(Anthony Williams) A book covering C++11 concurrency support including the thread library, the atomics library, the C++ memory model, locks and mutexes, as well as issues of designing and debugging multithreaded applications.&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Advanced C++ Metaprogramming&/a& (Davide Di Gennaro) A pre-C++11 manual of TMP techniques, focused more on practice than theory. There are a ton of snippets in this book, some of which are made obsolete by typetraits, but the techniques, are nonetheless useful to know. If you can put up with the quirky formatting/editing, it is easier to read than Alexandrescu, and arguably, more rewarding. For more experienced developers, there is a good chance that you may pick up something about a dark corner of C++ (a quirk) that usually only comes about through extensive experience.&/p&&/li&&/ul&Reference Style - All Levels&ul&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&The C++ Programming Language&/a& (Bjarne Stroustrup) (&strong&updated for C++11&/strong&) The classic introduction to C++ by its creator. Written to parallel the classic K&R, this indeed reads very much alike it and covers just about everything from the core language to the standard library, to programming paradigms to the language's philosophy. (Thereby making the latest editions break the 1k page barrier.)
&a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D620& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a& The &a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&fourth edition&/a& (released on May 19, 2013) covers C++11.&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&C++ Standard Library Tutorial and Reference&/a& (Nicolai Josuttis) (&strong&updated for C++11&/strong&) &em&The&/em& introduction and reference for the C++ Standard Library. The second edition (released on April 9, 2012) covers C++11. &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D1849& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a&&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&The C++ IO Streams and Locales&/a& (Angelika Langer and Klaus Kreft) There's very little to say about this book except that, if you want to know anything about streams and locales, then this is the one place to find definitive answers. &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D200& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a&&/p&&/li&&/ul&&p&C++11 References:&/p&&ul&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//webstore.ansi.org/RecordDetail.aspx%3Fsku%3DINCITS%252fISO%252fIEC%2B& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&The C++ Standard (INCITS/ISO/IEC )&/a& This, of course, is the final arbiter of all that is or isn't C++. Be aware, however, that it is intended purely as a reference for &em&experienced&/em& users willing to devote considerable time and effort to its understanding. As usual, the first release was &em&quite&/em&expensive ($300+ US), but it has now been released in electronic form for $60US&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//www.artima.com/shop/overview_of_the_new_cpp& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Overview of the New C++ (C++11/14) (PDF only)&/a& (Scott Meyers) (&strong&updated for C++1y/C++14&/strong&) These are the presentation materials (slides and some lecture notes) of a three-day training course offered by Scott Meyers, who's a highly respected author on C++. Even though the list of items is short, the quality is high.&/p&&/li&&/ul&Classics / Older&p&&strong&Note:&/strong& Some information contained within these books may not be up-to-date or no longer considered best practice.&/p&&ul&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&The Design and Evolution of C++&/a& (Bjarne Stroustrup) If you want to know &em&why&/em& the language is the way it is, this book is where you find answers. This covers everything &em&before the standardization&/em& of C++.&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Ruminations on C++&/a& - (Andrew Koenig and Barbara Moo) &a href=&//link.zhihu.com/?target=http%3A//accu.org/index.php%3Fmodule%3Dbookreviews%26func%3Dsearch%26rid%3D776& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[Review]&/a&&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Advanced C++ Programming Styles and Idioms&/a& (James Coplien) A predecessor of the pattern movement, it describes many C++-specific &idioms&. It's certainly a very good book and might still be worth a read if you can spare the time, but quite old and not up-to-date with current C++. &/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Large Scale C++ Software Design&/a& (John Lakos) Lakos explains techniques to manage very big C++ software projects. Certainly a good read, if it only was up to date. It was written long before C++98, and misses on many features (e.g. namespaces) important for large scale projects. If you need to work in a big C++ software project, you might want to read it, although you need to take more than a grain of salt with it. The first volume of a new edition is &a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&expected in 2015&/a&.&/p&&/li&&li&&p&&a href=&//link.zhihu.com/?target=http%3A//rads.stackoverflow.com/amzn/click/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Inside the C++ Object Model&/a&(Stanley Lippman) If you want to know how virtual member functions are commonly implemented and how base objects are commonly laid out in memory in a multi-inheritance scenario, and how all this affects performance, this is where you will find thorough discussions of such topics.&/p&&/li&&/ul&
是时候显出杀器了。
链接里具体书单如下(从易到难) BeginnerIntroductory, no previous programming experience (Bjarne Stroustrup) (updated for C++11/C++14) An introduction to…
&figure&&img src=&https://pic3.zhimg.com/v2-d05c0b61dac_b.jpg& data-rawwidth=&800& data-rawheight=&600& class=&origin_image zh-lightbox-thumb& width=&800& data-original=&https://pic3.zhimg.com/v2-d05c0b61dac_r.jpg&&&/figure&&blockquote&简评:作为工程师,你在命令行下最常打的命令无非就是 cd 与 ls。这些年你浪费了多少时间?&/blockquote&&p&作为一个程序员或者在 shell 中花费大量时间的人,你可能会经常以一种低效率的方式在目录中来回移动,特别是每天经常访问相同目录。&/p&&p&比如像这样:&/p&&figure&&img src=&https://pic4.zhimg.com/v2-e401aa76f06a_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&677& data-rawheight=&276& class=&origin_image zh-lightbox-thumb& width=&677& data-original=&https://pic4.zhimg.com/v2-e401aa76f06a_r.jpg&&&/figure&&p&当然你可能用的稍微熟练点了,用 Tab 能省不少事,像这样:&/p&&figure&&img src=&https://pic2.zhimg.com/v2-ef9ea2b812f12cc54b69_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&677& data-rawheight=&204& class=&origin_image zh-lightbox-thumb& width=&677& data-original=&https://pic2.zhimg.com/v2-ef9ea2b812f12cc54b69_r.jpg&&&/figure&&p&不错!你大约节省了 20 次的输入,值得称赞。你也会使用 mkdir 创建新目录并直接进入新建目录(cd !$),你也能记住 project 的目录,你就不用老 ls 来寻找文件。不过现实问题,人不是电脑,我们能记住一两个,但不可能记住全部,我们的效率不够高。&/p&&p&有没有想过这种方式?&/p&&figure&&img src=&https://pic1.zhimg.com/v2-27aada867cdbbfef5757f1_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&668& data-rawheight=&169& class=&origin_image zh-lightbox-thumb& width=&668& data-original=&https://pic1.zhimg.com/v2-27aada867cdbbfef5757f1_r.jpg&&&/figure&&p&现在只需要 j d(或者 j dev、j develop)就可以跳转到 ~/Develop 目录,j p 就可以跳转单 ~/Develop/project。效率大幅提高。&/p&&p&看看对比:&/p&&figure&&img src=&https://pic4.zhimg.com/v2-ba332fb79fb918ec4c17bed1_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&680& data-rawheight=&132& class=&origin_image zh-lightbox-thumb& width=&680& data-original=&https://pic4.zhimg.com/v2-ba332fb79fb918ec4c17bed1_r.jpg&&&/figure&&p&这是如何实现的?&/p&&p&用 AutoJump 可以做到。(GitHub 地址:&a href=&https://link.zhihu.com/?target=https%3A//github.com/wting/autojump& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&wting/autojump&/a&)&/p&&p&根据官方介绍,它能以更快的方式浏览系统文件,这并不准确,或者说很谦虚。据我完全估计,用 AutoJump 至少让我省了 100 个小时,最起码省了这么多。&/p&&p&&br&&/p&&h2&Autojump 是如何工作的?&/h2&&p&看看这两个命令:&/p&&figure&&img src=&https://pic1.zhimg.com/v2-27f646dbc12cf8b5ac05c7feee92ddf9_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&672& data-rawheight=&73& class=&origin_image zh-lightbox-thumb& width=&672& data-original=&https://pic1.zhimg.com/v2-27f646dbc12cf8b5ac05c7feee92ddf9_r.jpg&&&/figure&&figure&&img src=&https://pic4.zhimg.com/v2-c273b73d3c018a_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&672& data-rawheight=&73& class=&origin_image zh-lightbox-thumb& width=&672& data-original=&https://pic4.zhimg.com/v2-c273b73d3c018a_r.jpg&&&/figure&&p&它们的作用相同。AutoJump 会记住 cd 命令并用 j 来进入所有的目录。更重要的是 AutoJump 可以&b&模糊匹配&/b&。意味着只需要提供一个字母,就可以匹配到之前访问过的该首字母的目录。&/p&&p&如果有两个以 p 为开头的目录怎么办?&/p&&p&这就是有趣的地方。&/p&&p&当你第一次输入 cd directory_name,AutoJump 会记录该目录并成为绝对路径,并将其指定权重为 10.0 分。&/p&&p&举个例子:&/p&&figure&&img src=&https://pic2.zhimg.com/v2-2c98fed464_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&670& data-rawheight=&53& class=&origin_image zh-lightbox-thumb& width=&670& data-original=&https://pic2.zhimg.com/v2-2c98fed464_r.jpg&&&/figure&&p&然后输入 j -s 命令可以看到(s 代表统计信息):&/p&&figure&&img src=&https://pic1.zhimg.com/v2-f5bbe7f3f6_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&667& data-rawheight=&46& class=&origin_image zh-lightbox-thumb& width=&667& data-original=&https://pic1.zhimg.com/v2-f5bbe7f3f6_r.jpg&&&/figure&&p&如果你再次 cd/var 后,j -s,看看会发生什么?&/p&&figure&&img src=&https://pic4.zhimg.com/v2-5c1eea55329aa8beb8e4b_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&670& data-rawheight=&51& class=&origin_image zh-lightbox-thumb& width=&670& data-original=&https://pic4.zhimg.com/v2-5c1eea55329aa8beb8e4b_r.jpg&&&/figure&&p&对,这个路径的权重增加了。比如看看我电脑上的 j -s,我平时都在干什么你就会一目了然:&/p&&figure&&img src=&https://pic3.zhimg.com/v2-1bca4646fe_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&673& data-rawheight=&363& class=&origin_image zh-lightbox-thumb& width=&673& data-original=&https://pic3.zhimg.com/v2-1bca4646fe_r.jpg&&&/figure&&p&我第一个campus 和第四个 SodeSchool 都包含字母 c,那么 AutoJump 应该县跳转到哪个目录呢?&/p&&p&由于 campus 权重低,所以会 j c 会跳到 CodeSchool 目录,如果重复 j c 命令,就会跳转到 campus 目录。&/p&&figure&&img src=&https://pic3.zhimg.com/v2-c9b9d705e6a5eea14ebe595_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&670& data-rawheight=&123& class=&origin_image zh-lightbox-thumb& width=&670& data-original=&https://pic3.zhimg.com/v2-c9b9d705e6a5eea14ebe595_r.jpg&&&/figure&&p&如果你不喜欢 AutoJump 自动设置的路径,你可以自己设置匹配:&/p&&figure&&img src=&https://pic3.zhimg.com/v2-bfd292c2a1b2e4347dc8_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&671& data-rawheight=&222& class=&origin_image zh-lightbox-thumb& width=&671& data-original=&https://pic3.zhimg.com/v2-bfd292c2a1b2e4347dc8_r.jpg&&&/figure&&p&你可以设置后面的数字, j c _4 就是 j c 跳转到第四个目录。&/p&&p&&br&&/p&&h2&高级功能&/h2&&ul&&li&jc(注意没空格 不是上面的 j c)仅在子目录下跳转,非常适合寻找被嵌套的 log&/li&&li&jo 会在操作系统下打开匹配的目录。&/li&&li&j -i 增加当前目录权重&/li&&li&j -d 减少当前目录权重&/li&&li&j --purge 消除所有的权重&/li&&/ul&&h2&安装 AutoJump&/h2&&p&AutoJump 支持:&/p&&ul&&li&Python v2.6+(除了 3.2 版本)&/li&&li&支持的 shell:&/li&&li&bash v4.0+&/li&&li&zsh&/li&&li&fish&/li&&li&tcsh (experimental)&/li&&li&clink (Windows, experimental)&/li&&/ul&&p&你可以通过许多 Linux 软件包安装器来安装。对于 MacOS 我推荐 Homebrew 的 brew install autojump,真的超简单方便。&/p&&p&把 Autojump 放在.bash_profile 或者 .szhrc 下,输入命令行:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh
&/code&&/pre&&/div&&p&它会自动检查脚本是否可用并加载到 shell 中。&/p&&p&你也可以克隆 git 仓库,手动安装。不管怎么说,它都是一个非常简单的、稳定的工具。&/p&&p&我用了它的这些年里,从来没有后悔过。&/p&&p&&br&&/p&&h2&&b&&u&下载地址:&a href=&https://link.zhihu.com/?target=https%3A//github.com/wting/autojump& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&wting/autojump&/a&(GitHub)&/u&&/b&&/h2&&hr&&p&园长:翻译完这篇我就马上安装了,最开始还不太习惯,不过感觉确实能快了不少。&/p&&p&&br&&/p&&p&&b&极光日报,&a href=&https://link.zhihu.com/?target=http%3A//y0.cn/6AAFc& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&极光开发者&/a&旗下媒体。&/b&&/p&&p&&b&每天导读三篇英文技术文章。&/b&&/p&&p&&br&&/p&&figure&&img src=&https://pic1.zhimg.com/v2-3ebfbd58bf_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&1474& data-rawheight=&1162& class=&origin_image zh-lightbox-thumb& width=&1474& data-original=&https://pic1.zhimg.com/v2-3ebfbd58bf_r.jpg&&&/figure&&p&&/p&
简评:作为工程师,你在命令行下最常打的命令无非就是 cd 与 ls。这些年你浪费了多少时间?作为一个程序员或者在 shell 中花费大量时间的人,你可能会经常以一种低效率的方式在目录中来回移动,特别是每天经常访问相同目录。比如像这样:当然你可能用的稍微…
&figure&&img src=&https://pic1.zhimg.com/v2-2e2ebf51afdaa06f60c7e89_b.jpg& data-rawwidth=&900& data-rawheight=&500& class=&origin_image zh-lightbox-thumb& width=&900& data-original=&https://pic1.zhimg.com/v2-2e2ebf51afdaa06f60c7e89_r.jpg&&&/figure&&p&本文所有文章内容已同步至GitHub:&a href=&http://link.zhihu.com/?target=https%3A//github.com/xingshaocheng/architect-awesome& class=& external& target=&_blank& rel=&nofollow noreferrer&&&span class=&invisible&&https://&/span&&span class=&visible&&github.com/xingshaochen&/span&&span class=&invisible&&g/architect-awesome&/span&&span class=&ellipsis&&&/span&&/a&&/p&&p&如下是文档内容:&/p&&ul&&li&数据结构&/li&&ul&&li&二叉树&/li&&li&完全二叉树&/li&&li&平衡二叉树&/li&&li&二叉查找树(BST)&/li&&li&红黑树&/li&&li&B-,B+,B*树&/li&&li&LSM 树&/li&&li&队列&/li&&li&集合&/li&&li&链表、数组&/li&&li&字典、关联数组&/li&&li&栈&/li&&li&树&/li&&li&BitSet&/li&&/ul&&li&常用算法&/li&&ul&&li&KPM 算法&/li&&li&选择排序&/li&&li&冒泡排序&/li&&li&插入排序&/li&&li&快速排序&/li&&li&归并排序&/li&&li&希尔排序&/li&&li&堆排序&/li&&li&计数排序&/li&&li&桶排序&/li&&li&基数排序&/li&&li&二分查找&/li&&li&Java 中的排序工具&/li&&li&排序、查找算法&/li&&li&布隆过滤器&/li&&li&字符串比较&/li&&li&深度优先、广度优先&/li&&li&贪心算法&/li&&li&回溯算法&/li&&li&剪枝算法&/li&&li&动态规划&/li&&li&朴素贝叶斯&/li&&li&推荐算法&/li&&li&最小生成树算法&/li&&li&最短路径算法&/li&&/ul&&li&并发&/li&&ul&&li&Java中的锁和同步类&/li&&li&公平锁 & 非公平锁&/li&&li&悲观锁 & 乐观锁 & CAS&/li&&li&ABA 问题&/li&&li&CopyOnWrite容器&/li&&li&RingBuffer&/li&&li&可重入锁 & 不可重入锁&/li&&li&互斥锁 & 共享锁&/li&&li&死锁&/li&&li&事务 ACID 特性&/li&&li&事务的隔离级别&/li&&li&多线程&/li&&li&线程安全&/li&&li&一致性、事务&/li&&li&锁&/li&&/ul&&li&操作系统&/li&&ul&&li&计算机原理&/li&&li&进程&/li&&li&线程&/li&&li&协程&/li&&li&Linux&/li&&/ul&&li&设计模式&/li&&ul&&li&康威定律&/li&&li&设计模式的六大原则&/li&&li&23种常见设计模式&/li&&li&应用场景&/li&&li&单例模式&/li&&li&责任链模式&/li&&li&MVC&/li&&li&IOC&/li&&li&AOP&/li&&li&UML&/li&&li&微服务思想&/li&&/ul&&li&运维 & 统计 & 技术支持&/li&&ul&&li&OpenStack&/li&&li&Docker&/li&&li&KVM&/li&&li&Xen&/li&&li&OpenVZ&/li&&li&TDD 理论&/li&&li&单元测试&/li&&li&压力测试&/li&&li&全链路压测&/li&&li&A/B Test&/li&&li&Ansible&/li&&li&puppet&/li&&li&chef&/li&&li&Jenkins&/li&&li&环境分离&/li&&li&常规监控&/li&&li&APM&/li&&li&统计分析&/li&&li&持续集成(CI/CD)&/li&&li&自动化运维&/li&&li&测试&/li&&li&虚拟化&/li&&li&容器技术&/li&&li&云技术&/li&&li&DevOps&/li&&li&文档管理&/li&&/ul&&li&中间件&/li&&ul&&li&日志搜集&/li&&li&Sharding Jdbc&/li&&li&Dubbo&/li&&li&Thrift&/li&&li&gRPC&/li&&li&单机定时调度&/li&&li&分布式定时调度&/li&&li&消息总线&/li&&li&消息的顺序&/li&&li&RabbitMQ&/li&&li&RocketMQ&/li&&li&ActiveMQ&/li&&li&Kafka&/li&&li&Redis 消息推送&/li&&li&ZeroMQ&/li&&li&Memcached&/li&&li&Redis&/li&&li&Tair&/li&&li&架构&/li&&li&回收策略&/li&&li&本地缓存&/li&&li&Nginx&/li&&li&OpenResty&/li&&li&Apache Httpd&/li&&li&Tomcat&/li&&li&Jetty&/li&&li&架构原理&/li&&li&调优方案&/li&&li&Web Server&/li&&li&缓存&/li&&li&客户端缓存&/li&&li&消息队列&/li&&li&定时调度&/li&&li&RPC&/li&&li&数据库中间件&/li&&li&日志系统&/li&&li&配置中心&/li&&li&API 网关&/li&&/ul&&li&网络&/li&&ul&&li&Hessian&/li&&li&Protobuf&/li&&li&Epoll&/li&&li&NIO&/li&&li&kqueue&/li&&li&OSI 七层协议&/li&&li&TCP/IP&/li&&li&HTTP&/li&&li&HTTP2.0&/li&&li&HTTPS&/li&&li&协议&/li&&li&网络模型&/li&&li&连接和短连接&/li&&li&框架&/li&&li&零拷贝(Zero-copy)&/li&&li&序列化(二进制协议)&/li&&/ul&&li&数据库&/li&&ul&&li&MongoDB&/li&&li&Hbase&/li&&li&原理&/li&&li&InnoDB&/li&&li&优化&/li&&li&索引&/li&&li&explain&/li&&li&聚集索引, 非聚集索引&/li&&li&复合索引&/li&&li&自适应哈希索引(AHI)&/li&&li&数据库设计的三大范式&/li&&li&基础理论&/li&&li&MySQL&/li&&li&NoSQL&/li&&/ul&&li&搜索引擎&/li&&ul&&li&搜索引擎原理&/li&&li&Lucene&/li&&li&Elasticsearch&/li&&li&Solr&/li&&li&sphinx&/li&&/ul&&li&性能&/li&&ul&&li&HDFS&/li&&li&MapReduce&/li&&li&Yarn&/li&&li&Storm&/li&&li&Flink&/li&&li&Kafka Stream&/li&&li&应用场景&/li&&li&性能优化方法论&/li&&li&容量评估&/li&&li&CDN 网络&/li&&li&连接池&/li&&li&性能调优&/li&&li&流式计算&/li&&li&Hadoop&/li&&li&Spark&/li&&/ul&&li&安全&/li&&ul&&li&RBAC&/li&&li&OAuth2.0&/li&&li&内外网分离&/li&&li&登录跳板机&/li&&li&数据备份&/li&&li&对称加密&/li&&li&哈希算法&/li&&li&非对称加密&/li&&li&XSS&/li&&li&CSRF&/li&&li&SQL 注入&/li&&li&Hash Dos&/li&&li&脚本注入&/li&&li&漏洞扫描工具&/li&&li&验证码&/li&&li&web 安全&/li&&li&DDoS 防范&/li&&li&用户隐私信息保护&/li&&li&加密解密&/li&&li&服务器安全&/li&&li&数据安全&/li&&li&网络隔离&/li&&li&授权&/li&&/ul&&li&常用开源框架&/li&&ul&&li&Spring 家族&/li&&li&Log4j、Log4j2&/li&&li&Logback&/li&&li&开源协议&/li&&li&日志框架&/li&&li&ORM&/li&&li&网络框架&/li&&li&Web 框架&/li&&li&工具框架&/li&&/ul&&li&分布式设计&/li&&ul&&li&全局唯一ID&/li&&li&CAP 与 BASE 理论&/li&&li&分布式锁&/li&&li&分布式一致性算法&/li&&li&幂等&/li&&li&分布式一致方案&/li&&li&分布式 Leader 节点选举&/li&&li&TCC(Try/Confirm/Cancel) 柔性事务&/li&&li&PAXOS&/li&&li&Zab&/li&&li&Raft&/li&&li&Gossip&/li&&li&两阶段提交、多阶段提交&/li&&li&服务注册与发现&/li&&li&服务路由控制&/li&&li&读写分离模式&/li&&li&分片模式&/li&&li&硬件负载均衡&/li&&li&软件负载均衡&/li&&li&限流&/li&&li&应用层容灾&/li&&li&跨机房容灾&/li&&li&容灾演练流程&/li&&li&平滑启动&/li&&li&扩展性设计&/li&&li&稳定性 & 高可用&/li&&li&数据库扩展&/li&&li&服务治理&/li&&li&分布式一致&/li&&li&分布式文件系统&/li&&li&唯一ID 生成&/li&&li&一致性Hash算法&/li&&/ul&&li&设计思想 & 开发模式&/li&&ul&&li&命令查询职责分离(CQRS)&/li&&li&贫血,充血模型&/li&&li&DDD(Domain-driven Design - 领域驱动设计)&/li&&li&Actor 模式&/li&&li&响应式编程&/li&&li&DODAF2.0&/li&&li&Serverless&/li&&/ul&&li&项目管理&/li&&ul&&li&架构评审&/li&&li&重构&/li&&li&代码规范&/li&&li&RUP&/li&&li&看板管理&/li&&li&SCRUM&/li&&li&极限编程&/li&&li&敏捷开发&/li&&li&结对编程&/li&&/ul&&li&通用业务术语&/li&&li&技术趋势&/li&&li&架构师素质&/li&&li&团队管理&/li&&ul&&li&招聘&/li&&/ul&&li&资讯&/li&&ul&&li&在线电子书&/li&&li&纸质书&/li&&li&开发方面&/li&&li&架构方面&/li&&li&技术管理方面&/li&&li&基础理论&/li&&li&工具方面&/li&&li&大数据方面&/li&&li&团队博客&/li&&li&个人博客&/li&&li&行业资讯&/li&&li&公众号列表&/li&&li&博客&/li&&li&综合门户、社区&/li&&li&问答、讨论类社区&/li&&li&行业数据分析&/li&&li&专项网站&/li&&li&其他类&/li&&li&推荐参考书&/li&&/ul&&li&技术资源&/li&&ul&&li&开源资源&/li&&li&手册、文档、教程&/li&&li&在线课堂&/li&&li&会议、活动&/li&&li&常用APP&/li&&li&找工作&/li&&li&工具&/li&&li&代码托管&/li&&li&文件服务&/li&&li&综合云服务商&/li&&/ul&&/ul&&p&&b&部门内容截图如下:&/b&&/p&&figure&&img src=&https://pic1.zhimg.com/v2-46accbc0c92d40c5b8b288d8f9aa1790_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&1080& data-rawheight=&622& class=&origin_image zh-lightbox-thumb& width=&1080& data-original=&https://pic1.zhimg.com/v2-46accbc0c92d40c5b8b288d8f9aa1790_r.jpg&&&/figure&&figure&&img src=&https://pic2.zhimg.com/v2-f1b4db5ee46c1_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&1080& data-rawheight=&712& class=&origin_image zh-lightbox-thumb& width=&1080& data-original=&https://pic2.zhimg.com/v2-f1b4db5ee46c1_r.jpg&&&/figure&&figure&&img src=&https://pic4.zhimg.com/v2-1f2b8a58a4921e11bd3f_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&1080& data-rawheight=&876& class=&origin_image zh-lightbox-thumb& width=&1080& data-original=&https://pic4.zhimg.com/v2-1f2b8a58a4921e11bd3f_r.jpg&&&/figure&&figure&&img src=&https://pic1.zhimg.com/v2-05133cdbfcd3b87c9ed008_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&1080& data-rawheight=&886& class=&origin_image zh-lightbox-thumb& width=&1080& data-original=&https://pic1.zhimg.com/v2-05133cdbfcd3b87c9ed008_r.jpg&&&/figure&&figure&&img src=&https://pic2.zhimg.com/v2-2f6da328aadbc932f5cb90d_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&1076& data-rawheight=&871& class=&origin_image zh-lightbox-thumb& width=&1076& data-original=&https://pic2.zhimg.com/v2-2f6da328aadbc932f5cb90d_r.jpg&&&/figure&&p&&b&如何获取地址:&/b&&/p&&p&由于知识点众多,特整理在GitHub上,微信外链限制,无法在文本中直接加上超链接,有需要的欢迎Start/Fork,地址如下:&/p&&p&&b&&a href=&http://link.zhihu.com/?target=https%3A//github.com/xingshaocheng/architect-awesome& class=& external& target=&_blank& rel=&nofollow noreferrer&&&span class=&invisible&&https://&/span&&span class=&visible&&github.com/xingshaochen&/span&&span class=&invisible&&g/architect-awesome&/span&&span class=&ellipsis&&&/span&&/a&&/b&&/p&&p&&a href=&http://link.zhihu.com/?target=https%3A//github.com/xingshaocheng/architect-awesome& class=& external& target=&_blank& rel=&nofollow noreferrer&&&span class=&invisible&&https://&/span&&span class=&visible&&github.com/xingshaochen&/span&&span class=&invisible&&g/architect-awesome&/span&&span class=&ellipsis&&&/span&&/a& (二维码自动识别)&/p&&p&传送门在这里,一键抵达!&/p&
本文所有文章内容已同步至GitHub:如下是文档内容:数据结构二叉树完全二叉树平衡二叉树二叉查找树(BST)红黑树B-,B+,B*树LSM 树队列集合链表、数组字典、关联数组栈树BitSet常用算法KPM 算法选择排序冒泡排序插入排序快速排序归并…
推荐一下 &a href=&//link.zhihu.com/?target=http%3A//aosabook.org/en/index.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&The Architecture of Open Source Applications&/a& 上下两卷。&br&&br&所有内容都在良好排版之后,被公布在他们的网站上供以免费阅读。没有深入细节的东西,全是优秀开源软件的框架设计思路,应该可以满足题主了。&br&&br&如果想要深入到源代码环节,推荐一下Redis、CPython和LLVM。
上下两卷。 所有内容都在良好排版之后,被公布在他们的网站上供以免费阅读。没有深入细节的东西,全是优秀开源软件的框架设计思路,应该可以满足题主了。 如果想要深入到源代码环节,推荐一下Redis…
&p&符号索引是个重要功能,不论阅读新项目,还是开发复杂点的大项目,符号索引都能帮你迅速掌握项目脉络,加快开发进度。传统 ctags 系统虽和 vim 结合紧密,但只能查定义无法查引用,cscope 能查引用,但只支持 C 语言,C++都不支持,况且常年不更新。ctags 由于使用文本格式存储数据,虽用了二分查找,但打开 Linux Kernel 这样的大项目时,查询会有卡顿的感觉。&/p&&p&&a href=&https://link.zhihu.com/?target=https%3A//www.gnu.org/software/global/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&GTags&/a& (或者叫做 GNU GLOBAL)比起 ctags 来说,有几个主要的优点:&/p&&ol&&li&不但能查定义,还能查引用&/li&&li&原生支持 6 种语言(C,C++,Java,PHP4,Yacc,汇编)&/li&&li&扩展支持 50+ 种语言(包括 go/rust/scala 等,基本覆盖所有主流语言)&/li&&li&使用性能更好的本地数据库存储符号,而不是 ctags 那种普通文本文件&/li&&li&支持增量更新,每次只索引改变过的文件&/li&&li&多种输出格式,能更好的同编辑器相集成&/li&&/ol&&p&曾经用过 gtags 的人或许会问,gtags 我都用过好几年了,也没见用出朵花来啊? 现在不管是 vscode 还是 sublime text 或者 emacs ,不都有 gtags 插件了么,要用简单得很,还有比较好的用户体验,你在 vim 下配置半天图啥呢?&/p&&p&答案是,如果还停留在这些传统体验上,那我也没必要写这篇文章了。现实中,大部分人都没有用对 gtags,如果你能够在 Vim 下正确使用 gtags,不但能极大的方便你开发复杂项目或者阅读新项目代码,还能获得比上面所有编辑器更好的体验。&/p&&p&Vim中的符号索引,他真能玩出花来,接下来本文将一步步教你 DIY 一套超越市面上任何编辑器(vscode,emacs,vscode)体验的最强静态符号索引系统。&/p&&p&&br&&/p&&p&&b&正确安装 GTags&/b&&/p&&p&请首先安装最新版本 gtags,目前版本是 6.6.2,Windows 下可到 &a href=&https://link.zhihu.com/?target=http%3A//adoxa.altervista.org/global/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&[这里]&/a& 下载可执行,Linux 下请自行编译最新版(Debian / Ubuntu 自带的都太老了),Mac 下检查下 brew 安装的版本至少不要低于 6.6.0 ,否则请自己编译。&/p&&p&只写 C/C++/Java 的话,那么到这里就够了,gtags 原生支持。如想要更多语言,那么 gtags 是支持使用 ctags/universal-ctags 或者 pygments 来作为分析前端支持 50+ 种语言。使用 ctags/universal-ctags 作为前端只能生成定义索引不能生成引用索引,因此我们要安装 pygments ,保证你的 $PATH 里面有 python,接着:&/p&&div class=&highlight&&&pre&&code class=&language-bash&&&span&&/span&pip install pygments
&/code&&/pre&&/div&&p&保证 Vim 里要设置过两个环境变量才能正常工作:&/p&&div class=&highlight&&&pre&&code class=&language-vim&&&span&&/span&&span class=&k&&let&/span& $GTAGSLABEL &span class=&p&&=&/span& &span class=&s1&&'native-pygments'&/span&
&span class=&k&&let&/span& $GTAGSCONF &span class=&p&&=&/span& &span class=&s1&&'/path/to/share/gtags/gtags.conf'&/span&
&/code&&/pre&&/div&&p&第一个 GTAGSLABEL 告诉 gtags 默认 C/C++/Java 等六种原生支持的代码直接使用 gtags 本地分析器,而其他语言使用 pygments 模块。&/p&&p&第二个环境变量必须设置,否则会找不到 native-pygments 和 language map 的定义, Windows 下面在 gtags/share/gtags/gtags.conf,Linux 下要到 /usr/local/share/gtags 里找,也可以把它拷贝成 ~/.globalrc ,Vim 配置的时候方便点。&/p&&p&实际使用 pygments 时,gtags 会启动 python 运行名为 pygments_parser.py 的脚本,通过管道和它通信,完成源代码分析,故需保证 gtags 能在 $PATH 里调用
python,且这个 python 安装了 pygments 模块。&/p&&p&正确安装后,可以通过命令行 gtags 命令和 global 进行测试,注意shell 下设置环境变量。&/p&&p&&br&&/p&&p&&b&自动生成 Gtags&/b&&/p&&p&VSCode 中的 C++ Intellisense 插件就是使用 Gtags 来提供 intellisense 的,但是它有两个非常不好用的地方:&/p&&ul&&li&代码修改了需要自己手动去运行 gtags ,更新符号索引&/li&&li&会在代码目录下生成:GTAGS,GRTAGS,GPATH 三个文件,污染我的项目目录&/li&&/ul&&p&第一条是我过去几次使用 gtags 最头疼的一个问题;第二条也蛋疼,碍眼不说,有时不小心就把三个文件提交到代码仓库里了,极端讨厌。&/p&&p&那么 Vim 8 下有无更优雅的方式,自动打点好 gtags 三个文件,放到一个统一的地方,并且文件更新了自动帮我更新数据,让我根本体验不倒 gtags 的这些负担,完全流畅的使用 gtags 的各种功能呢?&/p&&p&当然有,使用我在《&a href=&https://www.zhihu.com/question//answer/& class=&internal&&韦易笑:如何在 Linux 下利用 Vim 搭建 C/C++ 开发环境?&/a&》中介绍过的 &a href=&https://link.zhihu.com/?target=https%3A//github.com/ludovicchabant/vim-gutentags& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&gutentags&/a& 插件来打理,它不但能根据文件改动自动生成 ctags 数据,还能帮我们自动更新 gtags 数据,稍微扩充一下上文的配置,让 gutentags 同时支持
ctags/gtags:&/p&&div class=&highlight&&&pre&&code class=&language-vim&&&span&&/span&&span class=&c&&& gutentags 搜索工程目录的标志,当前文件路径向上递归直到碰到这些文件/目录名&/span&
&span class=&k&&let&/span& &span class=&k&&g&/span&:gutentags_project_root &span class=&p&&=&/span& [&span class=&s1&&'.root'&/span&&span class=&p&&,&/span& &span class=&s1&&'.svn'&/span&&span class=&p&&,&/span& &span class=&s1&&'.git'&/span&&span class=&p&&,&/span& &span class=&s1&&'.hg'&/span&&span class=&p&&,&/span& &span class=&s1&&'.project'&/span&]
&span class=&c&&& 所生成的数据文件的名称&/span&
&span class=&k&&let&/span& &span class=&k&&g&/span&:gutentags_ctags_tagfile &span class=&p&&=&/span& &span class=&s1&&'.tags'&/span&
&span class=&c&&& 同时开启 ctags 和 gtags 支持:&/span&
&span class=&k&&let&/span& &span class=&k&&g&/span&:gutentags_modules &span class=&p&&=&/span& []
&span class=&k&&if&/span& executable&span class=&p&&(&/span&&span class=&s1&&'ctags'&/span&&span class=&p&&)&/span&
&span class=&k&&let&/span& &span class=&k&&g&/span&:gutentags_modules &span class=&p&&+=&/span& [&span class=&s1&&'ctags'&/span&]
&span class=&k&&endif&/span&
&span class=&k&&if&/span& executable&span class=&p&&(&/span&&span class=&s1&&'gtags-cscope'&/span&&span class=&p&&)&/span& && executable&span class=&p&&(&/span&&span class=&s1&&'gtags'&/span&&span class=&p&&)&/span&
&span class=&k&&let&/span& &span class=&k&&g&/span&:gutentags_modules &span class=&p&&+=&/span& [&span class=&s1&&'gtags_cscope'&/span&]
&span class=&k&&endif&/span&
&span class=&c&&& 将自动生成的 ctags/gtags 文件全部放入 ~/.cache/tags 目录中,避免污染工程目录&/span&
&span class=&k&&let&/span& &span class=&k&&g&/span&:gutentags_cache_dir &span class=&p&&=&/span& expand&span class=&p&&(&/span&&span class=&s1&&'~/.cache/tags'&/span&&span class=&p&&)&/span&
&span class=&c&&& 配置 ctags 的参数&/span&
&span class=&k&&let&/span& &span class=&k&&g&/span&:gutentags_ctags_extra_args &span class=&p&&=&/span& [&span class=&s1&&'--fields=+niazS'&/span&&span class=&p&&,&/span& &span class=&s1&&'--extra=+q'&/span&]
&span class=&k&&let&/span& &span class=&k&&g&/span&:gutentags_ctags_extra_args &span class=&p&&+=&/span& [&span class=&s1&&'--c++-kinds=+px'&/span&]
&span class=&k&&let&/span& &span class=&k&&g&/span&:gutentags_ctags_extra_args &span class=&p&&+=&/span& [&span class=&s1&&'--c-kinds=+px'&/span&]
&span class=&c&&& 如果使用 universal ctags 需要增加下面一行&/span&
&span class=&k&&let&/span& &span class=&k&&g&/span&:gutentags_ctags_extra_args &span class=&p&&+=&/span& [&span class=&s1&&'--output-format=e-ctags'&/span&]
&span class=&c&&& 禁用 gutentags 自动加载 gtags 数据库的行为&/span&
&span class=&k&&let&/span& &span class=&k&&g&/span&:gutentags_auto_add_gtags_cscope &span class=&p&&=&/span& &span class=&m&&0&/span&
&/code&&/pre&&/div&&p&通过上面的配置,可以在后台自动打理 ctags 和 gtags 数据库,检测文件改动,并更新到 ~/.cache/tags 目录中,避免污染你的项目目录。&/p&&p&上面定义了项目标志文件(.git, .svn, .root, .project, .hg),gutentags 需要确定当前文件所属的项目目录,会从当前文件所在目录开始向父目录递归,直到找到这些标志文件。如果没有,则 gutentags 认为该文件是个野文件,不会帮它生成 ctags/gtags 数据,这也很合理,所以如果你的项目不在 svn/git/hg 仓库中的话,可以在项目根目录 touch 一个空的名为 .root 的文件即可。&/p&&p&现在我们在 Vim 中随便编辑文件,gtags 数据库就会默默的帮我们生成好了,如果你使用 airline ,还能再 airline 上看到生成索引的状态。gtags 程序包里有个 gtags-cscope 的程序,可用 cscope 的接口来为 Vim 提供 cscope 的所有操作,只需要再 vim 中修改一下 cscopeprg 指向这个 gtags-cscope 程序,就可以 cs add 添加 gtags 数据库,然后像 cscope一样的使用 gtags 了。&/p&&p&Vim 里原有的 cscope 机制可以设定好数据文件后,启动一个 cscope 进程并用管道和其链接,通过管道命令实现定义和引用的查询,你修改了 cscopeprg 指向 gtags-cscope 后,就可以在 Vim 中用 :cs add path 命令启动 gtags-cscope 这个子进程,链接 gtags 的数据库,然后提供全套 cscope 类似的操作。&/p&&p&gtags-cscope 还有一个优点就是我后台更新了 gtags 数据库,不需要像 cscope 一样调用 cs reset 重启 cscope 子进程,gtags-cscope 一旦连上永远不用重启,不管你啥时候更新数据库,gtags-cscope 进程都能随时查找最新的符号。&/p&&p&那么最后临门一脚,我们将要想办法避免这个手工 cs add 的过程。&/p&&p&&br&&/p&&p&&b&数据库自动切换&/b&&/p&&p&gutentags 可以为我们自动 cs add 命令添加当前更新好的 gtags 数据库到 vim ,但是你编辑一个项目还好,如果你同时编辑两个以上的项目,gutentags 会把两个数据库都连接到 vim 里,于是你搜索一个符号,两个项目的结果都会同时出现,基本没法用了。&/p&&p&所以上面的配置中禁用了 gutentags 自动加载,我们可以每次查询单独执行一遍外部的 gtags-cscope 工具,将结果放到 quickfix。这样做可以避免项目之间结果混在一起,启动前配好项目目录和数据库目录,查询完就退出,稍微封装下即可,唯一问题就是用起来有点慢。&/p&&p&更好的方法是继续使用 vim 自带 cscope 系统,并解决好数据库链接断开问题:首先要能找到当前文件所属项目的 gtags 数据库被 gutentags 放到哪里了,其次一开始用不着 cs add 加载任何 gtags 数据库,只有在真正查询前增加个检测:&/p&&ol&&li&如果当前项目数据库已经添加过,就继续开始查询工作。&/li&&li&没有添加的话就断开其他所有项目的 gtags 数据库,再添加本项目数据库。&/li&&/ol&&p&过程说起来很复杂,用起来却很简单,我写了个 &a href=&https://link.zhihu.com/?target=https%3A//github.com/skywind3000/gutentags_plus& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&gutentags_plus.vim&/a& 的小脚本做这个事,直接用里面的 GscopeFind 命令,像 cs find 一样用就行了。&/p&&p&搭配 gutentags,这个脚本在你每次 GscopeFind 前帮你处理数据库加载问题,已经加载过的数据库不会重复加载,非本项目的数据库会得到即时清理,所以你根本感觉不到 gtags 的存在,只管始用 GscopeFind g 命令查找定义,GscopeFind s 命令查找引用,既不用 care gtags 数据库加载问题更不用关心何时更新,你只管写你的代码,打开你要阅读的项目,随时都能通过 GscopeFind 查询最新结果,并放入 quickfix 窗口中:&/p&&figure&&img src=&https://pic2.zhimg.com/v2-f0cbbf0efe6bfb33d5ad5e_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&1112& data-rawheight=&715& class=&origin_image zh-lightbox-thumb& width=&1112& data-original=&https://pic2.zhimg.com/v2-f0cbbf0efe6bfb33d5ad5e_r.jpg&&&/figure&&p&这个小脚本末尾还还定义了一系列快捷键:&/p&&ul&&li&&leader&cg
- 查看光标下符号的定义&/li&&li&&leader&cs
- 查看光标下符号的引用&/li&&li&&leader&cc
- 查看有哪些函数调用了该函数&/li&&li&&leader&cf
- 查找光标下的文件&/li&&li&&leader&ci
- 查找哪些文件 include 了本文件&/li&&/ul&&p&比如打开 Linux 代码树,memory.c 光标停留在 core_initcall 函数名上面,然后 &leader&cc,下面 quickfix 窗口立马就列出了调用过该函数的位置。&/p&&p&得益于 gtags 的数据存储格式,再大的项目,也能给你瞬间完成查询,得益于 gtags-cscope 的接口,vim中可以对同一个项目持续服用相同的 gtags-cscope 子进程,采用管道通信,避免同项目多次查询不断的启动新进程,查询毫无卡顿。&/p&&p&到此为止,我们在 vim 中 DIY 了一个比 vscode 流畅得多的符号索引体验,无缝结合 gtags 的程度超过以往任何编辑器,让你象在 IDE 里一样毫无负担的查找定义和引用,而IDE 只支持一两种语言,咱们起步就覆盖 50+ 种语言。&/p&&p&&br&&/p&&p&&b&快速预览&/b&&/p&&p&我们从新项目仓库里查询了一个符号的引用,gtags噼里啪啦的给了你二十多个结果,那么多结果顺着一个个打开,查看,关闭,再打开很蛋疼,可使用 &a href=&https://link.zhihu.com/?target=https%3A//github.com/skywind3000/vim-preview& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&vim-preview&/a& 插件高效的在 quickfix 中先快速预览所有结果,再有针对性的打开必要文件:&/p&&figure&&img src=&https://pic2.zhimg.com/v2-9a90d56b8e53aa_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&1260& data-rawheight=&759& class=&origin_image zh-lightbox-thumb& width=&1260& data-original=&https://pic2.zhimg.com/v2-9a90d56b8e53aa_r.jpg&&&/figure&&p&按照插件文档配置 keymap,就可以在quickfix中对应结果那一行,按 p键在右边打开预览窗口查看文件,多次按 p预览多个文件都会固定在右侧的预览窗口显示,不会打开新窗口或tab,更不会切走当前文件,也不用你因为预览新结果而要在文件窗口和 quickfix 窗口中来回切换,即便你想上下滚动预览窗口里的代码,也可以不用离开quickfix窗口,直接 alt+U/D 就可以在 quickfix 中遥控 preview 窗口上下滚屏了。&/p&&p&当你阅读完预览内容可以用大写 P 关闭预览窗口,然后正常用回车在新窗口或者tab中打开想要具体操作的文件了,这依赖 switchbuf 设置可以看vim帮助文档,不想看了 F10 关闭 quickfix 窗口就是。&/p&&p&搭配前文介绍过的 vim-unimpaired 插件,你还可以在不操作 quickfix窗口的情况下,使用快捷键进行上下结果跳转,Vim的好处在于有比较多的标准基础组件,比如 quickfix,emacs 就没有这样的基础设施,虽然 elisp 都可以实现,每个插件各自实现了一个差不多的 quickfix 窗口,碎片化严重,无法像vim那样一些插件往 quickfix里填充数据,一些插件提供 quickfix 方便的预览和跳转,还有一些插件可以根据quickfix里的结果内容做进一步的处理和响应,他们搭配在一起能够形成合力,这在碎片化严重的 emacs 里是看不到的。&/p&&p&通过上面的一系列 DIY,我们陆续解决了:按需自动索引,数据库自动连接以及结果快速预览等以往使用 gtags 的痛点问题,反观其他编辑器,符号索引功能或多或少都有这样那样不如意的地方。&/p&&p&所以如果你想得到这样一个其他编辑器从没达到过的IDE级别的符号索引系统,又能支持比IDE更多语言,那么花点时间DIY 一下也是值得的。&/p&&p&&br&&/p&&p&接下来我们谈 Language Server:&/p&&p&&a href=&https://zhuanlan.zhihu.com/p/& class=&internal&&韦易笑:Vim 8 中 C/C++ 符号索引:LSP 篇&/a&&/p&&p&&br&&/p&&p&----&/p&&p&&b&错误排查&/b&:gutentags: gutentags: gtags-cscope job failed, returned: 1&/p&&p&这说明 gtags 在生成数据时出错了&/p&&p&第一步:判断 gtags 为何失败,需进一步打开日志,查看 gtags 的错误输出:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&let g:gutentags_define_advanced_commands = 1
&/code&&/pre&&/div&&p&先在 vimrc 中添加上面这一句话,允许 gutentags 打开一些高级命令和选项。然后打开你出错的源文件,运行 “:GutentagsToggleTrace”命令打开日志,它会将 ctags/gtags 命令的输出记录在 Vim 的 message 记录里。接着保存一下当前文件,触发 gtags 数据库更新,稍等片刻你应该能看到一些讨厌的日志输出,然后当你碰到问题时在 vim 里调用 &:messages& 命令列出所有消息记录,即可看到 gtags 的错误输出,方便你定位。&/p&&p&第二步:禁用 pygments,将环境变量改为:&/p&&div class=&highlight&&&pre&&code class=&language-vim&&&span&&/span&&span class=&k&&let&/span& $GTAGSLABEL&span class=&p&&=&/span&&span class=&s1&&'native'&/span&
&/code&&/pre&&/div&&p&然后调试纯 C/C++ 项目看是否工作。&/p&&p&第三步:恢复 pygments 设置,并在项目根目录命令行运行:&/p&&div class=&highlight&&&pre&&code class=&language-bash&&&span&&/span&$ &span class=&nb&&export&/span& &span class=&nv&&GTAGSLABEL&/span&&span class=&o&&=&/span&native-pygments
&/code&&/pre&&/div&&p&看是否正常工作,如果 pygments_parser.py 报错,则修正一下,6.6.2 的 pygments_parser.py 在 Windows 下面有个文件名大小写的小 bug,需要手工更改一下:&/p&&div class=&highlight&&&pre&&code class=&language-python&&&span&&/span&
&span class=&k&&def&/span& &span class=&nf&&get_lexer_by_langmap&/span&&span class=&p&&(&/span&&span class=&bp&&self&/span&&span class=&p&&,&/span& &span class=&n&&path&/span&&span class=&p&&):&/span&
&span class=&n&&ext&/span& &span class=&o&&=&/span& &span class=&n&&os&/span&&span class=&o&&.&/span&&span class=&n&&path&/span&&span class=&o&&.&/span&&span class=&n&&splitext&/span&&span class=&p&&(&/span&&span class=&n&&path&/span&&span class=&p&&)[&/span&&span class=&mi&&1&/span&&span class=&p&&]&/span&
&span class=&n&&lang&/span& &span class=&o&&=&/span& &span class=&bp&&self&/span&&span class=&o&&.&/span&&span class=&n&&langmap&/span&&span class=&p&&[&/span&&span class=&n&&ext&/span&&span class=&p&&]&/span&
&span class=&k&&if&/span& &span class=&n&&lang&/span&&span class=&p&&:&/span&
&span class=&n&&name&/span& &span class=&o&&=&/span& &span class=&n&&lang&/span&&span class=&o&&.&/span&&span class=&n&&lower&/span&&span class=&p&&()&/span&
&span class=&k&&if&/span& &span class=&n&&name&/span& &span class=&ow&&in&/span& &span class=&n&&LANGUAGE_ALIASES&/span&&span class=&p&&:&/span&
&span class=&n&&name&/span& &span class=&o&&=&/span& &span class=&n&&LANGUAGE_ALIASES&/span&&span class=&p&&[&/span&&span class=&n&&name&/span&&span class=&p&&]&/span&
&span class=&n&&lexer&/span& &span class=&o&&=&/span& &span class=&n&&pygments&/span&&span class=&o&&.&/span&&span class=&n&&lexers&/span&&span class=&o&&.&/span&&span class=&n&&get_lexer_by_name&/span&&span class=&p&&(&/span&&span class=&n&&name&/span&&span class=&p&&)&/span&
&span class=&k&&return&/span& &span class=&n&&lexer&/span&
&span class=&k&&return&/span& &span class=&bp&&None&/span&
&/code&&/pre&&/div&&p&第三行有问题,项目目录中存在类似一个大写的 .Bat 文件名就会出错,前面做了大小写判断,觉得它支持,后面又没转换大小写检测,不用 pygments 就没问题,我正向官方反馈,官方修正前,需要改为:&/p&&div class=&highlight&&&pre&&code class=&language-python&&&span&&/span&
&span class=&n&&lang&/span& &span class=&o&&=&/span& &span class=&bp&&self&/span&&span class=&o&&.&/span&&span class=&n&&langmap&/span&&span class=&o&&.&/span&&span class=&n&&get&/span&&span class=&p&&(&/span&&span class=&n&&ext&/span&&span class=&p&&)&/span&
&/code&&/pre&&/div&&p&&br&&/p&&p&还有问题,请到 gitter 群里 at 我 skywind3000,一般都能 at 得到。&/p&&p&&a href=&https://link.zhihu.com/?target=https%3A//gitter.im/vim-china/Lobby& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&vim-china/Lobby&/a&&/p&
符号索引是个重要功能,不论阅读新项目,还是开发复杂点的大项目,符号索引都能帮你迅速掌握项目脉络,加快开发进度。传统 ctags 系统虽和 vim 结合紧密,但只能查定义无法查引用,cscope 能查引用,但只支持 C 语言,C++都不支持,况且常年不更新。ctags …
&p&Facebook的开源基础库Folly(&a href=&//link.zhihu.com/?target=https%3A//github.com/facebook/folly/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&GitHub - facebook/folly: An open-source C++ library developed and used at Facebook.&/a&) 还是非常值得看的。这是Facebook内部广泛使用的可重复C++库组件大集合。也是最近几年C++领域难得的高质量库。&/p&&br&&p&一方面,Folly直接采用C++ 11新标准,在coding guidelines、best practices 方面Folly做了一个榜样。&/p&&br&&p&另一方面,Folly对大规模高性能有很多支持,可谓这方面的基础库标杆。虽然STL BOOST性能已经上乘,但能有Folly这样对large-scale 的软件 performance近乎变态的追求的,还是比较少见,而且显然是industry-level的。在这方面是对STL与BOOST的有效补充。&/p&&br&&p& 另外,不得不提一下,领导Folly库的核心人物是C++社群的大神Andrei Alexandrescu,玩过C++的朋友,应该都知道Andrei的鼎鼎大名。《Modern C++ Design》,和Jolt大奖图书《C++ Coding Standards》的作者。开创了Modern C++ 代码风格的鼻祖。也是D语言之父。&/p&&br&&p&最后,顺便做一个 推荐,大神Andrei Alexandrescu和C++之父将出席 10月28-29日在上海举办的“&/p&&a href=&//link.zhihu.com/?target=http%3A//www.cpp-summit.org/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&2016 C++及系统软件技术大会&/a&, Andrei Alexandrescu 本人将有精彩演讲。并在会前10月27日有一个高干货的培训:&a href=&//link.zhihu.com/?target=http%3A//www.cpp-summit.org/training/fastware& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&《大规模系统软件性能优化》高端培训&/a&,感兴趣的朋友可以看看。
Facebook的开源基础库Folly() 还是非常值得看的。这是Facebook内部广泛使用的可重复C++库组件大集合。也是最近几年C++领域难得的高质量库。 一方面,Folly直接采用C…
&p&刚开始用vim写python的时候,感觉很不方便,于是就用了图形界面的&a href=&//link.zhihu.com/?target=https%3A//www.jetbrains.com/pycharm/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Pycharm&/a&(如果是windows用户,这个IDE应该是标配),用了一段时间也没有觉得有什么不好,不过,脑子里总是会想起《&a href=&//link.zhihu.com/?target=http%3A//book.douban.com/subject/1152111/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&程序员修炼之道&/a&》中,那句”最好是精通一种编辑器,并将其用于所有编辑任务。如果不坚持使用一种编辑器,可能会面临现代的巴别特大混乱。”所以,&em&我又决定用vim来写python&/em&。&/p&&br&&p&在知乎上有很多&a href=&http://www.zhihu.com/question/& class=&internal&&vim写python的插件&/a&推荐,不过我感觉很多人回答都不动脑子,这些回答主要有两个问题:&/p&&ol&&li&回答不全面,很多人都只是推荐一款插件,然后贴个链接就完了,如果要想很爽的用vim写python,可以肯定的是,一款插件是不够的&/li&&li&贴上自己的配置,说自己的配置有多爽,然后就不管了。如果是一个vim新手,是用不着这么多配置的,如果是一个vim老手,也不会放弃自己原有的配置,使用别人自定义、认为很爽的个性化配置&/li&&/ol&&br&&p&所以,这些回答都不是很靠谱。我争取推荐一些靠谱的东西,那么,就开始吧!&/p&&br&&b&1. 一键执行&/b&&br&&p&这个不是插件,而是一个自定义的vim配置。很多时候我们写python,都是写一些较为简单的脚本,那么,这个一键执行的功能就非常实用,我个人感觉最实用的是在写单元测试的时候,写完一个单元测试,都不用退出vim,立即执行就能看到结果。&/p&&p&将下面的配置放到.vimrc文件即可:&/p&&br&&br&&div class=&highlight&&&pre&&code class=&language-vim&&&span class=&c&&
&&&&&&&&&&&&&&&&&&&&&&&/span&
&span class=&c&&
&Quickly Run&/span&
&span class=&c&&
&&&&&&&&&&&&&&&&&&&&&&&/span&
map &span class=&p&&&&/span&F5&span class=&p&&&&/span& :&span class=&k&&call&/span& CompileRunGcc&span class=&p&&()&&/span&CR&span class=&p&&&&/span&
func&span class=&p&&!&/span& CompileRunGcc&span class=&p&&()&/span&
exec &span class=&s2&&&w&&/span&
&span class=&k&&if&/span& &&span class=&k&&filetype&/span& &span class=&p&&==&/span& &span class=&s1&&'c'&/span&
exec &span class=&s2&&&!g++ % -o %&&&/span&
exec &span class=&s2&&&!time ./%&&&/span&
&span class=&k&&elseif&/span& &&span class=&k&&filetype&/span& &span class=&p&&==&/span& &span class=&s1&&'cpp'&/span&
exec &span class=&s2&&&!g++ % -o %&&&/span&
exec &span class=&s2&&&!time ./%&&&/span&
&span class=&k&&elseif&/span& &&span class=&k&&filetype&/span& &span class=&p&&==&/span& &span class=&s1&&'java'&/span&
exec &span class=&s2&&&!javac %&&/span&
exec &span class=&s2&&&!time java %&&&/span&
&span class=&k&&elseif&/span& &&span class=&k&&filetype&/span& &span class=&p&&==&/span& &span class=&s1&&'sh'&/span&
:&span class=&p&&!&/span&time bash %
&span class=&k&&elseif&/span& &&span class=&k&&filetype&/span& &span class=&p&&==&/span& &span class=&s1&&'python'&/span&
exec &span class=&s2&&&!time python2.7 %&&/span&
&span class=&k&&elseif&/span& &&span class=&k&&filetype&/span& &span class=&p&&==&/span& &span class=&s1&&'html'&/span&
exec &span class=&s2&&&!firefox % &&&/span&
&span class=&k&&elseif&/span& &&span class=&k&&filetype&/span& &span class=&p&&==&/span& &span class=&s1&&'go'&/span&
&span class=&c&&
exec &!go build %&&&/span&
exec &span class=&s2&&&!time go run %&&/span&
&span class=&k&&elseif&/span& &&span class=&k&&filetype&/span& &span class=&p&&==&/span& &span class=&s1&&'mkd'&/span&
exec &span class=&s2&&&!~/.vim/markdown.pl % & %.html &&&/span&
exec &span class=&s2&&&!firefox %.html &&&/span&
&span class=&k&&endif&/span&
&/code&&/pre&&/div&&b&2. 代码补全(snipMate)&/b&&br&&p&代码补全能够显著地减少你敲键的次数,并且将你从琐碎的语法中解放出来。说白了,就是帮你写代码!&/p&&br&&p&如果使用snipMate插件,那么,当你输入ifmain以后按tab键,将会自动为你生成下面的代码:&/p&&br&&div class=&highlight&&&pre&&code class=&language-python&&
&span class=&k&&if&/span& &span class=&n&&__name__&/span& &span class=&o&&==&/span& &span class=&s&&'__main__'&/span&&span class=&p&&:&/span&
&span class=&n&&main&/span&&span class=&p&&()&/span&
&/code&&/pre&&/div&&p&输入for,再按tab键,生成如下代码:&/p&&br&&div class=&highlight&&&pre&&code class=&language-pycon&&&span class=&go&&
for needle in haystack:&/span&
&span class=&go&&
# code...&/span&
&/code&&/pre&&/div&&br&&p&代码补全有两款插件都比较不错,可以根据自己的需要进行选择:&/p&&ol&&li&&a href=&//link.zhihu.com/?target=https%3A//github.com/garbas/vim-snipmate& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&snipMate&/a&&/li&&li&&a href=&//link.zhihu.com/?target=https%3A//github.com/drmingdrmer/xptemplate& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&xptemplate&/a&&/li&&/ol&&b&3. 语法检查(Syntastic)&/b&&br&&p&&a href=&//link.zhihu.com/?target=https%3A//github.com/scrooloose/syntastic& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&syntastic&/a&是一款强大的语法检查插件,当你保存源文件时,它就会执行,并提示用户哪些代码存在语法错误,哪些代码风格不符合规范,并给出具体的提示。&/p&&p&例如,python代码风格默认设置为PEP8,即使你不知道PEP8的风格,只要你使用syntastic插件,并根据它给出的提示修改,那么,你就能写出完全符合PEP8风格的代码!&/p&&br&&b&4. 编程提示(jedi-vim)&/b&&br&&p&&a href=&//link.zhihu.com/?target=https%3A//github.com/davidhalter/jedi-vim& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&jedi-vim&/a&是基于jedi的自动补全插件,与Syntastic 不同的是,该插件更加智能,更贴切的称呼是”编程提示”,而不是代码补全插件。&/p&&br&&p&如下图所示:&/p&&figure&&img src=&https://pic3.zhimg.com/50/v2-ee6ec410fbc783fb6f4e151d_b.jpg& data-rawwidth=&1366& data-rawheight=&768& class=&origin_image zh-lightbox-thumb& width=&1366& data-original=&https://pic3.zhimg.com/50/v2-ee6ec410fbc783fb6f4e151d_r.jpg&&&/figure&&br&&p&可以说,这个插件是写vim的标配,并且,真正让vim写python变成一件轻松愉快的事情。&/p&&p&&em&注意:&/em& 安装惊jedi-vim插件,需要在电脑中安装jedi,根据jedi-vim给出的提示,正常按装即可。不过我之前遇到一个问题,在公司的虚拟机里面,安装以后不起作用,google了半天没有成功,最后更新了一下vim就可以了,希望遇到相同问题的人,能够看到。&/p&&br&&br&&div class=&highlight&&&pre&&code class=&language-text&&sudo aptitude install vim-gnome vim vim-common vim-tiny
&/code&&/pre&&/div&&br&&br&至于调试,难道你们不是用ipdb的吗?如果不是,赶紧用用,你们会喜欢的。
刚开始用vim写python的时候,感觉很不方便,于是就用了图形界面的(如果是windows用户,这个IDE应该是标配),用了一段时间也没有觉得有什么不好,不过,脑子里总是会想起《》中,那句”最好是精通一种编辑器,并将其用于所有编辑任务。…
我觉得对普通的程序员来说,编译原理里面有实际用途的,是parser和codegen,但是因为这两个领域,到了2016年都没什么好研究的了,而且也被搞PLT的人所鄙视,所以你们看到的那些经典的教材,都没有好好讲。&br&&br&在这里我隆重推荐,一行代码、一句公式都没有,但是却什么都讲明白了的:《Parsing Techniques》。第一版官网免费下载,第二版多出来的东西你们用不上不用看了。全书只讲parsing,没有后端的任何废话(逃&br&&br&人们可能会说,现在做parser的工具这么多,学这些有用吗?当然有用。数据结构都被封装好了,你们不还是要学过一遍,才能把别人的库用得高效。做parser也一样,没有受过训练的人,很容易语法总结成屎,或者因为想象力不够而无法实现自己的需求。&br&&br&至于要是哪天真的需要做后端了,多半还是随便看点资料(如Engineering a Compiler),知道点优化的概念和架构的知识,然后直接用LLVM干了。
我觉得对普通的程序员来说,编译原理里面有实际用途的,是parser和codegen,但是因为这两个领域,到了2016年都没什么好研究的了,而且也被搞PLT的人所鄙视,所以你们看到的那些经典的教材,都没有好好讲。 在这里我隆重推荐,一行代码、一句公式都没有,但…
&figure&&img src=&https://pic3.zhimg.com/43aae900dec41c_b.jpg& data-rawwidth=&900& data-rawheight=&557& class=&origin_image zh-lightbox-thumb& width=&900& data-original=&https://pic3.zhimg.com/43aae900dec41c_r.jpg&&&/figure&&p&(一)&/p&&br&&p&在前几日的文章『软件随想录』里,我随性写了一句:「现在似乎已经不是lex/yacc 或 bison/flex的时代了。我亲眼看见一个同事在费力地用perl一行行解析某个系统的数据文件,却压根没想到写个BNF。BNF对他来说,不是一种选择。」&/p&&br&&p&很多同学不解,问我:lex/yacc不是写编译器 [&a href=&#_footnote_1&&1&/a&] 的么?我又不发明新的语言,它们对我有什么用?&/p&&br&&p&从这个问题里,我们可以见到国内本科教育荼毒之深。象牙塔里的讲编译原理的老师们,估计用lex/yacc也就是写过个毫无用处的toy language,然后把自己的一知半解传递给了他们的学生,学生们学得半通不通,兴趣索然,考完试之后便把死记硬背的内容如数奉还给了老师。&/p&&br&&p&别笑,我还真就是这么过来的。我用lex/yacc干的唯一一件事,就是TMD设计一个语言。&/p&&br&&p&这世间的语言如此之多,实在容不下我等庸人再设计一门蹩脚的,捉急的,没有颜值,没有性能的语言。况且2000年左右的时候还没有LLVM这种神器,也没有github这样的冥想盆去「偷」别人的思想,设计出来的蹩脚语言只能到语法分析这一步就停下来,没有任何实际用处。&/p&&br&&p&后来lex/yacc进化成flex/bison,在工作中我也无意中翻看了一本orelley叫『Flex & Bison』的书,这书的副标题赫然写着:text processing tools。&/p&&br&&p&书的内容还是挺教条的,和实际的工作内容略微脱节,可text processing tools这个说法戳中了我:是啊,词法分析 - lexical parsing(lex/flex),语法分析 - grammar parsing(yacc/bison)只是更好的文本处理工具(parser),是个高效处理带有语法的文本的DSL(Domain Specific Language)!它们和编译器没有半毛钱关系,只不过,它们的某一个应用场景是和编译器有关罢了。我们不必将其想得过于高深!&/p&&br&&p&我们想想文本处理有什么工具?&/p&&br&&p&Regular expression!&/p&&br&&p&如今的编程语言,有哪个不支持regular expression呢?同样的,如今的程序员,哪个不用使用(没在代码里使用)regular expression呢?&/p&&br&&p&Regular expression也是一种文本处理工具,也是个DSL,只不过,它处理不了复杂的语法。&/p&&br&&p&我们知道,自动化理论(automata theory)里,有FSA(Finite State Automata)和PDA(PushDown Automata),前者可以用regular expression表述,而后者可以处理CFG(Context Free Grammar)。而CFG便是flex/bison要处理的对象!&/p&&br&&p&遗憾的是,大部分语言都没有内置对CFG的处理,一旦文本处理的复杂度超过了regular expression可以表述的复杂度,我们便无能为力。举个例子,如果要你解析这样一段文本,你该怎么做?&/p&&br&&figure&&img src=&https://pic4.zhimg.com/476d39e8d7fd88da961f5f_b.jpg& data-rawwidth=&491& data-rawheight=&222& class=&origin_image zh-lightbox-thumb& width=&491& data-original=&https://pic4.zhimg.com/476d39e8d7fd88da961f5f_r.jpg&&&/figure&&br&&p&用regular expression自然是无能为力的,一个字符一个字

我要回帖

更多关于 slides自己动手做6 的文章

 

随机推荐