Text editor function to indent multiple lines at once - indentation

I want to make my code more organized. So, whenever I copy a function from my functions.php file and paste it in a class, I need to indent each line of the function one or more times so that it's easier to read and looks nice. Some of my functions are nothing more than huge switch statements and indenting each and every line once has proven to be time consuming and tedious.
Are there any functions in TextWrangler that lets users indent a highlighted chunk of code at once?

You can go to Preferences > Keyboard and then select "Allow Tab key to indent text blocks".

You can do:
Command + ]: to tab right
Command + Shift + ]: to space right
Command + Shift + [: to move left

Command - Close Bracket (]) to tab right;
Command Shift Close Bracket to space right;
Same with Open Bracket ([) to move left

Related

Adobe brackets: write spaces instead of tabs

I am using brackets with coffeescript, but when I hit Tab, it insert a tabulation whereas i only need 2 spaces. Also, when I create a line break, the indent is tabs, and not spaces. Can I change these 2 setting ?
In the lower-right of the status bar you should see an indicator saying "Tab Size." Click the label to toggle to spaces. To change the amount of indent, click the number next to it and type a new value.
Note: if the indicator already says "Spaces" then Brackets should be using spaces instead of tab characters already. But it might not feel that way because when you move the cursor or press Backspace, there's a "soft tabs" behavior: the cursor will smartly skips over contiguous spaces to line up evenly with the next tab stop. If that bothers you, there will be a preference in the next release of Brackets (Sprint 38) to disable that behavior, making the cursor never move more than one space at a time.
For language specific control, Brackets allows you to provide different tab and space indentation values in the brackets.json file. For example:
"language": {
"html": {
"spaceUnits": 4
},
"javascript": {
"tabSize": 2
}
}
For changing tab spacing you can edit your brackets.json file. you can find it on Debug->Open Preferences File and simple add "spaceUnits": 2 at the end of the file for 2 space. Remember to add a comma on previous line. You can edit that file for customizing your bracket.
Or you can change it more easily at the right-bottom of your bracket interface you saw a option Space: 4 click on the number and change it as your wish...

Transpose function in Notepad++

I have a text file as:
0xC1,0x80,
0x63,0x00,
0x3F,0x80,
0x01,0xA0,
I want output as:
Line1: 0xC1,0x63,0x3F,0x01,
Line2: 0x80,0x00,0x80,0xA0,
How to do this using replace function in Notepad++?
You can use the below shortcuts to do the transpose in Notepad ++
Step 1: Ctrl + A: selects all.
Step 2: Ctrl + J: Transpose the Row you selected
Use the box select feature to select the second column text.
Use Alt+Shift+Arraw keys to select the second column.
Copy the selected text to a new file.
Use Find/Replace to remove all the newline characters.
Ctrl+F to open find/replace dialog box.
Select either Extended or Regular Expression Serach mode.
Type \r\n in Find What box.
Keep the Replace with box blank.
Click on Replace All in ALL Open Documents.
Now, the text is brought in single line.
Copy the text from second file and paste it to second line of first file.
Cheers...
There is no built-in function in Notepad++ for transposing a matrix and you can't do it using Replace (as M42 pointed out). Also, I'm not aware of any related plugin. So you will either need a different editor or do it with a script. The simplest solution I guess using a Spreadsheet, eg Excel or OpenOffice, both of them allow you to easily transpose a table.
But, there's still a good alternative without leaving Notepad++. Is to use the Python Script plugin.
Setup Python Script plugin
Install Python Script plugin, from Plugin Manager or from the official website.
When installed, go to Plugins > Python Script > New Script. Choose a filename for your new script (eg transpose.py) and copy the first code block that follows and copy the second one to another script, called for example transpose_uneven.py.
Open your data file and then run Plugins > Python Script > Scripts > transpose.py. This will open a new tab with your data transposed.
transpose.py
delimiter=","
newline="\n"
content=editor.getText()
matrix=[line.split(delimiter) for line in content.rstrip(newline).split(newline)]
transposed=list(map(list, zip(*matrix)))
notepad.new()
for line in transposed:
editor.addText(delimiter.join(line) + newline)
if len(transposed)!=len(matrix[0]):
console.clear()
console.show()
console.write("Warning: some rows are of uneven length. You might consider using the transpose_uneven script instead.")
transpose_uneven.py
import itertools
delimiter=","
newline="\n"
content=editor.getText()
matrix=[line.split(delimiter) for line in content.rstrip(newline).split(newline)]
transposed=list(map(list, itertools.izip_longest(*matrix, fillvalue="")))
notepad.new()
for line in transposed:
editor.addText(delimiter.join(line) + newline)
Examples
The transpose.py script will transpose the following example:
0xC1,0x80,
0x63,0x00,
0x3F,0x80,
0x01,0xA0,
To:
0xC1,0x63,0x3F,0x01
0x80,0x00,0x80,0xA0
,,,
If some of your rows are uneven:
0xC1,0x80,
0x63,0x00,
0x3F,0x80,
0x01,0xA0,
0x02
The uneven columns will be discarded accordingly:
0xC1,0x63,0x3F,0x01,0x02
If this is not desired, use transposed_uneven.py and it will return:
0xC1,0x63,0x3F,0x01,0x02
0x80,0x00,0x80,0xA0,
,,,,
If you really have such a fixed format and need such a fixed output i normally try it with an instant macro.
So my cursor is in the top left corner of the file ready to manipulate and i press the record button (or within the menu bar Macro - Start recording).
In you specific case now press:
End
Del
Pos1
↓
End hit the stop button (or within the menu bar Macro - Stop recording).
Now for a first test hit the playback button (or within the menu bar Macro - Playback) and test if it works. If yes click on Macro - Run a macro multiple times and select Run until the end of file.

How to Move selected text Left or Right

I can't believe I can't find a way in Webstorm that when you highlight code, then move it right or left as a group (tab left or right, moving it over left or right).
Is there a way to do this? I can't find one. I need to shift several lines of code in JSON to tab and make it read better from withing Webstorm as just one example. Most editors have this capability! unless I'm just missing it, this is a huge hole in Webstorm that is fundamental that is simply not there!
On top of this I've also noticed that if you put your cursor at the beginning of a line of code and then do Shift + Home to highlight the empty space before it, typically in most editors you can hit tab and start moving it back from the farthest point left back to right. In webstorm, when you highlight the empty space to the left of a starting line and hit tab, it starts tabbing from the the start of the line, not from the first empty space. I find this bizarre and very frustrating.
select a code region and hit Tab (Edit | Indent Selection) or Shift+Tab (unindent)

Add trailing zeroes to line in notepad++

I have a file containing (hundreds) of blocks of numbers like below;
This one is fine (16x20, correct number of rows and columns)
11111111111111111110
16666616666666661110
16111616111111162610
16111646111663132610
16162616261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261626132610
16166313661116632610
16111111111116132610
16666666666666136610
11111111111111111110
This one needs to be padded with trailing zeroes so it is (16x20)
111111111111111111
166616666666663661
166611111111111661
166666366663661661
113161111111161611
1316166666616161
1616162262616161
11616166112616161
16616166116616161
16616162262616161
16616166266616161
16616111161116161
1661666666666616111
1661666166163366661
1641666166166613661
1111111111111111111
I would like to pad them with zeroes so they are all like the first example. I'm aware of the regular expressions feature in notepad++ but am struggling to get it to work. I appreciate any help given.
You could do it via a macro.
First append a large number of zeroes to the end of each line using a macro.
Caret on the first entry
click record macro
press end
type out 20 zeroes
press down arrow
click stop recording
play the macro until all lines look like this
11111111111111111100000000000000000000000000000000000000000000
16661666666666366100000000000000000000000000000000000000000000
16661111111111166100000000000000000000000000000000000000000000
16666636666366166100000000000000000000000000000000000000000000
11316111111116161100000000000000000000000000000000000000000000
131616666661616100000000000000000000000000000000000000000000
161616226261616100000000000000000000000000000000000000000000
1161616611261616100000000000000000000000000000000000000000000
1661616611661616100000000000000000000000000000000000000000000
1661616226261616100000000000000000000000000000000000000000000
1661616626661616100000000000000000000000000000000000000000000
1661611116111616100000000000000000000000000000000000000000000
166166666666661611100000000000000000000000000000000000000000000
166166616616336666100000000000000000000000000000000000000000000
164166616616661366100000000000000000000000000000000000000000000
111111111111111111100000000000000000000000000000000000000000000
Then...
Caret on first line
click record
press home key
press the right arrow key 20 times
hold shift and press end key
press delete key
press down arrow
click stop recording
play the macro until all lines are processed
You could save the entire process as a single macro so its just a single click in the future.
I can give you a macro solution
go to the beginning of your text
select Macro/Start Recording
press end, press 0 16 times then press Home and down arrow key
select Macro/End Recording
You now have a macro to add sixteen zeros to the end of all lines.
Playback this macro on all lines.
You now have appended zeroes to all lines.
Pressing Alt key and using mouse select the required block(columns) of text you want and paste it into another empty notepad tab
help on column mode editing is there inside notepad ? / help contents menu
Good luck
You can use the plugin ConyEdit to do this.
With ConyEdit running in the background, follow these steps:
use the command line cc.aal 00000000000000000000 to append after lines with twenty zero character.
use the command line cc.gc 1/\d{20}/ to get the first column of regex match.
Looking to do this manualy and not progomaticly ?
Open Findreplace
Copy from the last to rhe first WITHOUT NUMBERS on a line so...
in this example
111111111111111111 <---from here
to here ---> 166616666666663661
166611111111111661
paste that into the fine ( yes your effecticly copying the return wich some applications allow you to manualy input others wont )
then in the replace box, type '0' then your return
Hit that magic replace all :D
This will then add a 0 every time it hits a new line, then add a new... new line....
edit : quickly reviewing another method a second to recover for alternate options :P give me 10
edit 2:
Ah ok somthing like this will work :P just tested it.
use [0-9] in the find replace. so if im looking for 123123123123 ( wich is 12 long ) and i need to buff i up to 20,
Your FIND must be in ()
so..
the find would be
([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] )
and the replace is referd to as \1 no the regex, this was my mistake
\100000000
tested and confirmed !dont forget YOU NEED MATCH ALL on, WRAP off!
And so on for your other numbers, Not sure if you can loop this with macros nd stuff :P but hope it helps more than you have now
two good resources.
http://blog.creativeitp.com/posts-and-articles/editors/understanding-regex-with-notepad/comment-page-1/
http://regexpal.com/
base on OP's comment: you could try an editor called vim/gvim
open your file in vim, then type:
:%s/.*/\=printf("%-20s",getline("."))/|%s/ *$/\=substitute(submatch(0)," ","0","g")/
don't forget pressing <Enter> after the above typing.
then you will see the text has been changed into what you want.
of course vim macro can work as well, however, I feel command better... :)

What are most useful/used vim commands in C/C++ dev environment [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 13 years ago.
Here is the list of mine
Unlike me -- as I did it for illustrative purposes -- don't paste too many.
And most importantly, provide an explanation
Commands shouldn't be generic but relevant to C++/C environment. ctags & scope are welcome too
gi .....................init insert mode in last insertion position
'0 .....................open last edited file
gf .....................open file under cursor in same window
Ctrl-w q ...............close current window
:setlocal autoread .....Auto reloads the current buffer..especially useful while viewing log files
for i in range(1,255) | .put='10.0.0.'.i | endfor.... insert range ip's
g; and g, .......................to move (forward, backward) through the changelist
fx Move the cursor forward to the next occurrence of the character x on the current line (obviously, x can be any character you like). This is an extremely useful command. You can type ; to repeat the last f command you gave.
tx Same as above, but moves the cursor to right before the character, not all the way to it. (It's very useful, really.)
Fx Move the cursor backward to the next occurrence of the character x on the current line.
w Move the cursor forward by a word.
b Move the cursor backward by a word.
0 Move the cursor to the beginning of the current line.
^ Move the cursor to the first character on the current line.
$ Move the cursor to the end of the line
Visual search ....... you can simply yank the selected text with y and go to search mode
/, then you can paste the last yanked text with Ctrl+R 0
ci" - cuts the text in current quotes
ciw - cuts the current word. This works just like the previous one except that ( is replaced with w.
C - cut the rest of the line and switch to Insert mode.
zz -- it scrolls the screen to make this line appear in the middle
C - cut the rest of the line and switch to Insert mode.
de - delete from cursor to the end of the word (you can also do dE to delete until the next space)
df[space] -- delete up until and including the next space
bye -- copies current word
b and e move the cursor word-by-word
capital D (take a deep breath) Deletes the rest of the line to the right
cd %:h change to current directory
:r! <command> pastes the output of an external command into the buffer.
:%s/foo/bar(&)/g will look for foo, and surround the matched pattern with bar().
:s/.*/PREFIX & SUFFIX/ you want to add a prefix and a suffix simultaneously, you can do something like this:
gd....... keystroke stands for Goto Declaration
gD....... This takes you to the global declaration of the variable under the cursor
------------------
:make error
[make_error]
On pressing RETURN, the cursor moves to line number 6
Now, the command :cn will move the cursor to the line number 4.
To move back to the previous error, one can use the command :cN and the cursor will move back to the line 6.
After correcting the error on line 5 and adding "return 1;", one can run :make again and the output will be
---------
:%!grep sdf | sort -n -k3
1)select the whole content using '%'
2) pipe it to an external command using '!'
3) grep onyl the lines containing 'sdf'
4) sort these lines numerically (-n) on the third field (-k3)
d$ will delete from current position to end of line
d^ will delete from current backward to first non-white-space character
d0 will delete from current backward to beginning of line
dw deletes current to end of current word (including trailing space)
db deletes current to beginning of current word
:%s/pattern//gn........... For counting the number of times some pattern occurs, use:
CTRL-O Go to [count] Older cursor position in jump list
CTRL-I Go to [count] newer cursor position in jump list
zz - line that has a cursor is in the middle of the screen
zt - line that has a cursor is in the top of the screen
zb - line that has a cursor is in the buttom of the screen
set printoptions=number:y ...set numbers in a hardcopy
:hardcopy.... to print the file :w
shift d ...... Deleting from current position to end of line
vim -o ....... allows you to open two windows, split vertically horizontally
vim -O ....... allows you to open two windows, split vertically
CTRL+W CTRL-Q ......to close the current windows
qall.........How do I quit all windows
0 ...First position on line
Ctrl g ...where am I
:set wrapmargin=70
printexpr=system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error
Tab block of code ....select your block of code (with [V]isual line mode normally), then press > or <.
If you want to tab more than once, 2> or 3> to repeat it.
News:
Guys, let's REOPEN THIS QUESTION, and go WIKI-CRAZY!
One set of commands I find useful is [[, ]], [], ][. They navigate through curly braces on the first column, so they effectively allow you to walk through functions if you use proper indentation.
The ones I overuse are the following :
:AV to vertically split the current window and open the header/source file associated to the respective source/header file (if not yet opened, otherwise we jump to its window instead)
:GSp and :GVSp to split the current window and open the requested file (which is somewhere in &path), or jump to the file if it is already opened
<m-x> to toggle comment on the current line
:Make to compile the current project in the background -- NB: a flag needs to be set in order to do so
<c-x>be to add .begin(), /container_name/.end() in whatever(container_name<curoser_here>)
#i which will expand into #include
:DOX which will add a doxygen comment to the current function prototype -- parameters const-/ref-ness, throw spec, return type are taken into account
:GOTOIMPL which will create a default body from the current function declaration (or jump to the already existing body when possible)
<c-w><m-down> : another way to navigate the tags base
for/if/... : expand into the relevant code snippet in insert mode (outside of string/comment context)
,for/,if/.. and ,,for/,,if/... to surround the current selection with the relevant code snippet, the selection will go into the control-statement body (one ,), or its condition (two ,)
tpl expands into template <<cursor>><+placeholder+>
all the text-object motions with =, d, c, ... + di,/vi,/... that acts on the current parameter
<c-x>v, <c-x>t to extract the selected variable/type (refactoring)
All the bracket opening characters + <m-del> to maintain balanced brackets
There are many other commands I use when I develop in C++, but less often -- just explore the links I've given.
Those may be usefull for programming
= - to intend text. To indent all file g CTRL+V G =
CTRL-P/CTRL-O - to complete text
}y - to paste block and indent it correctly in a new place. For example code block in clipboard is 2 level indentation and should be pasted in code, where it will be in 3 level indentation.
CTRL-X+f to complete file name
>>/<< - increase/decrease indentation
% - go the the corresponding open/close bracket
minibufexpl is good plugin to work at once on several files
>aB to indent a block. Not frequently used, but a gem nonetheless.
Using different views is usefull for side by side code comparison.
Note each view created by a split can hold a separate file.
To split the view horizontally
:split
To split the view vertically
:vsplit
To move between split views
^W<arrow> (Thats control W) (Arrow Key)
Once you have set up the tags file:
^] (Move over identifier you want to find: Hit Control ])
:tn Next Tag
:tp Previous Tag
:pop Pop back to the place you where when you hit ^]
You should take a look at SnippetsEmu. A great plugin that will save you a lot of regularly typed words in C.
Note: You're asking about commands and not plugins, but just wanted to mention this one anyway.
The best I've ever used is when I used a combination of combining running make and Quickfix. I pressed F6 to compile, and then F7 to move backwards through the errors and F8 to move forwards by using the line numbers in the gcc warning / error output. Quicker than alt-tab, press up.

Categories