I just installed Django on my Mac and I am trying to figure out a way to edit the python modules directly from the terminal.
I know I can view the contents of a file using the less command in the command line, but is there a way I can edit Django modules from the command line, as well? It's just kind of annoying having to switch between the command line and a text editor, so I was hoping I could do everything in one spot.
Thanks,
Jerry
EDIT: rephrased.
There are lots of TUI text editors available for *nix. vim and emacs are popular, and are available in several forms for OS X.
This question is a little confused.
There's no such thing as "editing in Python", or "editing in Bash". I don't know what you're regarding as the "Python" that you have to switch to, but most people using a Mac edit their Python files in something like Textmate. That can be always running, and the Django development server automatically reloads when you save changes to any of the files in use, so this is the often most convenient way of doing it.
Bash is the shell that runs inside the terminal. Instead of talking about "editing in Bash", I expect you mean "editing in the terminal". Of course, there are hundreds of editors that run inside the terminal. One that comes installed on the Mac is vim, which I use all the time - but it has its fair share of idiosyncrasies, and takes a lot of getting used to.
However, if anything, editing in vim inside the terminal seems like it would involve more "switching" rather than less. You'd either need to have a separate terminal tab, and switch between the one running the server and the one running vim, or continually quit your server to go into vim.
Related
I am a new programmer and I am trying to use the terminal on my Mac to compile and run the C++ code I write using the Sublime text editor.
I am able to get my code to run using the terminal, however, whenever I make changes to my code on sublime and then re-compile it on my terminal, my terminal doesn't recognize my changes and keeps on running my original code.
Does anyone know what might be happening?
Thank you so much!
I can think of two possibilities that spring immediately to mind. If you're changing your code in the editor, and that's not being reflected in the compilation, then it's likely to be one of the following. Either:
you're not saving the file in the location you think you are; or
you're not saving the file at all.
The easiest way to tell if one of these is the case is to introduce an error into your code(a), like:
int my hovercraft = full of eels;
and make sure the compiler complains about it.
If you're not saving it at all, do so. If you're saving it in the wrong place, you can usually find out where just by doing a Save As and seeing where the default location is.
If you're annoyed that you have to save, and that computers should just "work"(b), Sublime Text has an auto-save feature that may come in handy, courtesy of one Lucy Bain. Instructions (paraphrased) are duplicated here in case that site ever disappears:
Open Sublime
Find Settings and edit the user window (under Sublime Text 2 > Preferences for Mac, just Preferences for Windows).
Add the line "save_on_focus_lost": true.
Save and close the file.
At that point, whenever you click away from a particular file, it should save it.
(a) Some developers seem to have little trouble doing this without even trying :-)
(b) A not unreasonable expectation for a Mac user :-)
I currently use vim/byobu-tmux to multiplex between a command line (cmake/gcc) and a vim session.
Is there a way to do the following directly within the vim session?
Compile within vim (I currently use a cmakedbg bash alias in a command line/bash session)
Jump to files/location where the compile has failed
all within vim, that would save me a lot of time.
Did you try
set makeprg=cmakedbg
Then
:make
should compile and if it fails it should automatically jump to the error (while :make! would compile without jumping to the error). This works usually, but might need some tweaking depending on the setup.
If you need to source .bashrc before cmakedbg works, you can make the shell interactive by
:set shellcmdflag=-ic
However, I always had problems with that. I know it's working for some people, but when I try that, vim is stopped by the interactive mode. I can get it back by typing fg, but that's not what I want.
I think the best way to do it is to set up a function in vim and do it without .bashrc.
I made a simple regex search in Netbeans 7.3 on Windows (using Ctrl+F):
\{\{.*?\}\}
The results get highlighted correctly and the question is - how to extract highlighted text search results? Let it be copying to clipboard, saving as file or whatever else.
Is there any method doing this?
Maybe someone has any suggestion of alternative quick approach to such task in Netbeans? (or other editor)
What OS are you running? If OS X or Linux, read on!
I'm not sure about automatically copying the highlighted results to the clipboard, but I do workaround this quite a bit as well.
The easiest way to accomplish this for me without leaving NetBeans is to simply open a built in terminal window through Window>Output>Terminal (in 7.2.1) - I then navigate to my project, and run the RegEx that I built in the Find feature with my tool of choice. In fact, I use the built in terminal for this type of quick stuff in NetBeans quite a bit. If running Linux, using clipboard tools like xsel (http://linux.die.net/man/1/xsel) in combination with a built in terminal emulator can allow for devising some nice workflow shortcuts within IDEs if you are more comfortable working/coding at a terminal. Note that built in terminal emulators like the one in NetBeans is likely not going to play nicely with cut/copy/paste using the mouse, for various reasons that I won't get in to here.
As far as a built in/extension based solution for something like this, it would be helpful! I am not aware of one.
Hope this workaround helps in the meantime.
I used VIM whole my life but recently I am a bit tired of it because I am lost in buffers, windows, and tabs when working simultaneously with 20 files or so in a big project (with 500k LOC, and hundreds files).
Whenever i do :make, :grep, etc, new buffers are jumping out in the current window.
The same happens for the tags. At some point this starts to be very confusing because I really have to focus where things are in a VIM.
What are a proven and easy ways to control this behavior?
Use :hide to get rid of all windows unless you really need them open.
I'm not sure why tags are creating a new window for you, CTRL+] should re-use the current window.
nnoremap + 4<C-W>+ and nnoremap - 4<C-W>- make it much easier to resize windows, along with the standard <C-W>_ and <C-W>|.
Get a 22" monitor (minimum) and use :vsplit to show files side by side. I find this is even more important than having two smaller monitors.
Use <C-W>L, <C-W>H etc to move windows around. Don't forget :tab sp to open the current file (or a new one) in a new tab.
:map <LEFT> <C-W>h and :map <RIGHT> <C-W>l, etc make it much easier to move between windows. :map <C-LEFT> :tabprev<CR> and :map <C-RIGHT> :tabnext<CR> make it much easier to move between tabs.
And finally, if you need to have 20 files open regularly, this could be a sign that your code is poorly organized. If possible, features should be contained within a single file, then you just need to focus work on one feature at a time.
I tested out Eclim http://eclim.org/ a while ago for a friend. Basically, it lets you run Eclipse in a headless mode while using vim for editing and so on. With the extension, it allows Vim to draw on all the strengths of both worlds, adding for instance Eclipse's project tree to your favourite editor!
Installation was a bit daunting back then, but once I had it up and running, it was really smooth and quite a brilliant solution. Try it out, I'm pretty sure you won't be disappointed. And the installation is probably easier now. :)
Oh, I should also mention that there are several Eclim-setups. You can have headless Eclipse with vim as your primary interface (as I first mentioned), you can have a headed Eclipse and Vim, so that you can easily switch back and forth (in the same project no less), or you can have Vim integrated into Eclipse itself.
Run multiple vims. I use "konsole" on my Linux machine. It allows me to open many tabbed linux terminal sessions in one window. I can double click the tabs to name them, e.g. "models", "views", "controllers", etc. In each of these tabbed linux terminals, I'll have a vim process running that has usually 2 or 3 files open at a time.
Another option is to find and IDE that has Vim mode, so you can still use most of your key commands.
As a longtime vim user, it pains me to say it, but--it might be time for you to graduate to a full-fledged IDE. You can still use vim as your editor in most cases, but the IDE will handle file management and navigation for you, and probably will simplify your make and grep workflows (e.g., structural search beats the pants off of grep). What language are you working on?
Vim-CtrlSpace lets you organize Tabs, Buffers, Sessions (workspaces) + fuzzy search.
It is quite suitable to work on large projects. That's how I actually come up with it.
Before, I used 'jlanzarotta/bufexplorer.git' and 'xolox/vim-session'
You can check the demo on YouTube.
I work on an application that usually runs unattended. Now I need to add to it something like an interactive prompt. In the interactive mode the operator will be able to give simple commands to the application - nothing fancy, simple commands like start and stop. Parametrized commands (e.g. repeat 10) and commands history could be nice too.
Do you know, by chance, any library that helps with such tasks. I've been thinking about something that works like boost::program_options or gflags but for an interactive prompt and not for command line parameters. Any ideas?
Thanks
Readline is one the best known libraries for this
http://tiswww.case.edu/php/chet/readline/rltop.html
It is covered by GPL, so it is only possible to use in GPL-compatible programs.
I did a quick search for alternatives, and found this:
http://github.com/antirez/linenoise
I'm not sure if the following is a reasonable amount of work for what you're trying to do, but Python has a very nice Command Line Interface (CLI) building library called cmd2. If it's possible to expose the relevant parts of your apps to Python using SWIG or CTypes, then doing the rest should be easy.
Here's a nice video presentation about cmd2:
PyCon 2010:Easy command-line applications with cmd and cmd2
HTH
One possibilty is to open a TCP port and accept messages in text format. Then you can telnet to that port and issue simple commands.