schlitt.info - php, photography and private stuff ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :Author: Tobias Schlitt :Date: Tue, 29 Jan 2013 08:32:21 +0100 :Revision: 1 :Copyright: CC by-nc-sa ==================================== Comfortable PHP Editing With VIM -9- ==================================== :Description: After telling you about my completely reworked VIM setup and the awesome VIM plugins I'm using in it, this blog post deals to share with some snippets and settings I'm using to make all that stuff work round. :Abstract: After telling you about my `completely reworked VIM setup`__ and the `awesome VIM plugins`__ I'm using in it, this blog post deals to share with some snippets and settings I'm using to make all that stuff work round. __ /opensource/blog/0739_comfortable_php_editing_with_vim_7.html __ /opensource/blog/0740_comfortable_php_editing_with_vim_8.txt After telling you about my `completely reworked VIM setup`__ and the `awesome VIM plugins`__ I'm using in it, this blog post deals to share with some snippets and settings I'm using to make all that stuff work round. __ /opensource/blog/0739_comfortable_php_editing_with_vim_7.html __ /opensource/blog/0740_comfortable_php_editing_with_vim_8.txt ---------- Leader Key ---------- VIM already provides you with a ton of pre-defined shortcuts on various keys and in various combinations with ```` and ````. Therefore, the so called *Leader Key* was introduced, allowing you to choose one base key to deal as the starting point for all your custom shortcuts. Defining the leader is easy using:: let mapleader = "," let maplocalleader = "," You can then access this key through ```` and use it in keyboard combinations. Many plugins also try to register sensible defaults here, without inteferring with others. ------------------- Incrememntal Search ------------------- Using the incremental search setting, VIM starts running through your text document and showing you search results, while you still type your search. This helps a) to find stuff earlier and b) return early, if the desired result cannot be found. Incsearch is set by:: set incsearch set nohlsearch The latter option disables the annoying highlighting of search results after you finished searching. --------- Wild Menu --------- When auto-completing file names in command mode (like when doing ``:edit``, ``:split`` or ``:vsplit``), the wild menu offers you more comfort and especially more context. Enable it by:: set wildmenu set wildmode=list:longest The latter setting defines the style of the menu. A matter of taste. ----------- Cursor Line ----------- The place you are currently editing in insert mode is typically only marked by the cursor. Using the cursor line, you get a more appealing visual identifier:: autocmd InsertLeave * set nocursorline autocmd InsertEnter * set cursorline The autocommands deal for enabling/disabling the line when you enter/leave insert mode. --------------------- Restore Last Position --------------------- One feature which I had ages ago already (I suspect by either some plugin or by a distro based setting), but which suddenly vanished, was to restore the cursor position in a file I recently edited, when I re-open it again. Thanks to Benjamin__, I now have that again through:: au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif __ http://www.whitewashing.de/ --------------- Invisible Chars --------------- Making invisible chars (e.g. tabs) visible can sometimes help while debugging. This little snippet allows you to switch that on using ````:: nnoremap L :set list! set listchars=tab:▸\ ,eol:¬ Thanks to `a VIM cast`__ for that. __ http://vimcasts.org/episodes/show-invisibles/ ------------ Save as Root ------------ How often do you forget a ``sudo`` in front of your ``vim`` command when editing a system config file? Using the following snippet allows you to write your changes anyway, without exiting your VIM session:: cnoremap w!! w !sudo tee % >/dev/null Thanks to Jakob__ for this snippet. __ http://westhoffswelt.de ------------------------ Moving through CamelCase ------------------------ If you write CamelCase code, its often useful to navigate through the dedicated parts using ```` and ````:: nnoremap :cal search('\<\\U\@<=\u\\u\ze\%(\U\&\>\@!\)\\%^','bW') nnoremap :cal search('\<\\U\@<=\u\\u\ze\%(\U\&\>\@!\)\\%$','W') inoremap :cal search('\<\\U\@<=\u\\u\ze\%(\U\&\>\@!\)\\%^','bW') inoremap :cal search('\<\\U\@<=\u\\u\ze\%(\U\&\>\@!\)\\%$','W') ------------ Paste Toggle ------------ Using ``:setpaste`` you can switch off all automatic formatting (e.g. indentation) in VIM. This is useful, if you want to paste from external sources through your terminal. However, using the following config, it becomes even more convenient:: set pastetoggle= nnoremap :setlocal paste!i autocmd InsertLeave se nopaste The ```` (insert) key becomes the *paste toggle*, meaning that, in insert mode, it switches between ``paste``/``nopaste``. In normal mode, pressing insert will set you into insert mode and set ``paste``. Furthermore, when you leave insert mode with ``paste`` it will be switched off, so that you don't forget it. ------------ Endless Undo ------------ In times of distributed version control, undo functionality might become less and less important. However, it still gives you some comfort, especially if VIM remembers your undo history between sessions:: set undodir=~/.vim/undodir set undofile set undolevels=1000 set undoreload=10000 This sets vim to store undo information in files below ``~/.vim/undodir``. It will keep up to 1000 (yes, feels almost endless) actions and up to 10000 lines of buffers that get overwritten externally. ------------------- Edit Files Relative ------------------- Another goodie found in Benjamins__ config: When editing a file, it occurs quite often to me, that I need to edit one in the same directory (or one level above). I tent to write stuff like ``:vs %:h`` which is __ http://www.whitewashing.de/ - vertical split (``:vs``) - current file name (``%``) - strip last path element (``:h``) This works, but is a) hard to type and b) does not give you auto-completion for subsequent path elements (the files). The following shortcut simply expands the desired base path from typing ``%%``:: cnoremap %% =expand('%:h').'/' I would love to have ``%%%`` expand to ``%:h:h`` (one more path level removed), but we did not find a solution for that, yet. Anyone maybe has an idea? .. Local Variables: mode: rst fill-column: 79 End: vim: et syn=rst tw=79 Trackbacks ========== Comments ======== - lucash at Wed, 30 Jan 2013 01:57:30 +0100 First of all thanks for sharing your config and plugins in this and the previous posts. To get %%% work as described this should work: cnoremap %%% =fnamemodify(fnamemodify(expand('%'), ":h"), ":h") - Toby at Wed, 30 Jan 2013 10:29:06 +0100 Hi lucash, well, that works. However, I need to wait quite a bit now after using just %%. I expect VIM now waits if I will type another % and only expand the first 2 afterwards. Maybe there is a solution without that hassle? Cheers, Toby - Saara james at Tue, 12 Feb 2013 16:00:12 +0100 It is an useful info about VIM plugin and I ever heard about it any where.Nice post to know about PHP editing with VIM -9- Those who interest in it should know following shortcuts. Sounds good. - Аренда Яхты at Fri, 15 Feb 2013 09:31:19 +0100 Interesting post. I will subscribe for new posts - fashion spot at Thu, 28 Mar 2013 02:06:47 +0100 As for why the critics was completely misinterpreted also a wide range of hair pass is issued, all free evaluation of evidence! - ffxi gil sale at Thu, 28 Mar 2013 08:26:20 +0100 I think your leader key is wonderful for me to learn. I am looking forward for your next post, I will try to get the hang of it! - Archeage Gold at Thu, 28 Mar 2013 08:27:13 +0100 Sometimes it is extremely difficult to explore good and useful information out there when doing research.I'm glad that there is a knowledge from your page - Samfrank at Sat, 06 Apr 2013 14:26:23 +0200 Lovely work! I'm definitely going to visit the blog frequently. I tried the ctags command and this does seem to do exactly the same thing. You're right on that :) VIM is pretty damn cool. will take a look at NERDTree later. - ana at Wed, 10 Apr 2013 16:49:47 +0200 i know that vim is very powerful but i prefer nano :) - Anvith Bhat at Mon, 15 Apr 2013 05:10:28 +0200 You should know, anti-corruption commissioner had billions of assets, it is because he often to help the mediation of disputes between the mine owners, all of these are he deserved rewards, http://www.louboutinukstockists.co.uk/ - www.freeartsonline.com at Wed, 17 Apr 2013 05:33:47 +0200 I like the valuable info you provide in your articles. I will bookmark your blog and check again here regularly. I am quite certain I will learn many new stuff right here! Best of luck for the next - mac repair at Wed, 17 Apr 2013 05:42:59 +0200 I wanted to inform you for this great help!! I definitely enjoyed every little bit of it. I have you bookmarked to check out new stuff on this post. - elektronik sigara at Wed, 17 Apr 2013 05:43:28 +0200 Such an interesting article. I really still don't believe that I will find this article on your site surely not believe it. But Thanks for posting it. - liquidation entreprise eurl at Wed, 24 Apr 2013 13:48:05 +0200 The author has written an excellent article. You made your point and not much to discuss. It's like this universal truth that you can not argue with the truth is not universal, everything has its exception. Thanks for this information. - www.bestfootballteams.com at Thu, 25 Apr 2013 02:42:16 +0200 Great team there. San Gabriel Valley puts out some good players. I am very much overwhelmed by your thoughts for this particular story. A more deeper and staged knowledge would be good for me. - www.seoeggs.com at Thu, 25 Apr 2013 09:26:10 +0200 There are a lot of important elements of SEO. As any busy Perth SEO company, who utilizes a diversified approach that helps clients weather all Google algorithm changes, are seeing that it is becoming increasingly important to add unique content and high quality content to your business website. - www.dailyfamily.eu at Thu, 25 Apr 2013 09:26:25 +0200 The actual rings given in the engagement are actually changed in the right hand left, and big quantities associated with savoury as well as sweet foods are supplied. - www.onlineflowershop.eu at Thu, 25 Apr 2013 09:26:44 +0200 Flowers can be bought or sent with the local florist and today, due in order to advances within technology, through on the internet florists too. - www.electronicbooks.eu at Thu, 25 Apr 2013 09:27:03 +0200 Guide fairs offer an excellent chance for more information about the actual publishing business, about booksellers, marketers, distributors as well as marketers. The going to author will even learn a good deal about exactly what readers would like and how you can reach visitors. - www.autosdeals.eu at Thu, 25 Apr 2013 09:27:25 +0200 it's not necessary to worry regarding your poor credit as lots of creditors are prepared to serve a person the loan on the platter. It's you opportunity to own the greatest model associated with car. It's an easy and also the most traditional loan. - Christine at Fri, 26 Apr 2013 08:21:20 +0200 I rewrote PDV - phpDocumentor for VIM completely and it now nicely integrates with current plugin managers. Its code is now way cleaner and maintainable and it has some fancy new features like templating support through my Vmustache implementation and support for making the generated doc blocks UltiSnippets snippets for even more ease in editing them - www.popfreemusic.com at Mon, 29 Apr 2013 07:22:47 +0200 You write about wonderful information. Publish clause stunning as well as article writing levels is very beneficial effortlessly realize for you to anybody who is going to understand ones document understanding that boost my understanding. - www.ilikechinesefoods.com at Tue, 07 May 2013 08:44:17 +0200 Guide fairs offer an excellent chance for more information about the actual publishing business, about booksellers, marketers, distributors as well as marketers. The going to author will even learn a good deal about exactly what readers would like and how you can reach visitors. - hotspot software at Wed, 08 May 2013 12:57:07 +0200 This plan is ideal for our customers for whom system availability is business critical, and who require software investment protection. - sakfo at Wed, 08 May 2013 15:09:48 +0200 Flowers can be bought or sent with the local florist and today - kirsten price female mind mastery at Thu, 09 May 2013 16:24:38 +0200 Ive been visiting several websites for about the last two hours and Taking advantage of this resources will really be a good read for visitors - http://pinterest.com/lvlouisvuitton/ at Mon, 13 May 2013 07:51:49 +0200 The 2013 Louis Vuitton Handbags are classic and a girl must have at least one in her closet. Chic, classic style, classy and good quality. - Alltherma airquality at Mon, 13 May 2013 17:45:04 +0200 It is pronounce wiggling and everyone likes it. It also needs to amend examinee and someone. - Application Security at Wed, 15 May 2013 12:31:27 +0200 A website's security certificate gives users extended security by encrypting data between the user's browser and the Web server. Security certificates are installed on the server, so your website developers can securely transfer information such as financial or medical records. - www.queens-hotel-karlsruhe.com at Wed, 15 May 2013 18:21:22 +0200 Qualified post and also very helpful for writing this valuable information. Your post is one of the better that I have read, You should congrat your self for having able to write down some really wonderful articles - www.queens-hotel-karlsruhe.com at Wed, 15 May 2013 18:47:12 +0200 A top new topic in this post makes your site is greatly appreciated. Look forward to read more on this blog's updates. This is just what I'm looking for, a blog that I find almost all of the posts to be very beneficial - law-states.com at Thu, 16 May 2013 08:01:17 +0200 By state law, there is typically a small fee that you must pay before a public record can be released and divorce is one of the categories of such public information.