Vim tips: curly quotes and visual selection

Curly quotes: because reasons.¬† ūüėȬ† In Insert mode:

  • Ctl+K '6 will give you an open curly single quote, and Ctl+K '9 will give you the closing curly single quote.
  • Similarly, Ctl+K "6 will give you an open curly single quote, and Ctl+K "9 will give you the closing curly single quote.

Visual mode: turns out you can just hit o when in Visual mode to move the cursor to the other end of the selection.  Handy!

vim: cleaning up mixed indents

Thanks to the wiki for this.  If you run across a file that mixes tabs and spaces (ewww!), set the tab settings the way you want (e.g., ts=4 sts=4 sw=4 et ai) and run

:retab

to convert all the tabs to the right number of spaces. ¬†This takes tab stops into account, which :%s/^I/ ¬† ¬†/g won’t.

This replaces what I used to do, which was /^I s<Tab><Esc> followed by a whole lot of n.n.n.n.n.n.n.n. … . ¬†One command is much better ūüôā . ¬†I’m not even going to try to count the keystroke savings on my current project (pym, a preprocessor written in Python).

Filename searching in Explorer – Windows 8.1 Enterprise

Some tips for filename searches in the “Search” box in an Explorer window in Windows 8.1 Enterprise. ¬†I just found these out by trial and error.

  • You can specify “filename:” rather than “system.filename:” to search filenames.
  • The text after “filename:” will, by default, only match at the beginning of a word within the filename.
  • “filename:*foo” will search for foo, whether at the beginning of a word within the filename or not.
  • As far as I can tell, search¬†filenames get an implicit “*” added on the end unless you specify otherwise.
  • To search for a word in the name and also the extension, use “filename:foo AND ext” where DOS would have required “*foo*.ext”. ¬†I tried “filename:*foo*.ext” and “filename:(foo AND ext)” without success. ¬†Remember, the “AND” has to be uppercase!

Happy searching!

Boolean searching in Microsoft Outlook

Turns out it can be done!  This article from Slipstick Systems shows you how to enable the Query Builder in the Advanced Find dialog box.

I was trying to search for two partial words in the Subject of my emails in Outlook 2013. ¬†Turns out the “Search” box in the folder view only finds matches at the start of a word. ¬†The Advanced Search dialog box, Advanced pane, looked promising. ¬†However, when I added multiple criteria, I think it was ORing them rather than ANDing. ¬†Not sure, but I do know that I added two separate Subject terms and not all the results had both terms in their Subject fields.

With Query Builder, each search criterion I entered was automatically added to an AND group, and the search results were what I expected. ¬†Now if only you didn’t have to tweak the registry to enable this incredibly useful feature…

Breaking infinite loops in VBA

I do a lot of Visual Basic for Applications (VBA) development in Microsoft Office. Any program can get stuck in an infinite loop, and when my VBA programs have it has always meant data loss. The Internet to the rescue, as of not quite a month ago!

To break VBA code execution, at least in Office 2013, hit Ctrl+Scroll Lock. ¬†Obvious, right? ūüėČ

Huge thanks to¬†MSDN user povidla, who posted this solution in¬†the MSDN forums. ¬†Povidla, if you’re reading this, please comment so I can thank you directly!

Edit I have found that, in some situations, this doesn’t work unless there is a DoEvents call to catch the Ctrl+ScrLk. ¬†If you have a loop that might be infinite, sticking a DoEvents in it is probably a good practice.

Greetings to Stack Overflow users!  I keep hoping that Povidla will find this page.  If you happen to know who Povidla is, please pass along a thank you from me.  Regardless, thanks for reading!

How not to waste disk bandwidth

In the Windows 7 search box, keywords are case-insensitive, but Boolean operators are case-sensitive.  Typing

System.FileName:~=".doc" AND datemodified:‚Äé1/‚Äé5/‚Äé2016

works fine. Typing

System.FileName:~=".doc" and datemodified:‚Äé1/‚Äé5/‚Äé2016

doesn’t given an error message or a warning ‚ÄĒ it just burns a lot of disk searching and finding nothing. Live and learn!

Adventures in vim

Just ran across this question on Stack Exchange by DJ McMayhem, which pointed out a great tip for commenting blocks of code. Say you have

int main()
{
  int answer=42;
  string question;
  for(int i=0; i&lt;answer; ++i) {
    question += "what do you get";
  }
  return answer;
}

and want to comment out the question. I used to do that by putting the cursor on line 4 (string question), hitting ma to save my place in mark a, moving down to line 7 (the end of the for loop), and doing :'a,./s/^/\/\//<Enter>.

Thanks to DJ McMayhem, I can now do that by starting on line 4, hitting v3j to select the lines in question, and doing :norm0i//<Enter>. Result:

int main()
{
  int answer=42;
//  string question; 
//  for(int i=0; i<answer; ++i) {
//    question += "what do you get";
//  }
  return answer;
}

Original: 20 keystrokes (counting Enter, but not counting Shift presses as separate keystrokes)

New: 13 keystrokes ūüôā

My next adventure is to wrap :normal in a function so I can use :N or some such, for a savings of a further three keystrokes!

Adventures in vim

Vim is my text editor of choice.  (emacs users, commence flaming!)  Yesterday I discovered ip and today I discovered Control-O.  Best shortcuts ever!

ip selects the current paragraph, delimited by blank lines unless you set the modes otherwise.  I used to select whole paragraphs with {y}, which copied extra lines and lost my cursor position.  Now I can copy with yip, which grabs just the paragraph text and keeps the cursor firmly planted.  Fantastic!  See :help object-select for more.

Control-O is a get-out-of-insert-mode-free card. ¬†When inserting, hit Control-O and you’ll be back in command mode for the duration of one command. ¬†That can be a colon or immediate command. ¬†For example, <Ctrl-O>f, will jump you forward to the next comma — without leaving insert mode. ¬†Esc, w or f or / or what have you, i has been my everyday for years. I am thrilled about saving one keystroke per such action times ~1e100 actions over my vimming life. More at¬†:help ins-special-special.

Stay tuned for more adventures in vim!