RStudio Environment TAB missing blanks on strings. Is this a BUG? - rstudio

On RStudio console, I enter:
S = "a b"
then, on environment TAB, I see S = "a b"
The spaces have collapsed to only one space!?
Is this a BUG ?
Very annoying this behaviour

Related

How to make Visual Studio's Immediate window give me plain string output?

If I evaluate something in Immediate that produces a long and complex string, the debugger encodes everything in C string escapes, so I end up with a mess of \n, \t, and so on throughout my text which I then have to fix by hand. (Which is particularly annoying in the case of \n, as most text editors can't do multiline search-and-replace!)
Is there any way to get the debugger to give me the raw, un-munged, multi-line string value?
We could check the string value with Text Visualizer in Watch window, which will show the string value without any \n and \t content.
Please add a breakpoint in the string variable in your code and start debugging your code. When the breakpoint hit, you could right-click the variable and choose "Add Watch" Then press F11 to go to next line of code. Now you could view the string value from Watch window by click the "Text Visualizer" icon. It will not show the \n and \t.
You can use C# Interactive Window (Views > Other Windows > C# Interactive).
Usage:
Type command:
Console.Write("r1bqkb1r/pp3ppp/2p5/3pP3/P2Q1P2/2N1B3/1PP3PP/R4RK1 w - - 1 2\nr1bqkb1r/pp3ppp/2p5/3pP3/P2Q1P2/2N1B3/1PP3PP/R4RK1 w - - 1 2")
Then I'll get:
r1bqkb1r/pp3ppp/2p5/3pP3/P2Q1P2/2N1B3/1PP3PP/R4RK1 w - - 1 2
r1bqkb1r/pp3ppp/2p5/3pP3/P2Q1P2/2N1B3/1PP3PP/R4RK1 w - - 1 2
C# Interactive Window is independent from the project so it will work on all projects of all language (C#, C++,...)
Here is the demo image:
Set a format specifier at the end of the expression in the immediate window.
Problem:
? "test string with escape chars \r\nThis is on the next line"
"test string with escape chars \r\nThis is on the next line"
Add the , nq format specifier to the end:
? "test string with escape chars \r\nThis is on the next line", nq
test string with escape chars
This is on the next line
This works exactly the same with a real variable:
? testvariable, nq
test string with escape chars
This is on the next line
(I tried the answer from Konstantine Kozachuck using a format specifier on the Print statement and it did not work the same way the ? statement did, but it did help me figure out want I wanted.)
Print variableName,sb.
Example (Immediate window):
>"raw\nmultiline\tstring",sb
raw
multiline string
Documentation: https://learn.microsoft.com/en-us/visualstudio/debugger/format-specifiers-in-cpp?view=vs-2019

Vim Command Mapping "Copy to Clipboard" Not Working

I recently began using Vim as my primary editor instead of programs like Atom/VSCode. I added a number of leader mappings to simplify tasks I do quite often but I'm having trouble with a few of them.
In Visual mode, I would like to be able to press <Space>y to copy the current selection to the clipboard (+ register). I've verified that I can do this manually by entering visual mode, selecting the text I want, and pressing "+y. However, my mapping doesn't seem to work:
vmap <Leader>y "+y
I set my leader the following way:
map <Space> <Leader>
I do it this way so that when showcmd is set, I get a visual indicator in operator-pending mode. By looking at that indicator, I can tell that when I press <Space>, I do enter operator pending mode on the \ key as expected. Then, when I press y, I am no longer in operator pending mode, but I am still in visual mode and haven't yanked the selection to the register.
To make sure there wasn't a plugin colliding with my mapping, I backed up my .vimrc and replaced it with one that only has the following contents:
set showcmd
map <Space> <Leader>
vmap <Leader>y "+y
Does one of these keys need to be escaped? Or am I doing something else wrong?
(I'm currently running Ubuntu Bash on Windows. Vim is version 7.4)
For reference, I got the idea from this article (And use the exact same command):
https://sheerun.net/2014/03/21/how-to-boost-your-vim-productivity/
Thankfully, the fix is pretty simple.
map <Space> <Leader>
is incorrect. The right way is
let mapleader=" "
From :help mapleader
*<Leader>* *mapleader*
To define a mapping which uses the "mapleader" variable, the special string
"<Leader>" can be used. It is replaced with the string value of "mapleader".
If "mapleader" is not set or empty, a backslash is used instead. Example: >
:map <Leader>A oanother line<Esc>
Works like: >
:map \A oanother line<Esc>
But after: >
:let mapleader = ","
It works like: >
:map ,A oanother line<Esc>
Note that the value of "mapleader" is used at the moment the mapping is
defined. Changing "mapleader" after that has no effect for already defined
mappings.
How to define the "leader" key is explained under :help mapleader. If you want to use <Space> as "leader" you are supposed to do:
let mapleader = "\<Space>"
Note that the "leader" key is not a special key at all. With <Space> as "leader", the two mappings below are strictly equivalent:
vmap <leader>y "+y
vmap <Space>y "+y

mac Terminal app:what is the shortcut for "goto next tab"?

In terminal app,when I enter "command + {" or "command + {",it will go next or before window, not next tab,who can tell me ,why?
You probably entered cmd[ and cmd] accidentally, since they do change the window.
Make sure to enter cmdshift[ and cmdshift] as they produce cmd{ and cmd} respectively.
This is because shift[ = {, etc., depending on your keyboard layout. (Just as you would press shift[ to type {, provided you're using the English or some similar keyboard layout.)
There are plenty of ways to switch tabs.
You can use command + shift + }, swipe with three fingers, or use command + [tab number, i.e. 1].
final ,I found ,the answer is "shift + command + }"。 but,in teminal menu,it show the "command + {" is shortcut for "show pervious tab"。

Bash keybinding with "bind" - avoid recursion like noremap in Vim

I've remapped the following keys in Bash:
bind '"a" "b"'
bind '"b" "c"'
If I press a or b both times a c will be printed.
How can I map the keys so that by pressing a and b will be printed and only by pressing a and c will be printed (like with Vims **nore**-map)?
You can make a char in the right part a literal with a preceeding "^V":
bind '"x":"^Vx "'
The key sequence to enter the text after colon is:
" Ctrl-v Ctrl-v x space "
In bash "Ctrl-v x" results in a literal x, without key-mapping interpretation .
You may find it useful to build your own keymapping file which maps the numeric signal you get from the keyboard to a character. This is done with the loadkeys command i.e. if you're switching to the dvorak layout you can do (this is a verbose way to show you the location of the map files:
loadkeys /usr/share/keymaps/i386/dvorak/dvorak.map.gz
You could copy the map file for the layout you use and change the relavent chars, and load your modified mapping. I think loadkeys only affects the command line, though there are similar methods for changing the behaviour in X I believe.

How does one align code (braces, parens etc) in vi?

How do you prettify / align / format code in vi? What is the command?
I have pasted in a hunk of code and I need to have it all formatted/aligned... obviously I am a vi neophyte.
x
These commands in my answer work in vim. Most people who think they're using vi are using vim. To find out if your 'vi' is really 'vim', open vi and type :version -- if it's vim, it will say so. Otherwise you might just see a version number without the name of the program. Also, when you open vim for the first time you will usually see a splash screen of some sort that says "VIM - VI iMproved"...
Automatic Indentation
To turn auto-indentation on, make sure vim knows the file type you're editing (it usually automatically detects this from the file name extension, but might not figure it out with some file types). You can tell it the filetype using the menus for syntax highlighting. Then, do this:
:filetype indent on
You can disable auto-indentation with
:filetype indent off
Automatically adjusting/correcting indentation
In general, ={motion} will align code to an indentation level.
== align the current line
=i{ align the inner block
=% align to the matching parenthesis/bracket under the cursor
=14j or 14== align the next 14 lines
=G align to the end of the file
vG= same thing, align to the end of the
file (but using visual mode)
vjjj= align four lines (using visual mode)
Manual indentation
If vim is not guessing the indentation level correctly, there are two ways to change it:
If you are in normal mode (where everything is a command), do << to shift a line left, or >> to shift it right by one tab. You can do this with several lines by using the same movement commands I showed above (eg, >i{ indents the current inner code block).
If you are in insert mode, you can indent the line further (without moving the cursor) by doing a Ctrl-T, or un-indent one tab with Ctrl-D
Aligning equals signs, etc
If you want to align equals signs in a list of declarations, you should consider using this vim script: http://www.vim.org/scripts/script.php?script_id=294
Adjusting indentation/tab sizes
If you want vim to use spaces instead of tabs when it indents, run this command (or consider adding it to your vimrc file)
:set expandtab
To set how many spaces equal a tab, I usually do this:
:set expandtab softtabstop=3 tabstop=3 shiftwidth=3
tabstop - how many columns a tab counts for (affects display of existing tab characters)
shiftwidth - controls reindentation size with << and >>, among other commands.
softtabstop - how much space to insert when you press the tab key
expandtab - expand tab keys to spaces
But if you have to work with different amounts of tabs a lot, you could also use this function and keybinding:
function! Ktabs(tabsize)
execute "set softtabstop=" . a:tabsize . " tabstop=" . a:tabsize . " expandtab shiftwidth=" . a:tabsize
"set softtabstop=a:tabsize tabstop=a:tabsize expandtab shiftwidth=a:tabsize
endfunction
noremap <leader><Tab> :call Ktabs(3)<Left>
If you are editing a file with a mix of tabs and spaces, you may want to use this command after setting tab size:
:retab
={motion}
:h =
P.S. You shouldn't use vi if vim is available.
If manually adjusting indents I will open a visual block with V on the first or last line I want to re-indent, move to the brace containing the block, goto the other brace with % then shift the line with > or <
If indents are off by a lot I will shift everything all the way left with < and repeat it with . and then re-indent everything.
Another solution is to use the unix fmt command as described in Your problem with Vim is that you don't grok vi., {!}fmt

Resources