how to do vi search and replace within a range in sublime text - regex

I enabled vintage mode on sublime text.. but there are some important vim commands that are lacking.. so let's say I want to do a search and replace like so
:10,25s/searchedText/toReplaceText/gc
so I wanna search searchedText and replace it with toReplaceText from lines 10 to 25 and be prompted every time (ie yes/no)..
how do I do this with Sublime Text? everytime I hit : it gives me this funny menu.. any way around that?

If you so much would like to see vim in action, try the other way around; ie enable sublime stuff in vim.
Here are 2 links that might come in handy:
subvim and vim multiple cursors (Which is one amazing feature in sublime that lacks in native vim).
Hope that gets you creative ;)

Unfortunately vintage mode does not understand ranges. The best way I know how to do this is with incremental search:
highlight the first occurrence of searchedText on line 10
hit cmnd/ctrl D to have Sublime find the next occurence
If you you want the next occurrence ignored, hit cmnd/ctrl K
Once you have highlighted all the occurrences, you can replace them all at once, as Sublime has left cursors behind on every occurrence you opted in on.

VintageEx gives you a Vim-like command-line where you can at least perform substitutions. Well, that's how far I went when trying it. I don't know how extended the subset of Vim commands it implements is but I'd guess that it's not as large as the original and, like with Vintage, probably different and unsettling enough to keep a relatively experienced Vimmer out.
Anyway, I just tried it again and indeed you can more or less do the kind of substitution you are looking for, which instantly makes ST a lot more useful:
:3,5s/foo/bar/g
:.,5s/bar/foo/g
:,5/foo/bar/g
:,+5/bar/foo/g
Unfortunately, it doesn't support the /c flag.

a plugin named vintageous offers more features including search function. It's available in package control

although this question is answered.. i figured this would add some value
the full functionality of vi search/replace is possible with the ruby mine IDE, once you install the ideavim plugin. The idea is perfect for ruby on rails by the way.

Related

Regular expressions in ignored_words in Sublime Text 3 spell_check?

I'm trying to spellcheck a latex file. I would like the spellchecker to ignore strings containing a number. In my settings file I have
"ignored_words":
[
"textbf",
"renewenvironment",
etc...
]
If I add something like ".*[0-9].*" to "ignored_words" it doesn't seem to do anything. Is there a way to accomplish this?
It is not possible to use regex in spell checking at this point.
ST uses Hunspell as its spell checker. Adding regex to Hunspell is an open feature request. Not being closed means there is some hope that it may be on a long term enhancement list, maybe.
Until Hunspell adds this capability it seems impossible to achieve what you are seeking in ST.
Keeping an eye on the feature request may be worth it to see if there is any progress.

alt+backspace to delete words in vim

How can I remap alt+backspace to delete words like native *NIX text manipulation? I checked out this thread: Using alt+backspace key in vim command line to delete by words
And the examples like: cmap <a-bs> <c-w> and :imap <A-BS> <C-W> don't do anything. And the accepted answer was actually to not even remap it, but to use ctrl+w. Since VIM's alt+backspace doesn't do anything I'd rather remap it to something I'm used to.
I'm using terminal based VIM (specifically in iTerm)
On macOS with iTerm2, I have the option keys mapped to +Esc (like many people), and I found that pressing Option+Backspace actually was interpreted by vim as an Escape press followed by a Backspace press, so the following binding worked perfectly for me; I recommend trying it even if your configuration is different than mine, just in case it works for you!
:imap <Esc><BS> <C-w>
The Alt/Meta key is problematic in Vim and most terminals, see this answer of mine for an overview of the situation (the situation is the same for Meta and Alt).
In short, Vim doesn't receive Alt at all: hitting Alt+Backspace is exactly the same as hitting Backspace.
Anyway, it will be better for you in the long term to learn and get accustomed to Vim's default key-mappings.
If you are on OSX, macvim uses the standard key bindings, so pressing Alt+Backspace will delete the entire word. Same goes for navigating between words with Alt+RightArrow and Alt+LeftArrow.

internal code-completion in vim

There's a completion type that isn't listed in the vim help files (notably: insert.txt), but which I instinctively feel the need for rather often. Let's say I have the words "Awesome" and "SuperCrazyAwesome" in my file. I find an instance of Awesome that should really be SuperCrazyAwesome, so I hop to the beginning of the word, enter insert mode, and then must type "SuperCrazy".
I feel I should be able to type "S", creating "SCrazy", and then simply hit a completion hotkey or two to have it find what's to the left of the cursor ("S"), what's to the right ("Crazy"), regex this against all words in the file ("/S\w*Crazy/"), and provide me with a completion popup menu of choices, or just do the replace if there's only one match.
I'd like to use the actual completion system for this. There exists a "user defined" completion which uses a function, and has a good example in the helps for replacing from a given list. However, I can't seem to track down many particulars that I'd need to make this happen, including:
How do I get a list of all words in the file from a vim function?
Can I list words from all buffers (with filenames), as vim's complete does?
How do I, in insert mode, get the text in the word before/after the cursor?
Can completion replace the entire word, and not just up to the cursor?
I've been at this for a couple of hours now. I keep hitting dead ends, like this one, which introduced me to \%# for matching with the cursor position, which doesn't seem to work for me. For instance, a search for \w*\%# returns only the first character of the word I'm on, regardless of where I'm in it. The \%# doesn't seem to anchor.
Although its not exactly following your desired method in the past I've written https://github.com/mjbrownie/swapit which might perform your task if you are looking for related keywords. It would fall down in this scenario if you have hundreds of matches.
It's mainly useful for 2-10 possible sequenced matches.
You would define a list
:SwapList awesomes Awesome MoreAwesome SuperCrazyAwesome FullyCompletelyAwesome UnbelievablyAwesome
and move through the matches with the incrementor decrementor keys (c+a) (c+x)
There are also a few other cycling type plugins like swap words that I know of on vim.org and github.
The advantage here is you don't have to group words together with regex.
I wrote something like that years ago when working with 3rd party libraries with rather long CamelCasePrefixes in every function different for each component. But it was in Before Git Hub era and I considered it a lost jewel, but search engine says I am not a complete ass and posted it to Vim wiki.
Here it is: http://vim.wikia.com/wiki/Custom_keyword_completion
Just do not ask me what 'MKw' means. No idea.
This will need some adaptation to your needs, as it is looking up only the word up to the cursor, but the idea is there. It works for current buffer only. Iterating through all buffers would be sluggish as it is not creating any index. For those purposes I would go with external grep.

Making Dreamweaver more like Notepad++

I'm moving to Dreamweaver from Notepad++, and while Dw does have many better features than Notepad++, there are a few that I'm really missing.
Is there a way to make the "Home" key on the keyboard take you to the front of where the code starts, instead of the very front of the line? In Notepad++ this is how it works by default, and I don't know why anyone would want to go to the very front of the line instead of the front of the code. I use tabbing to keep it more organized, so this feature is really important to me.
How do I duplicate a line in Dw? In Notepad++ I can select the line and press ctrl + d and it automatically duplicated the code. This is awesome for something like a gallery or a table where I don't want to have to type out every line because it's so similar.
Less important, as I don't use this that often, but can you vertically select in Dw? In Notepad++ you can hold down alt and select lines vertically. Ex:
http://dl.dropbox.com/u/12147973/vert-select.jpg
Thanks in advance.
For #2, check out the Code Extras extension for Dreamweaver
No Longer works in DW5.5; Try here - http://yoropan.com/en/archives/544
I was also wanting some of this features... I discovered that, at least in CS6, #2 is already in Dreamweaver, but the shortcut is Ctrl+Alt+Down ou Up, depending on the direction that you wanna duplicate the code.
Note that I had to disable the shortcut that turns your screen view for that to work. (It's an intel default, press Ctrl+Alt+f12 to open the options)
And tãa dãaa... IT WORKS! :D
I want to say one thing different. My Dreamweaver theme (Users who use Dreamweaver after use Notepad++). Download Dreamweaver.xml
"Dreamweaver.xml" file is in here for windows: C:\Program Files\Notepad++\themes\Dreamweaver.xml
The answer to #1 = Ctrl+Home in anything in windows will take you to the absolute start of the documents, same as Ctrl+End, Home and End to start and finish of lines, Ctrl+Left or Right arrow to jump entire words...
I too am on the quest for duplicating lines in DW. #3 your image no longer shows.
If I want to duplicated a line I click on the line number, then CTRL+C to copy and CTRL+V to paste. Is that what you're looking for or am I being simple?

notepad++ regular expressions to convert lines for SPSS syntax editor

I am curently busy with bulding a synthax document in SPSS and have a column of variable strings that consists of approximately 40 lines (it will be much much more in coming week). SPSS has a nice way of creating it (can be seen here :)
http://vault.hanover.edu/~altermattw/methods/stats/reliable/reliability-1.html) but it can be done per one variable at a time which is possible to automatize.
I am a total beginner (I wouldn't mind if you would call me n00b) at search&replace with reqular expressions in notepad++ but I can use the extended search function as a basic user :P
The data contains scores Likert scale (from 1-7) and I would like to reverse it to do some tests.
For example: my variable name on the line is q_4_SQ001 and the sline in synthax editor is q_4_SQ001=COMPUTE q_4_SQ001r=8-q_4_SQ001.
My question so far is thus:
How can I convert a line containing a unique variable name into it's revers formula?
So in this case, how can I replace the following lines:
q_4_SQ001
q_4_SQ002
q_4_SQ003
q_4_SQ004
into the synthax given under:
COMPUTE q_4_SQ001r=8-q_4_SQ001.
COMPUTE q_4_SQ002r=8-q_4_SQ002.
COMPUTE q_4_SQ003r=8-q_4_SQ003.
COMPUTE q_4_SQ004r=8-q_4_SQ004.
Please remark the dots in the end of each line I did this manually to give you an impression of what I would like to achieve. My data set has different questions and different variable strings so I would like to make my life a bit easier right now :P
I also tried recording and running a macro as stated in here (http://stackoverflow.com/questions/2467875/notepad-replace-all-regular-expression-start-of-the-line-and-end-of-the-line) but that still is pretty time consuming since I have to do each line manulally and clean up with extended search in the end.
Wouldn't it be easier to convert each line?
Thanks a bunch in advance :)
Funny, Notepad++ works under Wine, as I just found out ;)
New file, inserted:
q_4_SQ001
q_4_SQ002
q_4_SQ003
q_4_SQ004
Select all (CTRL+A), replace (CTRL+R).
Tick Regular Expr, stick ^(.*)$ in the "find" bit (first textbox), and COMPUTE \1r=8-\1. in the "replace" bit (second textbox). Hit the Find button, and then the Replace Rest button.
Parenthesis () around a pattern cause the pattern to be "memorised", each set of parenthesis available to the replacement pattern via \1, \2, etc.
After the replace, I got:
COMPUTE q_4_SQ001r=8-q_4_SQ001.
COMPUTE q_4_SQ002r=8-q_4_SQ002.
COMPUTE q_4_SQ003r=8-q_4_SQ003.
COMPUTE q_4_SQ004r=8-q_4_SQ004.
Which I assume is what you wanted. Enjoy.