code-formatting

Format Ruby code in Vim

不想你离开。 提交于 2019-12-03 03:15:42
问题 Just moving over to Vim at the moment. In TextMate I could format code by hitting Cmd - Alt - [ . How do I achieve the same in Vim? See the answer below for the command. I found I also needed the following in my .vimrc so that Vim knew how to autoindent Ruby. if has("autocmd") filetype indent on endif 回答1: Vimcasts has a useful screencast on this subject that you may be interested in gg=G gg => go to start of file = => apply autoformatting G => ... to the end of file 回答2: When I see questions

Code-formatting: How to align multiline code to special characters?

可紊 提交于 2019-12-03 03:05:36
Is IDEA or one of its plugins capable of aligning code to special characters? I mean so that the code Map( 'name -> "Peter", 'age -> 27, 'company -> "Foobar" ) is transformed to Map( 'name -> "Peter", 'age -> 27, 'company -> "Foobar" ) Example2: execute("x", true, 27) execute("foobar", false, 0) transformed to execute("x" , true , 27) execute("foobar", false, 0 ) You can align case statements, however: value match { case s: String => Some(java.lang.Long.parseLong(s)) case bi: BigInt => Some(bi.longValue) case _ => None } Like so: value match { case s: String => Some(java.lang.Long.parseLong(s)

How to format html files in Eclipse?

和自甴很熟 提交于 2019-12-03 02:57:06
问题 The XML formatting works perfect but not the html formatting. In fact if I use "cmd-shift-F" for a html file, it just left aligns almost everything. I've attached the before and after pictures. Does anyone know how to fix this? I played around with HTML formatting preferences but had no luck. Note that the same document, if it is saved as xml will format perfectly. I am using eclipse 3.6 with WTP plugin. 回答1: go to Window --> preferences --> Web --> HTML files --> Editor . In the Inline

Are there any lint tools for C and C++ that check formatting?

亡梦爱人 提交于 2019-12-03 02:08:32
I have a codebase that is touched by many people. While most people make an effort to keep the code nicely formatted (e.g. consistent indentation and use of braces), some don't, and even those that do can't always do it because we all use different editors, so settings like spaces vs. tabs are different. Is there any standard lint tool that checks that code is properly formatted, but doesn't actually change it (like indent but that returns only errors and warnings)? While this question could be answered generally, my focus is on C and C++, because that's what this project is written in. Nikola

Autoindent on Sublime Text

喜你入骨 提交于 2019-12-03 01:37:34
Are there any command/shortcut to auto-indent all my code on the page at once on Sublime Text 3? e.g: On NetBeans I can do this with Alt + Shift + F . That's quite simple in Sublime. Just Ctrl+Shift+P (to open tools pallet), type reindent , and pick Indentation: Reindent Lines . It should reindent all the file you are in, just remember to save before running the command, or it may not appear. Auto-indenting on Sublime Text 3 - "Key Bindings" Just add this binding to your "Key Bindings - User" file: Preferences > Key Bindings - users {"keys": ["alt+shift+f"], "command": "reindent", "args": {

How to config intellij-idea not format some part of the code?

天大地大妈咪最大 提交于 2019-12-03 01:07:45
In a html file, there is some code used custom template-language: <script type="text/javascript"> function ($scope, JsRoutes) { $scope.rows = [ ${"#{list rows, as: 'row', separator: ','}"} { #{list fieldConfigs, as: 'f', separator: ','} ${f.name} : ${'$'}{row.${f.name}.toJson()}#{/list} } ${'#{/list}'} ] } </script> Is it possible to configure intellij-idea not to format it(but format the other part of the document)? Since idea will make it hard to read after formatting: <script type="text/javascript"> function ($scope, JsRoutes) { $scope.rows = [ ${"#{list rows, as: 'row', separator: ','}"} {

How to auto format code in WebStorm?

好久不见. 提交于 2019-12-03 01:02:01
问题 I'm looking for a way to auto-format my code in the WebStorm IDE? 回答1: Mac : Command + Option + L PC : Ctrl + Alt + L 回答2: It is possible by creating a macro that formats the code and save it, and then bind this macro to Ctrl + S shortcut. (Mac: Cmd + S ) This answer was posted for phpStorm and it is equally valid for WebStorm. A modified version of answer is as follows: Record the macro Edit > Macros > Start Macro recording Press Ctrl + Alt + L , and then Ctrl + Alt + S (on Mac: Cmd + Option

Ruby code beautification, split long instructions on multiple lines

≡放荡痞女 提交于 2019-12-03 00:57:29
How can we write the following statement to improve readability? Promotion.joins(:category).where(["lft>=? and rgt<=?", c.lft, c.rgt]).joins(:shops).where(:promotions_per_shops => { :shop_id => shops_id }).count('id', :distinct => true) The following doesn't compile Promotion.joins(:category) .where(["lft>=? and rgt<=?", c.lft, c.rgt]) .joins(:shops) .where(:promotions_per_shops => { :shop_id => shops_id }) .count('id', :distinct => true) syntax error, unexpected '.', expecting kEND .where(["lft>=? and rgt<=?", c.lft, c.rgt]) Do it like this: Promotion.joins(:category). where(["lft>=? and rgt<

Notepad++/Eclipse sql code auto-indent option?

左心房为你撑大大i 提交于 2019-12-03 00:55:24
DDL gets especially ugly. Is there any option of SQL auto-indenting for Notepad++? I've tried to do it in Eclipse, but the code doesn't react to auto-indent. Yes, there is a free/open-source T-SQL formatting plugin for Notepad++, called "Poor Man's T-SQL Formatter". It is available in the NPP "Plugin Manager" plugin list (gets updated every once in a while automatically), and is also available for manually downloading/installing from here: http://www.architectshack.com/PoorMansTSqlFormatter.ashx If you just want to check it out without adding to notepad++, you can check the online formatting

ReSharper Line Breaks and Wrapping

别来无恙 提交于 2019-12-02 21:44:22
So, this: cmd = new OdbcCommand( string.Format( @" SELECT * FROM Bobby_Tables WHERE Name = {0}", "Little Bobby Drop Tables" ), odbcConnection ); gets formatted to: cmd = new OdbcCommand( string.Format( @" SELECT * FROM Bobby_Tables WHERE Name = {0}", "Little Bobby Drop Tables" ), odbcConnection ); I've looked at each of the options for line breaks and wrapping but I haven't been able to find the one to keep things on the same line as long as possible. I'm assuming that I missed the correct option. My Right margin (columns) option is set to 100, which is plenty big. Question: Is there a way to