I'm already aware of using \b and \r to move back one character and to the beginning on the line respectively. But is there a way, (specifically in python,) to move the cursor position up 1 line? I'm trying to avoid using curses, but if this is the best option then so be it.
The cuu1 capability will give you the sequence you need in order to do so.
echo -e "aa\n$(tput cuu1)b"
Related
I am making a small online database that is accessible through the form of checkboxes for download. I was wondering if there was some way to list all of the filenames available for download in Sublime Text 2 and insert the same code around each filename?
Everything is functional, it would just save me a lot of repetitive copy and pasting if there is a faster way to do this.
Use SublimeText Find & Replace. Click the Regex button (it looks like a * to the left of the search box)
In the Find box, insert: (^.*$)
In the replace box: [yourcode]$1[yourcode]
Where [yourcode] is what you want to insert into the box.
So, if you want to make them all <li> then your replace box would be:
<li>$1</li>
Remember to use escape \ characters where they are needed, in case you need to insert restricted characters.
^ - beginning of a new line.
. - wildcard
* - any number of the previous character in the sequence (in this case a wildcard, so any text)
$ - the end of a line
() - denotes a block, it's how the $1 knows what text to put in it's place.
Sublime Text Search and Replace
Use search/replace on a text editor with regular expressions.
^ and $ represent the beginning and end of a line - thus allowing you to easily surround each line with the appropriate text.
Sometimes you can copy the newline character (as in copy the end of one line to the beginning of the next line), and replace that with whatever text you need.
You could always use the regular expression search / replace feature in Notepad++.
I know i can select a block of lines, and then split it into many selections, one per line, using Ctrl+Shift+L then just typing a quote it will wrap the line automatically or to wrap each line with htlm tags I know I can use ctrl+shift+w
The problem is that I would like to skip the initial whitespaces of each line and just adding a quote or a html tag at the begging of the first word.
ps: Im using SublimeText 2 with Vintage
Select a block, then press:
Ctrl+Shift+L, Home, Shift+End
Is that what you are looking for?
Select a block, then press:
Command+Shift+L, right-arrow, Command+Shift+left-arrow
(Note: I'm on a mac.)
I want to replace <whatever>Some Title</whatever> with <something>Some Title</something> using the Find and Replace tool inside of Dreamweaver. How do I perform?
Not a Dreamweaver user, but this simple approach works in my editor (Emacs):
Replace:
<whatever>\(.*\)</whatever>
With:
<something>\1</something>
This is a pretty straightforward approach but it may fall short of your needs. Do some or all of your <whatever> element pairs occupy more than one line of text? Or do you have more than one <whatever> pair on a single line?
i guess what you want is to change all your <whatever> tag with an <something> tag whitout changing your text, right?
If it is so, you want to use find and replace with regular expression. Find (in source code) <whatever>(.*)</whatever> and replace it with <something>$1</something>. The $1 is used as a variable for anything fits the (.*) part DW finds for each instance.
For example, you you want to comment all instances of an
document.NAMEOFANYFORMONTHEPAGE.WHATEVERNAME.focus();
in a JavaScript file, you would use find:
document\.(.*)\.focus\(\);
and replace it with:
// document.$1.focus();
Don't forget to escape special characters and, please, try a few instances before using Replace All
I like to keep my lines below 80 columns, so I often want to refactor a line that looks like this:
object.function(a_long_argument, another_long_argument, and_a_third)
to this:
object.function(a_long_argument,
another_long_argument,
and_a_third)
But when I press Enter after the first "," in Sublime it just linebreaks and indents the cursor a few spaces. I want it to align to the paranthesis or [] or {} that I am in, like Emacs does so beautifully.
Is there an option for this? Is there a plugin for this? Do I have to write my own?
I have tried searching for it, but I have not found anything.
EDIT:
Even better would be a shortcut or plugin or something for selecting a few rows, or the entire buffer, and let it try to auto-linebreak at good spots. Refactor comments too. If it has to be language specific, I want it primarily for Python and C++.
Sublime's indent_to_bracket will wrap the cursor for you. Just add the following line to either your User/Preferences.sublime-settings or User/Python.sublime-settings file:
"indent_to_bracket": true
Unfortunately this currently only seems to work with parentheses, curly braces and square brackets still wrap to the previous line indent.
What's the best shortcut or plugin to comment out HTML/XML elements?
And also need to uncomment.
You can use a combination of matching XML tags, as can be seen in this question and Perl's search and replace.
For instance, given this snippet:
<TypeDef name="a">
<ArrayType high="14" low="0">
<UndefType type="node">
</UndefType>
</ArrayType>
</TypeDef>
Put the cursor on either the opening or closing TypeDef and type the following sequence:
vat:s/^\(.*\)$/<!-- \1 -->/
v - puts you into visual mode
at - selects the whole XML tag
:s/^\(.*\)$/<!-- \1 -->/ - surrounds each line with '<!-- ... -->', the comment delimiters for XML
Alternatively, you can just delete it like this:
dat
d - delete according to the following movements
at - as before
To delete id use then use vat:s/-->// to delete comments
I use the tComment plugin. You can find a detailed video tutorial here on how to install and use it.
The plugin is very useful as it allows you to toggle comments from both the command and input interface, and you can do so using both visual mode and motions (like gcw, or gc3w)
If you use emmet-vim, you can select the whole contents of the tag you would like to comment out by pressing v a t and then press Ctrl y /
To comment: vato<ESC>i<!-- <ESC>vatA --><ESC>
Position the cursor anywhere inside the HTML block. Not inside a nested one unless you want to comment that one.
Go to the opening tag: vato
Exit visual mode: Esc
Insert: i<!--
Exit insert mode: Esc
Go to closing tag: vat
Append: A -->
Exit insert mode: Esc
Note: You may use I to insert directly from visual mode, and it'll work with multi-line blocks, but for single line elements it'll mess up the indentation.
To uncomment: vat<ESC>4xvato<Esc>5X
Position the cursor anywhere inside the HTML block, ending comment delimiter excluded.
Go to the closing tag: vat
Exit visual mode: Esc
Delete 4 chars: 4x
Go to the opening tag vato
Delete preceding 5 chars: 5X
Using .vimrc or init.vim to create shorcuts
You may add these lines to your .vimrc (or init.vim in neovim) to remap shortcuts:
" Comment HTML element
nnoremap <silent> <leader>h :set lazyredraw<cr>mhvato<ESC>i<!-- <ESC>vatA --><ESC>`h:set nolazyredraw<cr>
" Uncomment HTML element
nnoremap <silent> <leader>H :set lazyredraw<cr>mhvat<ESC>4xvato<ESC>5X`h:set nolazyredraw<cr>
Warning:
You will need to undo if you try to uncomment a non-commented area for it will delete some characters. You could avoid this by replacing 4x with d2f- and 5X with dF!, but then you'd have issues with this kind of workaround and anything else in the same line that contains -...- or !.
If there are already comments in between the tags of the element to comment out, you will need to uncomment those first.
Notes:
Change <leader>h and <leader>H to what you'd like to use.
:set lazyredraw is to hide intermediate steps by not redrawing the screen and :set nolazyredraw to avoid possible visual glitches afterwards.
mh is to save current cursor position and `h is to jump back to that line and column. You may replace h with any other lower case letter.
Tip: Use :source $MYVIMRC to apply changes done to .vimrc (or init.vim) without having to restart vim.