I know that there exists String.upper for the alphabet, but I'm looking for the shift version rather than the alphabetic version, such as the "uppercase" of the semicolon would be the colon. When I attempt to google I get irrelevant results about string.upper.
I think the best way to handle this would be a lookup table, for example:
local with_shift = {
["1"] = "!",
["2"] = "#",
["3"] = "#",
}
I haven't been able to find an existing table of this, but I'm sure one exists somewhere.
If you are using that for input, you can always check that both the ',' key and the shift key are pressed at the same time - and then execute whatever code you wanted to do.
As others are saying, keyboard layouts are not universal. In a French keyboard, for example, you have to press shift in order to get a '1' when pressing the '1' key in the "top" number row (it defaults to symbols). Neither LÖVE nor Lua know all the keyboard layouts available, and even if they did you could be using a custom-made one (I in fact use one on my computer).
Related
I believe that it is used to determine which keyboards shortcut will be used and in this example underscore defines that (even though I'm not 100% positive about that).
Let's say there is a string on weblate like this:
make all _uppercase
Does that mean that there will be e.g. ctrl+u keyboard shortcut for this command or some defined key + u?
If that's correct, I have following question, what should be done if for some reason there is no "u" letter in corresponding translated phrase?
Should it be translated without using underscore?
I've seen use of something like (_u) after translated sentence,
"corresponding phrase in other language (_u)"
Is it ok to do it like that?
I need to find out which key was pressed, not what character it would be.
For example, I want after pressing 'a' a number such (1) create so I can map it to other languages. In common way we can find it is 'a' or we can have it's hash code, but is it possible to have char or hash code in a language and find out what char or hash code it would be in another language?
Attention some language have not the standard keyboard so pressing a key not mean a certain character.
There's no reason to do this in any language i've seen.
(besides the fact that you didn't specify in which language you are trying to achieve this)
All languages allow you to get the character code from a keypress.
If you know which encoding was used (UTF 8, Ascii, you name it), it's trivial to map the code to the actual character.
Assigning a different keyboard layout on OS level means that it no longer matters which keyboard layout you are using.
if you have a QWERTY keyboard, switch it to AZERTY and press the button where the q would be, you get an a, despite the letters on the keyboard still saying QWERTY.
If you are using a chinese keyboard, the characters no longer map to any western set, so the character codes will not match up with UTF8 or ASCII, but CP963 (or another chinese codepage, depending on several factors), which is so different there is no real way to translate it to UTF8 or ASCII.
value(val_1)
value(val_100)
value(val_10)
I want to select text between parentheses and do it for multiline, for one line I can use f(va( but I don't know how to select for 2 remaining lines.
EDIT (SOLUTIONS)
What I want to is to change text inside parentheses with unique text every line, firstly, I was thinking to select the text, delete it then change the text manually, #rosipov tell there is a plugin to do the selection part and it's great, but #romainl gave me another direction that works too.
f(ci(foo<Esc>jci(bar<Esc>jci(baz<Esc>
Do you want to select this:
value([val_1])
value([val_100])
value([val_10])
or to select that:
value([val_1)]
[value(val_100)]
[value(val_10])
The first is unfortunately not doable. But depending on what you want to do with the selected text, change it for example, a reasonable approximation would be:
f(l<C-v>jj$cnew value)<Esc>
However I'm sure a lot of Vimmers would probably approach the problem with a substitution:
:,+2s/(.*/(new value)
The second is done simply with:
f(lv3/)h
or
f(ljjt)
You will probably be interested in EasyMotion plugin in this case: https://github.com/Lokaltog/vim-easymotion
With plugin it will be: f(vLeaderLeaderf)c
Or: LeaderLeaderf(avLeaderLeaderf)c
Where c is letter representing 3rd closing parentheses, a represents first opening p.
EDIT: Without plugin it is possible to do it by line number.
Assuming that you work with lines 1-3: f(v3Gf)
Where 3G stands for "go to line number 3", works in both visual and normal modes.
Using vim I would like to replace all characters up to a certain one with another character, say a blank space - without affecting the layout/number of characters in the line. Here's an example:
Before:
real(kind=R12), intent(out) :: my_var
After replacing , intent(out) with blanks (i.e. starting from ,, and going up to )):
real(kind=R12) :: my_var
I know about r to replace one character, and about nr to replace n characters, but I would like to know whether I can accomplish my task without first having to count the characters I want to replace.
Thanks a lot for your replies!
Visual mode is probably the shortest way here:
vt:r
v enter visual mode
t: select till :
r (note space after r) replace selected region with spaces.
In command mode type 'df?' to delete up to that (?) character. Then 'i' to go back to insert.
For example if the following sentence is in your view:
The wizard quickly jinxed the gnomes before they vaporized.
and you enter dfs
You will be left with:
before they vaporized.
I know about r to replace one character
Did you know that R will keep you in that replace mode? So you could hit R and then hold Space until you've replaced everything you want.
However, I'd still go with Thor's answer. Visual mode allows you to use the efficient text navigation methods in vim without having to count out characters.
But if you disagree, there's always EasyMotion.
You can use regular expression here (use (.*?) to reference all values up to a token).
For instance:
The regex: (.*?)foo will get rid of everything up to foo.
I am trying to use vim properly - to aid me I've mapped my arrow keys to "" so that I am forced to use {hjlk} to move around.
This is causing me a problem when I want to just surround a character with spaces, eg:
"2+3" is better formatted "2 + 3"
Previously I would have put my cursor over the + and typed:
i[space][arrow-right][space][Esc]
That's 5 presses.
To do this without the arrow I seem to need to put the cursor over the + and go:
i[space][Esc]lli[space][Esc]
That's 8 presses.
I can convert the "li" into an "a" which reduces it to 7 presses:
i[space][Esc]la[space][Esc]
Short of writing this into a macro is there a better way of doing it? Is there some magic vim command which will allow me to do it in less than even 5 presses - and some way to generalise it so that I can do it to entire words or symbols, eg if I want to convert 3==4 to 3 == 4?
Personally, I think it makes most sense to destroy what you want to surround, and then repaste it.
c w "" ESC P
Obviously, you can replace both the object and the quotes with whatever you like. To change just one character + to be [space]+[space], you would do
s [space] [space] ESC P
on the +
The first thing that jumps to mind after reading just the title is surround.vim which is an excellent script to do all kinds of useful things along the lines of what you've described.
To solve your specific problem, I would probably position the cursor on the + and:
s[space]+[space][esc]
To change 3==4 into 3 == 4, I might position the cursor on the first =, and:
i[space][esc]ww.
i have been wondering about this as well. i tried with surround.vim, but the naive approach
S<space>
(after making a visual selection) does not work since the space is already taken up as a modifier for adding space to other surrounding character pairs. S<space><cr> adds a ^M in the output. Ss almost works but inserts a space only before.
after asking at tpope/surround.vim on github:
S<space><space>
in visual mode works. alternatively, from normal mode, ysl<space><space> works for a single character
Hah! I've been trying to figure out how to surround a block in spaces for quite a while and I finally found the right combination.
Using surround.vim you say surround selector space space.
So for this specific case I would use visual mode (a good trick for operating on single characters under the cursor BTW) thus: "vs " <- four key presses!
I also have a habit of typing things like argument lists without spaces. With this technique you can just navigate to the second argument using w and say "vws " to visually select a word and surround with spaces.
I prefer visual select mode generally. Also the alternate surround syntax "ysw " excludes the word final comma that is caught by "vw".
You could create a macro with one of the described actions and call it everytime you need it (Like amphetamachine proposed while I was writing) or you could simply search & replace:
:%s/\(\d\)\(+\|-\)\(\d\)/\1 \2 \3/g
You probably have to execute this command two times because it will only find every second occurence of +/-.
EDIT:
This will replace everything without the need to be called twice:
:%s/\d\#<=+\|-\d\#=/ \0 /g
Try positioning your cursor over the '+' and typing this:
q1i[space][right arrow][space][left arrow][esc]q
This will record a quick macro in slot 1 that you can re-use whenever you feel like it, that will surround the character under the cursor with spaces. You can re-call it with #1.
There is also the more versatile one:
q1ea[space][esc]bi[space][right arrow][esc]q
Which will surround the word under the cursor ("==" counts as a word) with spaces when you hit #1.
You could set up a mapping like this (press enter in visual mode to wrap spaces):
:vnoremap <CR> <ESC>`<i<SPACE><ESC>`>la<SPACE><ESC>h
This method allows you to use . to repeat the command at the next +.
Put your cursor over the + and type:
s[SPACE][CTRL-R]"[SPACE][ESC]
I know this is and old thread, but this might be useful to someone. I've found that the map (map it to anything else you want!)
noremap <leader>ss diwi<SPACE><C-R>"<SPACE><ESC>B
works ok both for turning 'a+b' into 'a + b' (when used over the '+' char) and for turning 'a==b' into 'a == b' (when used over either the first or the second '=' sign).
I hope it's useful to someone.