Live coding 5

I am not sure if there is anything that would work well with mobile that would be free.

On a PC I initially used github for syncing and backup using a cron job (cron jobs would be great to cover in the walk-thrus :slight_smile: ), but I then switched to onedrive, it makes more sense as I started to include more images in my notes.

Having said that, the ability to access Obsidian on a mobile is only a nice to have in my experience (though nice for reviewing notes while lying or on the go).

1 Like

I downloaded Obsidian when I was looking into taking more efficient notes using the Zettelkasten method, but I really haven’t done anything serious with it.

Using regex for editing text with movements in Vim

This is my favourite learning about Vim from Walk-thru 5. The walk-thrus are causing a revolution in my thinking!!! The gif doesn’t show the key bindings used so to replicate in Vim. I’m doing this in 2 steps:

Step 1: Create the movement

  • To delete and move to the start of the next digit type d /^\d

Step 2: Replicate the movement

  • Then move down a row using j (or down arrow) and type dot ‘.’ to repeat the movement: j .


vim-regex-movements

5 Likes

I tried the following:

  • configuring paperspace’s “Access remote kernel” inside VSCode as per paperspace docs (very easy to do)
  • launching fastbook’s lesson 5 pet breeds notebook (which I have stored on my local computer) in VSCode and training on paperspace’s GPU

It’s working well!

You can then even use “vscode vim” inside the notebook cells :upside_down_face: but I’ll leave that for another day.

I never tried running notebooks inside VSCode before, I don’t know if there are any downsides.

2 Likes

some widgets / javascript-y things can freak out and crash your notebook

1 Like

Also, for others coming across this topic at a later date, here’s my detailed “beginner’s guide” to connect VSCode to your Paperspace instance:

3 Likes

To deconstruct this a bit more, here is an example

image

Say I want to delete everything up to the line with 4 digits. I start by pressing d which stand for the verb delete. I then follow by pressing / which is used for searching (try pressing it in any file and type some combination of characters that appears in the text, see what happens).

I am brought down to the prompt at the bottom. There, I type the following
image
and hit enter.

This is a regex that tells 'find the first sequence of 4 digits. In other regex flavors, just '\d{4} would suffice, without the backslash in front of the first curly brace, but in vim this is what we have to do.

I didn’t realize you could combine deletion with searching, which is really cool! :slight_smile:

3 Likes

You can combine any command with any motion, and any repeat! :smiley:

1 Like

i haven’t really used vim that much before i switched to lunar vim, which is neovim with a lot of plugins and config to make it more like a modern code editor out of the box say vscode. however i feel that i miss some of the basic vim ‘tricks’ that Jeremy showed in the lesson. so my plan is to learn some vanilla vim :slight_smile:
just a basic question: is there a way for vim to show python syntax? :snake:

edit:
link to lunarvim if anyone is interested. It’s a nice program i think. can be tricky to install as it needs rust, nodejs, python packages…

1 Like

Thanks! I have been using workflowy for quite a while now, but don’t feel home with it. Do you have any good youtube or written tutorials on Obsidian to recommend?

2 Likes

The rough but detailed note on walkthrough 5

  • What is vim? What it is for? Why we need to learn it? 00:00

  • What are key bindings?

  • How to access the keyboard shortcuts (or key bindings) of fastai forum? ?

  • Are key bindings consistent in different programs?

  • How to move up and down in a thread of the forum? j or k

  • How to edit a reply or a post? e

  • How to select all and copy? cmd a and then cmd c

  • Are these keyboard shortcuts are very similar to vim?

  • How to install vim? brew install vim 05:57

  • Can we use vim in paperspace? Is it preinstalled there?

  • How to install vim in Linux? sudo apt install vim

  • How to start vim? vim

  • How to get into edit mode of vim? i 09:15

  • What is the default mode? command mode

  • How do we know we are in the edit mode? see “insert” at the bottom

  • How to go back to command mode? esc and see “insert” gone

  • How to move up and down in edit mode? arrow keys

  • How to move up and down in command mode? arrow keys or j or k

  • How to move left and right in command mode? h or l

  • How to open a file with vim? vim filename 10:53

  • How to add comment to the first line of code? enter edit mode and hit enter to move it down a line, and do the editing with other keys learned above

  • How to undo? in command mode, press u

  • How to open a new line below the current line where the cursor is? o

  • How to open a new line above the current line where the cursor is? shift + o

  • How to run command in vim? in command mode type : for writing commands at bottom

  • How to save a file? :w

  • How to save into a new file with a different name? :w aNewName

  • How to exit vim? :q

  • How to combine commands like save and quit? :wq

  • How to turn lower to upper case from left to right? in command mode press ~

  • How to do ~ command 10 times? in command mode press 10~

  • How to delete the current line? dd

  • How to delete 5 lines from cursor and below? 5dd

  • How to go to the bottom of the file? shift + g

  • How to delete a region from cursor to the end of the file? d + shift + g 15:53

  • How to go to the the start of the file? gg

  • How to delete from cursor to the start of the file? dgg

  • How to go to the start and the end of a paragraph? { and }

  • How to copy a paragraph below the cursor? put cursor at the line above the paragraph by {, and then press y} and p

  • How to move right and left by word? w or b

  • How to delete and edit on a word? command mode, cursor at the start of a word, cw to delete this word and enter edit mode

  • How to delete the remaining of the paragraph and the paragraph below? 2d}

  • 19:32 How to copy from forum and paste in vim? e; cmd + a; cmd + c; cmd + v; enter vim cmd + v; gg

  • After you delete a line (or any action) and you want to it again, what to do? .

  • How to delete 5 words from the cursor? 5dw

  • How to search the next digit at the start of a line in vim? /^\d

  • How to start to search? /

  • How to search the start of a line? /^

  • How to search the start of a line which is a digit? /^\d

  • How to search again with the same search command? n

  • How to delete the lines from the cursor to the next line start with digits? d/^\d

  • How to do the same action again? .

  • 22:17 How to make an ex command and apply to all lines? :%

  • How to make a grep search command on all lines? :%g/

  • How to search each line for a - at the start of a line? :%g/^-/

  • How to search all the lines for a - at the start of each line and delete them? :%g/^-/d

  • How to search all the lines with one or more empty spaces with the end of the line and delete them? :%g/^\s*$/d

  • How to do search and replace to the whole file? :%s/

  • How to do search the first empty space and replace with a space, - and another space to the whole file? :%s/ / - /

  • How to search all lines and find those start with a space and a - and delete them? :%g/^\s\-/d

  • 24:33 Why vim is so crucial to all data scientists? Can everything done above be automated by a macro in vim?

  • How to quit without saving changes? :q!

  • 25:54 Why our files disappear? because pre-run.sh stays in root not home directory

  • What does ctrl + z do? it stops the program which is currently running and put it in the background 26:35

  • How to check what is running in the background? jobs

  • When you are ready to get back to work on the program in the background, can you call it into the foreground? yes with fg

  • How to split vim vertically to view two files at the same time? :sp /run.sh

  • How to move to different panels with vim? ctrl + w twice (only cmd + w will close tab in chrome for mac)

  • 28:45 What is the solution to the file disappearing problem? by remembering the starting directory and go back to it at the end of the execution of pre-run.sh

    
    pushd ~
    
    #!/usr/bin/env bash
    
    cd
    
    rm -rf .local
    
    ln -s /storage/cfg/.local
    
    rm -rf .ssh
    
    ln -s /storage/cfg/.ssh
    
    popd
    
    
  • Can you open multiple programs or vim fileNames and put them all in the background? yes and you can see them with jobs and use fg 1 and fg 2 to access each of them

  • Can vscode work with paperspace remotely? 32:29 absolutely

  • How to learn vim? one bite at a time; get the attitude right and hear Jeremy’s story; don’t install any plugins to waste time; and type vimtutor to get a tutorial on vim

  • How to delete a character at the cursor? x

  • Radek’s resources of learning vim: https://vim-adventures.com/, Practical Vim: Edit Text at the Speed of Thought,

  • Where is Jeremy’s configuration files? fastai dotfiles

  • How does Jeremy customize its vim environment? Jeremy explained his .vimrc file 41:42

  • Where should we git clone fastai repo into? Is /notebooks/ directory is persistent in restarts of one machine and across machines? but will you still have the files once deleted the machine or notebook? 45:33 #question

  • How to only git clone the latest version of the repo to save time? git clone git@github.com:fastai/fastai.git --depth 1

  • How to explore the entire fastai library repo? 47:41 we can do it in github, vscode and vim

  • What is ctags? How does it work to explore the entire repo?

  • How to make mamba and conda work seamlessly together in paperspace? conda install -c defaults -c conda-forge mamba

  • How to install ctag with mamba? mamba install -c conda-forge universal-ctags

  • Where and how are we going to use ctags? go to the folder where the files you want to explore stored and type ctags

  • How to index the current folder where the files are stored? ctags -R . and use ls to check the ctag file created inside the current folder (git status does not see it, maybe because of .gitignore?`, need to check #question)

  • What is inside the ctag file? 54:19

  • How to search a function such as ArrayMask using ctags from terminal? ctags -t ArrayMask

  • How to search the above function within a python file? vim filename to open the file, :tj ArrayMask

  • How to jump from a particular class where the cursor is at to the class definition? ctrl + ]

  • How to go back to the previous tag? ctrl + t

  • What is the checkpoint.py file? 56:02

  • How to create a ctag config file to ignore the backup file? #question

  • How to split the tag to view the current function where the cursor is at and the function definition you are searching for? :stag FunctionName

8 Likes

Thanks Daniel! This is very helpful for folks reviewing, but less helpful for making chapter markers, since on this one you don’t have the lines you used to that have a timestamp from time to time that I can grep out. Instead the timestamps have been moved to the end or middle of lines, and those lines are generally more detailed comments than would be appropriate for timestamps.

I’ll manually generate timestamps for this one. Is it possible in the future to go back to your previous approach? It was really handy for me! (No problem if you can’t or don’t want to for any reason – I still appreciate your sharing of these notes.)

3 Likes

Oops my bad I forgot we already have the timestamps from @mattr for this one! :slight_smile:

1 Like

I’ve gone through the walk-thru5 recording from around 45:00 several times to reproduce what we did with ctags but it seems to only work for me on the first time through. After following the video and getting things working and then shutting down this Paperspace instance and reopening I find that the same ctags commands don’t work on the fastai directory.

  • The tags file is still in the /notebooks/fastai/fastai directory but it is empty which is surprising because it is in what I thought was a persistent storage folder
  • Reinstalling mamba and universal-ctags within this restarted instance and
  • Repeating the indexing command ctags -R . doesn’t fix the problem for me
  • I get a .: Is a directory response when attempting to rebuild the index

There is value in writing stuff down, no matter how or where you do it (this forum, Twitter, etc).

Anki is great for note-taking as well if your main objective is learning (here are non-exhaustive flashcards for part 1 v4 of the course).

This sequence by Nick Milo is quite nice as far as free resources go.

This book is coming out soon, might be quite interesting. This one is a very informative read, though it might not be easy to go from reading it to practice. This book by David Kadavy is extremely concise, with a more practical focus.

That is quite a few resources :slight_smile: I am a bit worried I might have derailed the discussion enough already, apologises for that! Will stick to the walk-thru content from now.

5 Likes

These walkthrus are designed to be informal and chatty, so please don’t worry about derailing - we’re all here to learn together :slight_smile:

4 Likes

Sure, of course, I will keep the usual approach next time. I am very glad this rough note is helpful.

1 Like

Don’t worry about it please, all these are very helpful.

Hey @radek
one more thing, I wonder could you show us how you take note with obsidian on walkthrough videos, especially with your style. By style, I mean what are your useful tricks and tips in how to effectively use internal links, tags, and vim binding keys, etc to note down ideas/questions, to organise and to search the entire notebooks.

If this question does make you worry about derailing from this thread, maybe you or I could start a new thread on a note-taking topic?

Further to this I tried installing universal-ctags on my local ARM64 machine that has been setup with mamba as per Walk-thru1 I think and am getting the following error message:

My workaround was to use Homebrew
brew install --HEAD universal-ctags/universal-ctags/universal-ctags

But then I was still getting the . : is a directory error after typing ctags -R .. Instead I found using ctags * in the folder to index appeared to successfully build the index and enabled me to navigate around the fastai repo on my local machine using vim ctags -t and :tj commands.

1 Like

Hi Matt, I installed ctags using ‘brew install universal-ctags’ and then in the cloned fastai/fastai repo where the .py files are I was able to do ‘ctags -R .’ without a problem. I also open ‘vi torch_core.py’ and then I can jump around using :tj ArrayMask (then CTRL-] to go to object under the cursor and CTRL-o to go back.)

I’m on macOS Monterey 12.3.1 , brew version 3.4.11 (MBP 15" 2015 intel)

P.S. I found this error which may or may not be related to the issue you’re having, but it might be worthwhile checking to see if you’ve got a folder named ‘tags’ in the directory tree you’re trying to index using ‘ctags -R’

3 Likes