Atom Editor - Body Keybind for Everything Except Vim Mode Insert - coffeescript

I am an avid Vim user who recently decided to give Atom a try. In vim I map ,bn & ,bp to next buffer and previous buffer, respectively. I am trying to imitate the same behavior in Atom for switching between tabs. In my keymap.cson file I have the following:
'body':
', b n': 'pane:show-next-item'
', b p': 'pane:show-previous-item'
This will work except if I try to type just the ',' character in Vim mode insert it will not display unless I hit ',' twice.
I thought maybe the following would work, but it had no effect:
'body .vim-mode:not(.insert-mode)':
', b n': 'pane:show-next-item'
', b p': 'pane:show-previous-item'
Any help is appreciated!

Turns out I simply forgot to add the atom-text-editor selector before the .vim-mode:not(.insert-mode) selector. Changed the script to the following and it worked:
'body atom-text-editor.vim-mode:not(.insert-mode)':
', b n': 'pane:show-next-item'
', b p': 'pane:show-previous-item'

Related

neovim :imap but stay printing before to replace

I'm writing a mapping in neovim. Here is:
:imap abcd efgh
When I type 'abcd', it replaces by 'efgh'. This is the expected behavior.
But as typing 'abcd', it prints a, then replaces a by b, then replaces b by d and, finally when I type 'd', it prints efgh. My cursor never moves.
In other words I never see "abc" as a whole.
What I want is to see "abc" and then, when typing "d", the whole gets replaced by "efgh".
I kind of remember that, in vim-latexsuite, I had :call IMAP ("abcd", "efgh") which made the work.
Is it possible with nvim ?

Unintended Indents with Plain Text Email

I have a function that will send plain text and HTML emails. When coding, I indent code to get proper nesting. Note the two code strings below.
$plain_text = '
*Hi ' . show_user_name($user_id) . '. Thanks for signing up!*
';
$plain_text = '
*Hi ' . show_user_name($user_id) . '. Thanks for signing up!*
';
When the second one is sent as plain text email, the line "*Hi...." is indented.
How can I prevent this from happening?
In short, it's indented because you indented it!
In plain-text email messages (unlike HTML), white space is preserved and significant, so if you don't want leading spaces, strip them from your content:
$plain_text = preg_replace('/^ +/m', '', $plain_text);
You need the m modifier to apply the leading space stripping to each line in the body.
Alternatively, don't indent in the first place - the indenting of your code doesn't have to be related to the format of the text that you generate:
$plain_text =
'*Hi ' . show_user_name($user_id) . '. Thanks for signing up!*';
If you're using tabs for indents, you could filter those out too:
$plain_text = preg_replace('/^[ \t]+/m', '', $plain_text);

How to use tab in disp()?

disp(['counter ' num2str(blk) (here I need a tab!!!) 'adc ' num2str(adc_nr)])
Try
disp(['counter ' num2str(blk) 9 'adc ' num2str(adc_nr)])
Explanation: Usually if you want to insert a tab, you put a '\t' in the string. This works well for sprintf, but the disp command doesn't interpret it properly. So one solution is to put the ASCII value of the tab directly, which is '9'.

Vim: change formatting of variables in a script

I am using vim to edit a shell script (did not use the right coding standard). I need to change all of my variables from camel-hum-notation startTime to caps-and-underscore-notation START_TIME.
I do not want to change the way method names are represented.
I was thinking one way to do this would be to write a function and map it to a key. The function could do something like generating this on the command line:
s/<word under cursor>/<leave cursor here to type what to replace with>
I think that this function could be applyable to other situations which would be handy. Two questions:
Question 1: How would I go about creating that function.
I have created functions in vim before the biggest thing I am clueless about is how to capture movement. Ie if you press dw in vim it will delete the rest of a word. How do you capture that?
Also can you leave an uncompleted command on the vim command line?
Question 2: Got a better solution for me? How would you approach this task?
Use a plugin
Check the COERCION section at the bottom of the page:
http://www.vim.org/scripts/script.php?script_id=1545
Get the :s command to the command line
:nnoremap \c :%s/<C-r><C-w>/
<C-r><C-w> gets the word under the cursor to command-line
Change the word under the cursor with :s
:nnoremap \c lb:s/\%#<C-r><C-w>/\=toupper(substitute(submatch(0), '\<\#!\u', '_&', 'g'))/<Cr>
lb move right, then to beginning of the word. We need to do this to get
the cursor before the word we wish to change because we want to change only
the word under the cursor and the regex is anchored to the current cursor
position. The moving around needs to be done because b at the
start of a word moves to the start of the previous word.
\%# match the current cursor position
\= When the substitute string starts with "\=" the remainder is interpreted as an expression. :h sub-replace-\=
submatch(0) Whole match for the :s command we are dealing with
\< word boundary
\#! do not match the previous atom (this is to not match at the start of a
word. Without this, FooBar would be changed to _FOO_BAR)
& in replace expressions, this means the whole match
Change the word under the cursor, all matches in the file
:nnoremap \a :%s/<C-r><C-w>/\=toupper(substitute(submatch(0), '\<\#!\u', '_&', 'g'))/g<Cr>
See 3. for explanation.
Change the word under the cursor with normal mode commands
/\u<Cr> find next uppercase character
i_ insert an underscore.
nn Search the last searched string twice (two times because after exiting insert mode, you move back one character).
. Repeat the last change, in this case inserting the underscore.
Repeat nn. until all camelcases have an underscore added before them, that is, FooBarBaz has become Foo_Bar_Baz
gUiw uppercase current inner word
http://vim.wikia.com/wiki/Converting_variables_to_camelCase
I am not sure what you understand under 'capturing movements'. That
said, for a starter, I'd use something like this for the function:
fu! ChangeWord()
let l:the_word = expand('<cword>')
" Modify according to your rules
let l:new_var_name = toupper(l:the_word)
normal b
let l:col_b = col(".")
normal e
let l:col_e = col(".")
let l:line = getline(".")
let l:line = substitute(
\ l:line,
\ '^\(' . repeat('.', l:col_b-1) . '\)' . repeat('.', l:col_e - l:col_b+1),
\ '\1' . l:new_var_name,
\ '')
call setline(".", l:line)
endfu
As to leaving an uncompleted command on the vim command line, I think you're after
:map ,x :call ChangeWord(
which then can be invoked in normal mode by pressing ,x.
Update
After thinking about it, this following function is a bit shorter:
fu! ChangeWordUnderCursor()
let l:the_word = expand('<cword>')
"" Modify according to your rules
let l:new_var_name = '!' . toupper(l:the_word) . '!'
normal b
let l:col_b = col(".")
normal e
let l:col_e = col(".")
let l:line = getline(".")
exe 's/\%' . l:col_b . 'c.*\%' . (l:col_e+1) .'c/' . l:new_var_name . '/'
endfu

T-SQL, Remove space in string

I have two strings in SQL and the REPLACE function only works on one of them, why is that?
Example 1:
SELECT REPLACE('18 286.74', ' ', '')
Example 2:
SELECT REPLACE('z z', ' ', '')
Example 1's output is still "18 286.74" whereas Example 2's output is "zz". Why does SQL not react the same way to both strings?
UPDATE:
When running select replace('123 123.12', ' ', '') that works fine, still not with '18 286.74'.
Test it the following way.
select unicode(substring('18 286.74', 3, 1))
If the code returns 32 then it's a space, if not, it's a different Unicode character and your replace ' ' won't work.
maybe cast is needed.
UPD: or not(on sql 2005 works fine too)
Are you sure it is a space? i.e. the same whitespace character that you are passing as the second argument? The code you've posted works fine for me on SQL Server 2008.
Re working on your friends PC - perhaps the whitespace got normalized when you sent it to him?
You are probably using non-breakable space.
I could reproduce it by typing ALT+0160 into the number in SELECT REPLACE('18 286.74', ' ', '')
Could you please issue this following:
SELECT CAST('18 286.74' AS BINARY), REPLACE('18 286.74', ' ', '')
by copying the '18 286.74' from REPLACE into CAST?
I was having the same issue and found that it was a char(10) (line feed). when copied out of Managment Studio it became a char(32) but in the record it was a char(10) try
Select Replace(#string, char(13), '')