投稿時間:2022-07-23 20:17:35 RSSフィード2022-07-23 20:00 分まとめ(20件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
AWS lambdaタグが付けられた新着投稿 - Qiita Lambdaでpythonの外部ライブラリをレイヤーで使用する方法 https://qiita.com/Tetsu_K/items/5ca13bece984ed8d6daf awslambda 2022-07-23 19:15:47
python Pythonタグが付けられた新着投稿 - Qiita Lambdaでpythonの外部ライブラリをレイヤーで使用する方法 https://qiita.com/Tetsu_K/items/5ca13bece984ed8d6daf awslambda 2022-07-23 19:15:47
js JavaScriptタグが付けられた新着投稿 - Qiita 私の運営しているサイトを紹介 https://qiita.com/efjnkw33/items/96e11f8d3109d153174b 運営 2022-07-23 19:24:27
AWS AWSタグが付けられた新着投稿 - Qiita AWSクラウドプラクティショナー合格体験記 https://qiita.com/MikaYamasaki/items/67d7952e48014b5c8661 awsclf 2022-07-23 19:40:17
AWS AWSタグが付けられた新着投稿 - Qiita Lambdaでpythonの外部ライブラリをレイヤーで使用する方法 https://qiita.com/Tetsu_K/items/5ca13bece984ed8d6daf awslambda 2022-07-23 19:15:47
AWS AWSタグが付けられた新着投稿 - Qiita 秒でウェブページ~EC2~ https://qiita.com/docdocdoc/items/ad61608fc69224751390 nmapncatsudoviindexhtml 2022-07-23 19:15:25
海外TECH DEV Community How to Create Vim Text-Objects in Lua https://dev.to/phantas0s/how-to-create-vim-text-objects-in-lua-e7f How to Create Vim Text Objects in Lua You don t get it Vim is like a language You ll speak Vim when you write When you go to the market You ll speak Vim with your cat When you think it will be the Word of Vimin your head You ll see It will change your life This is the kind of argument any Vim hippy would sing to the poor heretics trying to convert them to The Eternal Editor A hippy like me who s now writing an article about one of the main component of this language the text object Repeat after me glory to the text object It s powerful to use them that s true but we can do better We could create new text objects like a god creating life We could shape the Chaos to bring order in the galaxy The Greek god Hephaestus created the fire in his legendary forge Like him we also need some tools to create our own text objects What on Earth can we use Vimscript With Neovim we can use Lua to customize our favorite editor we can also compile Vim with Lua support To me one of the best way to learn how to customize Vim is to take already written functions in Vimscript and transform them in Lua The benefits If you don t know Vimscript analyzing the code to transform it in Lua will show you useful functions you can use for more customization It s essential for harnessing Vim s power If you don t know Lua you can learn it this way too It s a great programming language used by many other tools like the fantastic Pandoc for example You ll get a deeper understanding how Vim works allowing your to improve your workflow So let s taste the power of Vimscript functions combined with Lua constructs by implementing useful text objects More specificaly we ll see in this article The general principles governing text objects How to create a text object representing a line How to create text objects delimited by a pair of characters like two commas How to create a very useful and quite universal text object matching some level of indentation The text objects we ll create are inspired by other authors from The Great Internet You ll find the sources of this inspiration at the end of the article I assume here that you re somehow proficient with Vim If you don t understand what s happening in this article you can look at my series of articles to learn Vim If it s the first time you write some Lua I would encourage you to customize things further by modifying the examples we ll see in this article To use the correct syntax you should keep a quick reference on side like this one Are you ready to dive into Vimscript Lua and text objects I m sure you are Let s go What s a Text Object Before jumping into Vim to create our new delightful text objects let s first do what any developer should do when she needs to solve a problem thinking Let s decompose what a text object is Text objects are NORMAL mode keystrokes using two keys the first one can only be an a for around or an i for inside A text object represents a specific string of characters with a beginning and an end It can only be used after an operator or after switching to VISUAL mode character wise using v in NORMAL mode The operator will act on the text object VISUAL mode will select the text object itself To apply an operator on some text objects the cursor doesn t have to be on the text object itself In that case the operator will act on the next text object of the line If you never heard of the rule it can change your life and bring you glory and fortune in a couple of days Nothing less If you type di in NORMAL mode and your cursor is before a pair of parentheses you ll move inside them The operator d will then delete everything inside Neat As I was saying just above a text object can begin with an a or an i I understand text objects beginning with a as around even if Vim s help will refer to them as the indefinite article a like delete a word I prefer around because this kind of text objects often include some characters around the inside text object It s a good mnemonic to remember the difference between the two Motions are looking a lot like text objects but they re not the same Using an operator before a motion will perform an action from the cursor position to the end result of the motion A text object doesn t necessarily start at the cursor position that s the biggest difference For example daw will delete around a word whatever the letter of the word your cursor is on Using a motion dw will delete from the cursor position to the next word Now that we explored the problem space let s enter the solution space To create a text object with a start and an end we could simply Select the characters we want Apply whatever operator on the selection That s great because Vim has some mapping allowing us to do that easily Vim Help help text object help motion The Operator Pending Mapping BasicsWhen we hit an operator in NORMAL mode like d y or c for example we switch silently to the OPERATOR PENDING mode It s in this mode that we ll input our motion or text object we want to operate on Then we switch back to NORMAL mode automagically To define new text objects or motions which can be used in OPERATOR PENDING mode you can use an operator pending mapping omap or if you don t want a recursive mapping onoremap Thanks to them we only need to worry about selecting the characters included in our text objects we don t care about the operators themselves The Line Our New Text ObjectLet s now create the first text object of this article a line The text object al around the line will delete everything including the possible indentations at the beginning The text object il inside the line won t delete the indentation Here s a first mapping for il onoremap lt silent gt il lt c u gt normal v lt cr gt In case you re not sure what that means here are some explanations lt silent gt Don t echo the Ex command executed in the command line window lt c u gt Delete everything already written in COMMAND LINE mode like the selection markers lt gt for example normal This Ex command allow executing NORMAL mode keystrokes v Go to the end of the line switch to VISUAL mode and select till the beginning of the line without the eventual white spaces For example if you hit yil or dil your operators yank and delete will operate on our new text object If we only want to select it we need another mapping for VISUAL mode xnoremap lt silent gt il lt c u gt normal v lt cr gt You can now hit vil and admire the potential of your infinite skills We have now the inside version of our text object what about the around one xnoremap lt silent gt al lt c u gt normal v lt cr gt onoremap lt silent gt al lt c u gt normal v lt cr gt These mappings follow the same principles except that we select everything this time including the eventual whitespaces at the beginning of the line We could also use V instead of v Vim Help help omap info The Missing Text ObjectsOur new text objects are great but we can do better This time we ll create a whole series delimited by different pair of characters Between Two CharactersIt s easy to delete a pair of parentheses a a or even ab are there for you As always there are some inside variants too But what about deleting everything between two dots Between two hyphens Between two commas What about creating text objects delimited by these characters amp To solve this problem we could look at a simple example Hello how are you you If we want to change the characters between the two commas we could Move the cursor to the first comma Select everything till the second comma Whether including the commas in the selection or not will be the difference between the around and the inside text object This scenario requires our cursor to be between the two commas at least for now We ll improve this soon To move our cursor to the first or second comma we can use f F t and T in NORMAL mode Here s a possible solution xnoremap lt silent gt i lt c u gt normal T vt lt cr gt onoremap lt silent gt i lt c u gt normal T vt lt cr gt xnoremap lt silent gt a lt c u gt normal F ft lt cr gt onoremap lt silent gt a lt c u gt normal F ft lt cr gt We could repeat these mappings for every character we want to include But it would be quite difficult to read and maintain Taking some inspiration from a Zsh snippet I ve already covered in this article we could Loop through all the different characters Loop through all the different modes we want to map OPERATOR PENDING mode and VISUAL mode Create the different mappings for each iteration Here s a possible implementation in Vimscript let s chars lt bar gt lt bslash gt for char in s chars for mode in xnoremap onoremap execute printf s lt silent gt i s lt C u gt normal T svt s lt CR gt mode char char char execute printf s lt silent gt a s lt C u gt normal F svf s lt CR gt mode char char char endforendforI like to use Vimscript for simple configurations but as soon as I need to reach for loops or conditionals I hate the equality operators mess in Vimscript I switch to Lua If you use Neovim or if you have Vim compiled with Lua you can use the following function basic text objects local chars for char in ipairs chars do for mode in ipairs x o do vim api nvim set keymap mode i char string format lt C u gt normal T svt s lt CR gt char char noremap true silent true vim api nvim set keymap mode a char string format lt C u gt normal F svf s lt CR gt char char noremap true silent true end endendreturn basic text objects basic text objects I would advise you to keep your Lua scrips in a lua lt namespace gt folder lt namespace gt could be your username or anything else you d like For example my scripts are in XDG CONFIG HOME nvim lua hypnos Then you can call directly your new functions in your vimrc If it s a Vimscript file you ll need the prefix lua as follows lua require lt namespace gt text objects basic text objects To The Next Text ObjectRight now we need our cursor between the two characters to act on our new text objects It would also be nice to be able to operate on the first pair of these characters when our cursor is before them As we saw above in this article it s already what we can do with parenthesis or quotes Let s consider the following example She felt suddenly deeply in love with Vim We could try to end up on the first comma of the pair whether the cursor is before them or between them From there we would select everything till the second comma Here s a possible mapping onoremap lt silent gt i lt C u gt silent normal f F lvt lt cr gt Let s imagine that the cursor is on the first d of suddenly between the commas f Move to the second comma F Move to the first comma l Move one character to the right on the space after the comma vt Visually select everything till the next comma Now let s imagine that our cursor is on the S of She before the commas f Move to the first comma F There is no comma before the cursor to be found so the Ex command normal fails l Move one character to the right on the space after the comma vt Visually select everything till the next commaNote that the Ex command normal fails at the second step By default it would stop there not executing the steps and That s why we add the Ex command silent here it will force normal to execute till the end For the around text object we can follow the same principles The only difference we also select the two commas onoremap a lt C u gt silent normal f F vf lt cr gt Here s the final result in Lua function basic text objects local chars for idx char in ipairs chars do for idx mode in ipairs x o do vim api nvim set keymap mode i char string format lt C u gt silent normal f sF slvt s lt CR gt char char noremap true silent true vim api nvim set keymap mode a char string format lt C u gt silent normal f sF svf s lt CR gt char char noremap true silent true end endendKeep in mind that it s a naive approach First making the normal command fails feels a bit like a hack Additionally it s quite difficult to understand That said sometimes a hack is good enough to answer our needs and move forward I wouldn t use that in a plugin which could be used by others but for my own use it s good enough Each time we ve created our text objects we first stated the problem and then tried to find a way toward a solution That s a good iterative approach but it also means that our text objects might not cover all the possible scenario We can still improve things afterward if we see that our text objects don t behave as expected in specific situations This is different from installing a plugin you often have no idea how it works and you can t modify them iteratively to answer your specific needs Text Objects Based On IndentationsLet s create one more text object more complex this time It can be useful for any developer The BasicsIf you look at the text objects already available in vanilla Vim their boundaries are based on specific characters There are other important elements you ll find in most codebases which can be used for a text object indentations Here s how to select our new text objects Get the starting indentation of the current line This will be the indentation of reference we ll compare every other line to Move up line by line as long as the indentation is equal or higher to the starting indentation Stop when the next line doesn t fulfill the rule anymore and begin VISUAL mode line wise Move down till the indentation is equal or higher to the starting indentation It means that our text objects include all the lines having the same indentation as the one you start with or higher Since the behavior is more complex than other text objects we ve created let s implement a function we ll call in our mappings function IndentTextObject let startindent indent line Move up till we are at the top of the buffer or till the indentation is less than the starting one let prevline line while prevline gt amp amp indent prevline gt startindent let prevline line endwhile Begin linewise visual selection normal V Move down till we are at the bottom of the buffer or till the indentation is less than the starting one let nextline line let lastline line while nextline lt lastline amp amp indent nextline gt startindent let nextline line endwhileendfunctiononoremap lt silent gt ai lt C U gt call IndentTextObject lt CR gt onoremap lt silent gt ii lt C U gt call IndentTextObject lt CR gt xnoremap lt silent gt ai lt C U gt call IndentTextObject lt CR gt xnoremap lt silent gt ii lt C U gt call IndentTextObject lt CR gt Again I always prefer using Lua when things get slightly complex function select indent local start indent vim fn indent vim fn line local prev line vim fn line while prev line gt and vim fn indent prev line gt start indent do vim cmd prev line vim fn line end vim cmd normal V local next line vim fn line local last line vim fn line while next line lt last line and vim fn indent next line gt start indent do vim cmd next line vim fn line endendfunction indent text objects for mode in ipairs x o do vim api nvim set keymap mode ii lt c u gt lua select indent lt cr gt noremap true silent true vim api nvim set keymap mode ai lt c u gt lua select indent lt cr gt noremap true silent true endendreturn indent text objects indent text objects The core of the functions are the two while loops They will Move the cursor up till the previous line has less indentation than the starting one Begin VISUAL mode line wise with normal V and go down line by line selecting the ones at the same level of indentation or higher Note that we use the Ex command and to move up and down Yes they re Ex command try for example You could also use normal k or normal lt up gt Improving the ImplementationOur little function works great but it shows quickly its limits Perhaps the most obvious the inside and around text objects have the exact same behavior Horror and damnation Let s say that the around the text object should select two more lines the first lines having fewer indentations when we move up and down To illustrate consider the following code The symbol ┃ represents the cursor Commentfunction super function ┃ if true then print youpi print wuhu endend CommentHitting dii would delete the whole if block but let everything else untouched Hitting dai would delete everything except the two comments From there we have two solutions Create two different functions one for the around text object one for the inside Pass a boolean flag to use the around or inside text object in the same function If we go with the first solution we would have almost identical functions it s likely we would need to change both each time we want to improve our text objects So let s go with the second solution That said if there are too many conditionals creeping in because there are more and more differences between the two text objects I would definitely split the function Here s a possible implementation function select indent around local start indent vim fn indent vim fn line local prev line vim fn line while prev line gt and vim fn indent prev line gt start indent do vim cmd prev line vim fn line end if around then vim cmd end vim cmd normal V local next line vim fn line local last line vim fn line while next line lt last line and vim fn indent next line gt start indent do vim cmd next line vim fn line end if around then vim cmd endendfunction indent text objects for mode in ipairs x o do vim api nvim set keymap mode ii lt c u gt lua select indent lt cr gt noremap true silent true vim api nvim set keymap mode ai lt c u gt lua select indent true lt cr gt noremap true silent true endendreturn indent text objects indent text objects Next we could ignore the blank lines Right now we don t really care about them but they will inevitably stop our moves up and down because their level of indentation will always be less than the starting one That is if your cursor wasn t on a line without indentation from the start in which case you would select the entire buffer We can define a blank line as a line only containing white space spaces tabs and newlines To find out if the previous or next line is indeed blank we could use a regex local blank line pattern s Regexes in Lua are a bit odd where you would have s for representing white spaces in many other regex engines you have s in Lua We now need to verify at each iteration if the next line is blank We could create a small function for that local prev blank line function line return string match vim fn getline line blank line pattern endWe also need to modify the conditions for our two while loops For example while prev line gt and prev blank line prev line or vim fn indent prev line gt start indent doA last detail which might suits you When your cursor is on a blank line while summoning your text object with your agile fingers you could ignore the keystroke If you find the idea appealing you could add the following before the first while loop if string match vim fn getline blank line pattern then returnendWe ve now patched the most obvious defects of our text object But we can do better What about being able to give a count to select lower levels of indentation For example dai would work as it does now but dai would select a lower level of indentation and dai would select even more To do so we simply need to increase our starting indentation depending on the count given Right now we only know what s the level of indentation of the current line with our variable start indent but we don t know the amount of indentations for each level To get this information we can look at the value of the option shiftwidth Here s the implementation local start indent vim fn indent vim fn line if vim v count gt then start indent start indent vim o shiftwidth vim v count if start indent lt then start indent endendYou might wonder about the calculation start indent start indent vim o shiftwidth vim v count First vim v count is the count given to the text object In Vimscript it would be v count Regarding the calculation itself we need to multiply the count given by the amount of indentations per level the shiftwidth option and subtract it to the indentations of the current line It gives us the amount of indentations one level above We decide that a count of shouldn t change anything dai is the same as dai that s why we subtract from the count We also verify if our starting indentation is lower than which could happen if we enter a count on a line without any indentation In that case We force the starting indentation to Here s the final function function select indent around local start indent vim fn indent vim fn line local blank line pattern s if string match vim fn getline blank line pattern then return end if vim v count gt then start indent start indent vim o shiftwidth vim v count if start indent lt then start indent end end local prev line vim fn line local prev blank line function line return string match vim fn getline line blank line pattern end while prev line gt and prev blank line prev line or vim fn indent prev line gt start indent do vim cmd prev line vim fn line end if around then vim cmd end vim cmd normal V local next line vim fn line local next blank line function line return string match vim fn getline line blank line pattern end local last line vim fn line while next line lt last line and next blank line next line or vim fn indent next line gt start indent do vim cmd next line vim fn line end if around then vim cmd endendThat s it We ve created a wonderful text object with the power of our linked spirits It s with joy and proud that I dub you Godly Blacksmith of the Text Object Mapping a Lua FunctionTill now we ve used some Vimscript strings to map our Lua functions to our new text objects Neovim which came out a couple of days before this article was published allows us to directly map Lua functions without using any Vimscript You can try to look at help vim keymap set for example to improve our code even further The Power of the Text ObjectAs always coming up with new ideas of text objects depend on your needs I always prefer solving the pain points I notice when writing in Vim instead of trying to come up with ideas of improvements out of nothing For example I always wanted to have a text object to manipulate functions at the same time I wanted something which could work with most programming languages Having a text object based on indentation levels is the best compromise to me So what did we see in this article When you hit an operator in NORMAL mode you switch to OPERATOR PENDING mode From there you can give a motion or a text object to operate on what your want A text object is only a set of characters which can be acted upon using operators It s easy to build basic text objects thanks to the operator pending mappings omap and onoremap It s easier to write a function when you need more complex text objects You can then rely on the rich set of Vimscript functions to move your cursor and select what you want Vimscript is a language with many weird design decisions I prefer using Lua as soon as my data flow goes on multiple branches Do you want more articles where we use Vimscript and Lua to improve your customization power in Vim Don t hesitate to give your thoughts feedback and improvements in the comment section Like share and love ReferencesVim wiki Indent text objectVim wiki Creating new text objectsTransactions Pending Dylan McClureGetting started using Lua in Neovim Timothée SterleLearn X in Y minutes Lua Tyler Neylon Learning to Play Vim A Fun Guide to Learn the Best EditorI began to write a very ambitious guide to learn Vim from the ground up Thanks to great feedback from my readers I ll be able to address the problems many beginners complain about when learning Vim For example How to navigate in multiple files and projects in Vim How to debug in Vim How to search find and replace This guide will explain the most useful vanilla functionalities as well as some powerful plugins which will enrich your experience Help me make an impact in the Vim world You can subscribe to the newsletter and tell me everything you want to see in the book Early bird discount guarantees I reply to every email personally so don t hesitate to ask as many questions as you want It s always a pleasure to help Last but not least I ve also written a book about building your own Mouseless Development Environment so if you re interested by that too click on this shiny link 2022-07-23 10:48:43
海外TECH DEV Community 5.1 * 100 != 510 🤯 , Why you have to be careful with Doubles and Floats ! https://dev.to/shrihari/51-100-510-why-you-have-to-be-careful-with-doubles-and-floats--29eg Why you have to be careful with Doubles and Floats Internally Integers and Floats are stored differently This is how integers are stored depending upon the machine the number of bits will be different Normally it will be or bit By default most of the modern languages save a float double as double precision Bit But for this blog I will show you a bit model For the same value but will be saved in the IEEE Double Precision Format Below is the image showing single precision format But why This is because we can save integers easily in the binary form but not floats Floats are special numbers and always require special care when dealing them especially if you re using them for calculations This talks about Floats and Binary We can see there are some errors during the conversion of this float to binary This is why we get this title In our company we deal with a lot of transactions and taxes Hence we always take care of floating points Recently we found this exact bug where we missed to deal with floats it cost us with wrong calculations But we knew what was wrong immediately Peace If you are here it means you may have enjoyed reading this blog Just follow me shrihari which will motivate to write more and contribute open source and may considering a buttermilk If you want to receive these blogs in your mail from Medium Subscribe to my blogs Shrihari I write stuff on DevTo and Medium shrihari portfolio vercel app More Free Articles From me A custom right click menu on Angular FEAT PrimeNg Shrihari Mohan・Jul ・ min read webdev javascript programming html Top UI Frameworks for Angular and react Shrihari Mohan・Jul ・ min read webdev css react angular Colors amp design inspiration websites for new comers Shrihari Mohan・May ・ min read ux design colors webdev 2022-07-23 10:26:53
海外TECH CodeProject Latest Articles libpe - PE32/PE32+ Binaries Viewer Library https://www.codeproject.com/Articles/5205732/libpe-PE32-PE32plus-Binaries-Viewer-Library information 2022-07-23 10:40:00
ニュース BBC News - Home Tory leadership: Rishi Sunak would put UK on 'crisis footing' as PM https://www.bbc.co.uk/news/uk-politics-62270242?at_medium=RSS&at_campaign=KARANGA candidate 2022-07-23 10:17:56
ニュース BBC News - Home Clacton: Body found in search for 21-year-old swimmer https://www.bbc.co.uk/news/uk-england-essex-62277706?at_medium=RSS&at_campaign=KARANGA swimmer 2022-07-23 10:20:57
北海道 北海道新聞 決勝は旭東VS旭大高 夏の高校野球北北海道大会 https://www.hokkaido-np.co.jp/article/709371/ 全国高校野球選手権 2022-07-23 19:21:39
北海道 北海道新聞 女子ゴルフ、苫小牧出身・菊地絵理香が首位守る 大東建託いい部屋ネット第3日 https://www.hokkaido-np.co.jp/article/709374/ 大東建託 2022-07-23 19:32:27
北海道 北海道新聞 五輪、遺産残したと小池知事 国立競技場で1周年セレモニー https://www.hokkaido-np.co.jp/article/709378/ 国立競技場 2022-07-23 19:21:00
北海道 北海道新聞 ラグビー女子、南ア戦を控え練習 南主将「盛り上げる」 https://www.hokkaido-np.co.jp/article/709383/ 日本代表 2022-07-23 19:31:00
北海道 北海道新聞 萩尾望都さんがコミック殿堂入り 米漫画賞のアイズナー賞 https://www.hokkaido-np.co.jp/article/709382/ 殿堂入り 2022-07-23 19:31:00
北海道 北海道新聞 コロナに注意して夏休みを 好天の行楽地にぎわう https://www.hokkaido-np.co.jp/article/709366/ 行楽 2022-07-23 19:16:51
北海道 北海道新聞 照ノ富士と逸ノ城、ともに3敗 貴景勝4敗目、Vの可能性残る https://www.hokkaido-np.co.jp/article/709380/ 大相撲名古屋場所 2022-07-23 19:21:00
北海道 北海道新聞 被爆者の講話聴き原爆ドーム描く 広島で子ども写生大会 https://www.hokkaido-np.co.jp/article/709379/ 原爆ドーム 2022-07-23 19:19:00
北海道 北海道新聞 日6―7ロ(23日) 日本ハム逆転負けで6連敗 https://www.hokkaido-np.co.jp/article/709373/ 日本ハム 2022-07-23 19:06:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)